diff options
author | 2024-12-16 21:45:41 -0500 | |
---|---|---|
committer | 2025-01-11 14:17:35 -0500 | |
commit | e9a0e66716dab4dd3184d009d8920de1961efdfa (patch) | |
tree | 02dcc096643d74645bf28459c2834c3d4a2ad7f2 /tests/src/org/kelar | |
parent | fb3b9360d70596d7e921de8bf7d3ca99564a077e (diff) | |
download | latinime-e9a0e66716dab4dd3184d009d8920de1961efdfa.tar.gz latinime-e9a0e66716dab4dd3184d009d8920de1961efdfa.tar.xz latinime-e9a0e66716dab4dd3184d009d8920de1961efdfa.zip |
Rename to Kelar Keyboard (org.kelar.inputmethod.latin)
Diffstat (limited to 'tests/src/org/kelar')
291 files changed, 46106 insertions, 0 deletions
diff --git a/tests/src/org/kelar/inputmethod/compat/LocaleSpanCompatUtilsTests.java b/tests/src/org/kelar/inputmethod/compat/LocaleSpanCompatUtilsTests.java new file mode 100644 index 000000000..44aae0282 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/compat/LocaleSpanCompatUtilsTests.java @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.compat; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import android.graphics.Typeface; +import android.os.Build; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.style.StyleSpan; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class LocaleSpanCompatUtilsTests { + @Test + public void testInstantiatable() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { + // LocaleSpan isn't yet available. + return; + } + assertTrue(LocaleSpanCompatUtils.isLocaleSpanAvailable()); + final Object japaneseLocaleSpan = LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE); + assertNotNull(japaneseLocaleSpan); + assertEquals(Locale.JAPANESE, + LocaleSpanCompatUtils.getLocaleFromLocaleSpan(japaneseLocaleSpan)); + } + + private static void assertLocaleSpan(final Spanned spanned, final int index, + final int expectedStart, final int expectedEnd, + final Locale expectedLocale, final int expectedSpanFlags) { + final Object span = spanned.getSpans(0, spanned.length(), Object.class)[index]; + assertEquals(expectedLocale, LocaleSpanCompatUtils.getLocaleFromLocaleSpan(span)); + assertEquals(expectedStart, spanned.getSpanStart(span)); + assertEquals(expectedEnd, spanned.getSpanEnd(span)); + assertEquals(expectedSpanFlags, spanned.getSpanFlags(span)); + } + + private static void assertSpanEquals(final Object expectedSpan, final Spanned spanned, + final int index) { + final Object[] spans = spanned.getSpans(0, spanned.length(), Object.class); + assertEquals(expectedSpan, spans[index]); + } + + private static void assertSpanCount(final int expectedCount, final Spanned spanned) { + final Object[] spans = spanned.getSpans(0, spanned.length(), Object.class); + assertEquals(expectedCount, spans.length); + } + + @Test + public void testUpdateLocaleSpan() { + if (!LocaleSpanCompatUtils.isLocaleSpanAvailable()) { + return; + } + + // Test if the simplest case works. + { + final SpannableString text = new SpannableString("0123456789"); + LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 5, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if only LocaleSpans are updated. + { + final SpannableString text = new SpannableString("0123456789"); + final StyleSpan styleSpan = new StyleSpan(Typeface.BOLD); + text.setSpan(styleSpan, 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 5, Locale.JAPANESE); + assertSpanCount(2, text); + assertSpanEquals(styleSpan, text, 0); + assertLocaleSpan(text, 1, 1, 5, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if two jointed spans are merged into one span. + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 3, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 5, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if two overlapped spans are merged into one span. + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 4, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 5, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if three overlapped spans are merged into one span. + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 4, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 5, 6, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 2, 8, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 8, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if disjoint spans remain disjoint. + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 3, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 5, 6, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 8, 9, Locale.JAPANESE); + assertSpanCount(3, text); + assertLocaleSpan(text, 0, 1, 3, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + assertLocaleSpan(text, 1, 5, 6, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + assertLocaleSpan(text, 2, 8, 9, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if existing span flags are preserved during merge. + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 5, + Spanned.SPAN_INCLUSIVE_INCLUSIVE | Spanned.SPAN_INTERMEDIATE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 4, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE, + Spanned.SPAN_INCLUSIVE_INCLUSIVE | Spanned.SPAN_INTERMEDIATE); + } + + // Test if existing span flags are preserved even when partially overlapped (leading edge). + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 5, + Spanned.SPAN_INCLUSIVE_INCLUSIVE | Spanned.SPAN_INTERMEDIATE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 7, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 7, Locale.JAPANESE, + Spanned.SPAN_INCLUSIVE_EXCLUSIVE | Spanned.SPAN_INTERMEDIATE); + } + + // Test if existing span flags are preserved even when partially overlapped (trailing edge). + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 3, 7, + Spanned.SPAN_INCLUSIVE_INCLUSIVE | Spanned.SPAN_INTERMEDIATE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 5, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 7, Locale.JAPANESE, + Spanned.SPAN_EXCLUSIVE_INCLUSIVE | Spanned.SPAN_INTERMEDIATE); + } + + // Test if existing locale span will be removed when the locale doesn't match. + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 5, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 7, Locale.JAPANESE); + assertSpanCount(1, text); + assertLocaleSpan(text, 0, 1, 7, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if existing locale span will be removed when the locale doesn't match. (case 2) + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 7, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 5, 6, Locale.JAPANESE); + assertSpanCount(3, text); + assertLocaleSpan(text, 0, 3, 5, Locale.ENGLISH, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + assertLocaleSpan(text, 1, 6, 7, Locale.ENGLISH, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + assertLocaleSpan(text, 2, 5, 6, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if existing locale span will be removed when the locale doesn't match. (case 3) + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 7, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 2, 5, Locale.JAPANESE); + assertSpanCount(2, text); + assertLocaleSpan(text, 0, 5, 7, Locale.ENGLISH, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + assertLocaleSpan(text, 1, 2, 5, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + // Test if existing locale span will be removed when the locale doesn't match. (case 3) + { + final SpannableString text = new SpannableString("0123456789"); + text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 7, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + LocaleSpanCompatUtils.updateLocaleSpan(text, 5, 8, Locale.JAPANESE); + assertSpanCount(2, text); + assertLocaleSpan(text, 0, 3, 5, Locale.ENGLISH, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + assertLocaleSpan(text, 1, 5, 8, Locale.JAPANESE, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/compat/SuggestionSpanUtilsTest.java b/tests/src/org/kelar/inputmethod/compat/SuggestionSpanUtilsTest.java new file mode 100644 index 000000000..d9fe690ac --- /dev/null +++ b/tests/src/org/kelar/inputmethod/compat/SuggestionSpanUtilsTest.java @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.compat; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.text.Spanned; +import android.text.TextUtils; +import android.text.style.SuggestionSpan; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.SuggestedWords; +import org.kelar.inputmethod.latin.SuggestedWords.SuggestedWordInfo; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; + +import javax.annotation.Nullable; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SuggestionSpanUtilsTest { + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + /** + * Helper method to create a placeholder {@link SuggestedWordInfo}. + * + * @param kindAndFlags the kind and flags to be used to create {@link SuggestedWordInfo}. + * @param word the word to be used to create {@link SuggestedWordInfo}. + * @return a new instance of {@link SuggestedWordInfo}. + */ + private static SuggestedWordInfo createWordInfo(final String word, final int kindAndFlags) { + return new SuggestedWordInfo(word, "" /* prevWordsContext */, 1 /* score */, kindAndFlags, + null /* sourceDict */, + SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, + SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */); + } + + private static void assertNotSuggestionSpan(final String expectedText, + final CharSequence actualText) { + assertTrue(TextUtils.equals(expectedText, actualText)); + if (!(actualText instanceof Spanned)) { + return; + } + final Spanned spanned = (Spanned)actualText; + final SuggestionSpan[] suggestionSpans = spanned.getSpans(0, spanned.length(), + SuggestionSpan.class); + assertEquals(0, suggestionSpans.length); + } + + private static void assertSuggestionSpan(final String expectedText, + final int reuiredSuggestionSpanFlags, final int requiredSpanFlags, + final String[] expectedSuggestions, @Nullable final Locale expectedLocale, + final CharSequence actualText) { + assertTrue(TextUtils.equals(expectedText, actualText)); + assertTrue(actualText instanceof Spanned); + final Spanned spanned = (Spanned)actualText; + final SuggestionSpan[] suggestionSpans = spanned.getSpans(0, spanned.length(), + SuggestionSpan.class); + assertEquals(1, suggestionSpans.length); + final SuggestionSpan suggestionSpan = suggestionSpans[0]; + if (reuiredSuggestionSpanFlags != 0) { + assertTrue((suggestionSpan.getFlags() & reuiredSuggestionSpanFlags) != 0); + } + if (requiredSpanFlags != 0) { + assertTrue((spanned.getSpanFlags(suggestionSpan) & requiredSpanFlags) != 0); + } + if (expectedSuggestions != null) { + final String[] actualSuggestions = suggestionSpan.getSuggestions(); + assertEquals(expectedSuggestions.length, actualSuggestions.length); + for (int i = 0; i < expectedSuggestions.length; ++i) { + assertEquals(expectedSuggestions[i], actualSuggestions[i]); + } + } + // CAVEAT: SuggestionSpan#getLocale() returns String rather than Locale object. + assertEquals(expectedLocale.toString(), suggestionSpan.getLocale()); + } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) + @Test + public void testGetTextWithAutoCorrectionIndicatorUnderline() { + final String ORIGINAL_TEXT = "Hey!"; + final Locale NONNULL_LOCALE = new Locale("en", "GB"); + final CharSequence text = SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + getContext(), ORIGINAL_TEXT, NONNULL_LOCALE); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + assertNotSuggestionSpan(ORIGINAL_TEXT, text); + return; + } + assertSuggestionSpan(ORIGINAL_TEXT, + SuggestionSpan.FLAG_AUTO_CORRECTION /* reuiredSuggestionSpanFlags */, + Spanned.SPAN_COMPOSING | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE /* requiredSpanFlags */, + new String[]{}, NONNULL_LOCALE, text); + } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) + @Test + public void testGetTextWithAutoCorrectionIndicatorUnderlineRootLocale() { + final String ORIGINAL_TEXT = "Hey!"; + final CharSequence text = SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + getContext(), ORIGINAL_TEXT, Locale.ROOT); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + assertNotSuggestionSpan(ORIGINAL_TEXT, text); + return; + } + assertSuggestionSpan(ORIGINAL_TEXT, + SuggestionSpan.FLAG_AUTO_CORRECTION /* reuiredSuggestionSpanFlags */, + Spanned.SPAN_COMPOSING | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE /* requiredSpanFlags */, + new String[]{}, Locale.ROOT, text); + } + + @Test + public void testGetTextWithSuggestionSpan() { + final SuggestedWordInfo prediction1 = + createWordInfo("Quality", SuggestedWordInfo.KIND_PREDICTION); + final SuggestedWordInfo prediction2 = + createWordInfo("Speed", SuggestedWordInfo.KIND_PREDICTION); + final SuggestedWordInfo prediction3 = + createWordInfo("Price", SuggestedWordInfo.KIND_PREDICTION); + + final SuggestedWordInfo typed = + createWordInfo("Hey", SuggestedWordInfo.KIND_TYPED); + + final SuggestedWordInfo[] corrections = + new SuggestedWordInfo[SuggestionSpan.SUGGESTIONS_MAX_SIZE * 2]; + for (int i = 0; i < corrections.length; ++i) { + corrections[i] = createWordInfo("correction" + i, SuggestedWordInfo.KIND_CORRECTION); + } + + final Locale NONNULL_LOCALE = new Locale("en", "GB"); + + // SuggestionSpan will not be attached when {@link SuggestedWords#INPUT_STYLE_PREDICTION} + // is specified. + { + final SuggestedWords predictedWords = new SuggestedWords( + new ArrayList<>(Arrays.asList(prediction1, prediction2, prediction3)), + null /* rawSuggestions */, + null /* typedWord */, + false /* typedWordValid */, + false /* willAutoCorrect */, + false /* isObsoleteSuggestions */, + SuggestedWords.INPUT_STYLE_PREDICTION, + SuggestedWords.NOT_A_SEQUENCE_NUMBER); + final String PICKED_WORD = prediction2.mWord; + // Note that the framework uses the context locale as a fallback locale. + assertNotSuggestionSpan( + PICKED_WORD, + SuggestionSpanUtils.getTextWithSuggestionSpan(getContext(), PICKED_WORD, + predictedWords, NONNULL_LOCALE)); + } + + final ArrayList<SuggestedWordInfo> suggestedWordList = new ArrayList<>(); + suggestedWordList.add(typed); + suggestedWordList.add(prediction1); + suggestedWordList.add(prediction2); + suggestedWordList.add(prediction3); + suggestedWordList.addAll(Arrays.asList(corrections)); + final SuggestedWords typedAndCollectedWords = new SuggestedWords( + suggestedWordList, + null /* rawSuggestions */, + null /* typedWord */, + false /* typedWordValid */, + false /* willAutoCorrect */, + false /* isObsoleteSuggestions */, + SuggestedWords.INPUT_STYLE_TYPING, + SuggestedWords.NOT_A_SEQUENCE_NUMBER); + + for (final SuggestedWordInfo pickedWord : suggestedWordList) { + final String PICKED_WORD = pickedWord.mWord; + + final ArrayList<String> expectedSuggestions = new ArrayList<>(); + for (SuggestedWordInfo suggestedWordInfo : suggestedWordList) { + if (expectedSuggestions.size() >= SuggestionSpan.SUGGESTIONS_MAX_SIZE) { + break; + } + if (suggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_PREDICTION)) { + // Currently predictions are not filled into SuggestionSpan. + continue; + } + final String suggestedWord = suggestedWordInfo.mWord; + if (TextUtils.equals(PICKED_WORD, suggestedWord)) { + // Typed word itself is not added to SuggestionSpan. + continue; + } + expectedSuggestions.add(suggestedWord); + } + + // non-null locale + assertSuggestionSpan( + PICKED_WORD, + 0 /* reuiredSuggestionSpanFlags */, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE /* requiredSpanFlags */, + expectedSuggestions.toArray(new String[expectedSuggestions.size()]), + NONNULL_LOCALE, + SuggestionSpanUtils.getTextWithSuggestionSpan(getContext(), PICKED_WORD, + typedAndCollectedWords, NONNULL_LOCALE)); + + // root locale + assertSuggestionSpan( + PICKED_WORD, + 0 /* reuiredSuggestionSpanFlags */, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE /* requiredSpanFlags */, + expectedSuggestions.toArray(new String[expectedSuggestions.size()]), + Locale.ROOT, + SuggestionSpanUtils.getTextWithSuggestionSpan(getContext(), PICKED_WORD, + typedAndCollectedWords, Locale.ROOT)); + } + } + + @Test + public void testFindFirstLocaleFromSuggestionSpans() { + final String[] suggestions = new String[] {"Quality", "Speed", "Price"}; + final SuggestionSpan nullLocaleSpan = new SuggestionSpan((Locale)null, suggestions, 0); + final SuggestionSpan emptyLocaleSpan = new SuggestionSpan(new Locale(""), suggestions, 0); + final SuggestionSpan enUsLocaleSpan = new SuggestionSpan(Locale.US, suggestions, 0); + final SuggestionSpan jaJpLocaleSpan = new SuggestionSpan(Locale.JAPAN, suggestions, 0); + + assertEquals(null, SuggestionSpanUtils.findFirstLocaleFromSuggestionSpans( + new SuggestionSpan[] {})); + + assertEquals(null, SuggestionSpanUtils.findFirstLocaleFromSuggestionSpans( + new SuggestionSpan[] {emptyLocaleSpan})); + + assertEquals(Locale.US, SuggestionSpanUtils.findFirstLocaleFromSuggestionSpans( + new SuggestionSpan[] {enUsLocaleSpan})); + + assertEquals(Locale.US, SuggestionSpanUtils.findFirstLocaleFromSuggestionSpans( + new SuggestionSpan[] {nullLocaleSpan, enUsLocaleSpan})); + + assertEquals(Locale.US, SuggestionSpanUtils.findFirstLocaleFromSuggestionSpans( + new SuggestionSpan[] {nullLocaleSpan, emptyLocaleSpan, enUsLocaleSpan})); + + assertEquals(Locale.JAPAN, SuggestionSpanUtils.findFirstLocaleFromSuggestionSpans( + new SuggestionSpan[] {nullLocaleSpan, jaJpLocaleSpan, enUsLocaleSpan})); + } +} diff --git a/tests/src/org/kelar/inputmethod/compat/TextInfoCompatUtilsTests.java b/tests/src/org/kelar/inputmethod/compat/TextInfoCompatUtilsTests.java new file mode 100644 index 000000000..9b2ab94ee --- /dev/null +++ b/tests/src/org/kelar/inputmethod/compat/TextInfoCompatUtilsTests.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.compat; + +import static org.junit.Assert.assertTrue; + +import android.graphics.Typeface; +import android.os.Parcel; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.TextUtils; +import android.text.style.StyleSpan; +import android.text.style.URLSpan; +import android.view.textservice.TextInfo; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class TextInfoCompatUtilsTests { + final private static String TEST_TEXT = "0123456789"; + final private static int TEST_COOKIE = 0x1234; + final private static int TEST_SEQUENCE_NUMBER = 0x4321; + final private static int TEST_CHAR_SEQUENCE_START = 1; + final private static int TEST_CHAR_SEQUENCE_END = 6; + final private static StyleSpan TEST_STYLE_SPAN = new StyleSpan(Typeface.BOLD); + final private static int TEST_STYLE_SPAN_START = 4; + final private static int TEST_STYLE_SPAN_END = 5; + final private static int TEST_STYLE_SPAN_FLAGS = Spanned.SPAN_EXCLUSIVE_INCLUSIVE; + final private static URLSpan TEST_URL_SPAN_URL = new URLSpan("http://example.com"); + final private static int TEST_URL_SPAN_START = 3; + final private static int TEST_URL_SPAN_END = 7; + final private static int TEST_URL_SPAN_FLAGS = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; + + @Test + public void testGetCharSequence() { + final SpannableString text = new SpannableString(TEST_TEXT); + text.setSpan(TEST_STYLE_SPAN, TEST_STYLE_SPAN_START, TEST_STYLE_SPAN_END, + TEST_STYLE_SPAN_FLAGS); + text.setSpan(TEST_URL_SPAN_URL, TEST_URL_SPAN_START, TEST_URL_SPAN_END, + TEST_URL_SPAN_FLAGS); + + final TextInfo textInfo = TextInfoCompatUtils.newInstance(text, + TEST_CHAR_SEQUENCE_START, TEST_CHAR_SEQUENCE_END, TEST_COOKIE, + TEST_SEQUENCE_NUMBER); + final Spanned expectedSpanned = (Spanned) text.subSequence(TEST_CHAR_SEQUENCE_START, + TEST_CHAR_SEQUENCE_END); + final CharSequence actualCharSequence = + TextInfoCompatUtils.getCharSequenceOrString(textInfo); + + // This should be valid even if TextInfo#getCharSequence is not supported. + assertTrue(TextUtils.equals(expectedSpanned, actualCharSequence)); + + if (TextInfoCompatUtils.isCharSequenceSupported()) { + // This is valid only if TextInfo#getCharSequence is supported. + assertTrue("should be Spanned", actualCharSequence instanceof Spanned); + assertTrue(Arrays.equals(marshall(expectedSpanned), marshall(actualCharSequence))); + } + } + + private static byte[] marshall(final CharSequence cahrSequence) { + Parcel parcel = null; + try { + parcel = Parcel.obtain(); + TextUtils.writeToParcel(cahrSequence, parcel, 0); + return parcel.marshall(); + } finally { + if (parcel != null) { + parcel.recycle(); + parcel = null; + } + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysBase.java b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysBase.java new file mode 100644 index 000000000..5ba44c73e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysBase.java @@ -0,0 +1,337 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard; + +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.keyboard.internal.MoreKeySpec; +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.RichInputMethodManager; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Arrays; +import java.util.Locale; + +abstract class KeyboardLayoutSetNavigateMoreKeysBase extends KeyboardLayoutSetTestsBase { + private ExpectedMoreKey mExpectedNavigateNextMoreKey; + private ExpectedMoreKey mExpectedNavigatePreviousMoreKey; + private ExpectedMoreKey mExpectedEmojiMoreKey; + + protected ExpectedMoreKey getExpectedNavigateNextMoreKey() { + return new ExpectedMoreKey(R.string.label_next_key); + } + + protected ExpectedMoreKey getExpectedNavigatePreviousMoreKey() { + return new ExpectedMoreKey(R.string.label_previous_key); + } + + protected ExpectedMoreKey getExpectedEmojiMoreKey() { + return new ExpectedMoreKey(KeyboardIconsSet.NAME_EMOJI_ACTION_KEY); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mExpectedNavigateNextMoreKey = getExpectedNavigateNextMoreKey(); + mExpectedNavigatePreviousMoreKey = getExpectedNavigatePreviousMoreKey(); + mExpectedEmojiMoreKey = getExpectedEmojiMoreKey(); + } + + /** + * This class represents an expected more key. + */ + protected static class ExpectedMoreKey { + public static final int NO_LABEL = 0; + public static final ExpectedMoreKey[] EMPTY_MORE_KEYS = new ExpectedMoreKey[0]; + + public final int mLabelResId; + public final int mIconId; + + public ExpectedMoreKey(final String iconName) { + mLabelResId = NO_LABEL; + mIconId = KeyboardIconsSet.getIconId(iconName); + } + + public ExpectedMoreKey(final int labelResId) { + mLabelResId = labelResId; + mIconId = KeyboardIconsSet.ICON_UNDEFINED; + } + } + + private void doTestMoreKeysOf(final int code, final InputMethodSubtype subtype, + final int elementId, final int inputType, final int imeOptions, + final ExpectedMoreKey ... expectedMoreKeys) { + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.inputType = inputType; + editorInfo.imeOptions = imeOptions; + final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); + final Keyboard keyboard = layoutSet.getKeyboard(elementId); + + final Key actualKey = keyboard.getKey(code); + final MoreKeySpec[] actualMoreKeys = actualKey.getMoreKeys(); + final String tag = actualKey.toString() + " moreKeys=" + Arrays.toString(actualMoreKeys); + if (expectedMoreKeys.length == 0) { + assertEquals(tag, null, actualMoreKeys); + return; + } + if (expectedMoreKeys.length == 1) { + assertEquals(tag + " fixedOrder", false, actualKey.isMoreKeysFixedOrder()); + assertEquals(tag + " fixedColumn", false, actualKey.isMoreKeysFixedColumn()); + } else { + assertEquals(tag + " fixedOrder", true, actualKey.isMoreKeysFixedOrder()); + assertEquals(tag + " fixedColumn", true, actualKey.isMoreKeysFixedColumn()); + // TODO: Can't handle multiple rows of more keys. + assertEquals(tag + " column", + expectedMoreKeys.length, actualKey.getMoreKeysColumnNumber()); + } + assertNotNull(tag + " moreKeys", actualMoreKeys); + assertEquals(tag, expectedMoreKeys.length, actualMoreKeys.length); + for (int index = 0; index < actualMoreKeys.length; index++) { + final int expectedLabelResId = expectedMoreKeys[index].mLabelResId; + if (expectedLabelResId == ExpectedMoreKey.NO_LABEL) { + assertEquals(tag + " label " + index, null, actualMoreKeys[index].mLabel); + } else { + final CharSequence expectedLabel = getContext().getText(expectedLabelResId); + assertEquals(tag + " label " + index, expectedLabel, actualMoreKeys[index].mLabel); + } + final int expectedIconId = expectedMoreKeys[index].mIconId; + assertEquals(tag + " icon " + index, expectedIconId, actualMoreKeys[index].mIconId); + } + } + + private void doTestNavigationMoreKeysOf(final int code, final InputMethodSubtype subtype, + final int elementId, final int inputType) { + // No navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_NULL, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedNavigateNextMoreKey); + // With previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey); + // With next and previous naviagte flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey, mExpectedNavigateNextMoreKey); + // Action next. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey); + // Action next with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey); + // Action previous. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedNavigateNextMoreKey); + // Action previous with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigateNextMoreKey); + } + + private void doTestNavigationWithEmojiMoreKeysOf(final int code, + final InputMethodSubtype subtype, final int elementId, final int inputType) { + // No navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_NULL, + mExpectedEmojiMoreKey); + // With next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedEmojiMoreKey, mExpectedNavigateNextMoreKey); + // With previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey); + // With next and previous naviagte flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey, + mExpectedNavigateNextMoreKey); + // Action next. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT, + mExpectedEmojiMoreKey); + // Action next with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedEmojiMoreKey); + // Action next with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey); + // Action next with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey); + // Action previous. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS, + mExpectedEmojiMoreKey); + // Action previous with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedEmojiMoreKey, mExpectedNavigateNextMoreKey); + // Action previous with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey); + // Action previous with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigateNextMoreKey); + } + + private void doTestNoNavigationMoreKeysOf(final int code, final InputMethodSubtype subtype, + final int elementId, final int inputType) { + // No navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_NULL, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With next and previous naviagte flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + } + + public void testMoreKeysOfEnterKey() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final InputMethodSubtype subtype = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.US.toString(), SubtypeLocaleUtils.QWERTY); + + // Password field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + // Email field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + // Url field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); + // Phone number field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_PHONE, + InputType.TYPE_CLASS_PHONE); + // Number field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_NUMBER); + // Date-time field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_NORMAL); + // Date field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_DATE); + // Time field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME); + // Text field. + if (isPhone()) { + // The enter key has an Emoji key as one of more keys. + doTestNavigationWithEmojiMoreKeysOf(Constants.CODE_ENTER, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT); + } else { + // Tablet has a dedicated Emoji key, so the Enter key has no Emoji more key. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT); + } + // Short message field. + if (isPhone()) { + // Enter key is switched to Emoji key on a short message field. + // Emoji key has no navigation more keys. + doTestNoNavigationMoreKeysOf(Constants.CODE_EMOJI, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); + } else { + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysKlpTests.java b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysKlpTests.java new file mode 100644 index 000000000..c257e3dee --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysKlpTests.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard; + +import androidx.test.filters.SmallTest; + +@SmallTest +public class KeyboardLayoutSetNavigateMoreKeysKlpTests + extends KeyboardLayoutSetNavigateMoreKeysBase { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysLxxTests.java b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysLxxTests.java new file mode 100644 index 000000000..fadbba0fd --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysLxxTests.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; + +@SmallTest +public class KeyboardLayoutSetNavigateMoreKeysLxxTests + extends KeyboardLayoutSetNavigateMoreKeysBase { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_LXX_LIGHT; + } + + @Override + protected ExpectedMoreKey getExpectedNavigateNextMoreKey() { + return new ExpectedMoreKey(KeyboardIconsSet.NAME_NEXT_KEY); + } + + @Override + protected ExpectedMoreKey getExpectedNavigatePreviousMoreKey() { + return new ExpectedMoreKey(KeyboardIconsSet.NAME_PREVIOUS_KEY); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java new file mode 100644 index 000000000..122caea85 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard; + +import android.content.Context; +import android.content.res.Resources; +import android.test.AndroidTestCase; +import android.view.ContextThemeWrapper; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodSubtype; + +import org.kelar.inputmethod.compat.InputMethodSubtypeCompatUtils; +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet.Builder; +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.RichInputMethodManager; +import org.kelar.inputmethod.latin.RichInputMethodSubtype; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.settings.Settings; +import org.kelar.inputmethod.latin.utils.AdditionalSubtypeUtils; +import org.kelar.inputmethod.latin.utils.ResourceUtils; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.ArrayList; +import java.util.Locale; + +public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { + // All input method subtypes of LatinIME. + private final ArrayList<InputMethodSubtype> mAllSubtypesList = new ArrayList<>(); + + public interface SubtypeFilter { + public boolean accept(final InputMethodSubtype subtype); + } + + public static final SubtypeFilter FILTER_IS_ASCII_CAPABLE = new SubtypeFilter() { + @Override + public boolean accept(InputMethodSubtype subtype) { + return InputMethodSubtypeCompatUtils.isAsciiCapable(subtype); + } + }; + + public static final SubtypeFilter FILTER_IS_ADDITIONAL_SUBTYPE = new SubtypeFilter() { + @Override + public boolean accept(InputMethodSubtype subtype) { + return AdditionalSubtypeUtils.isAdditionalSubtype(subtype); + } + }; + + private RichInputMethodManager mRichImm; + private InputMethodSubtype[] mSavedAdditionalSubtypes; + private int mScreenMetrics; + + protected abstract int getKeyboardThemeForTests(); + + @Override + protected void setUp() throws Exception { + super.setUp(); + final Context context = getContext(); + final Resources res = context.getResources(); + RichInputMethodManager.init(context); + mRichImm = RichInputMethodManager.getInstance(); + + // Save and reset additional subtypes preference. + mSavedAdditionalSubtypes = mRichImm.getAdditionalSubtypes(); + final InputMethodSubtype[] predefinedAdditionalSubtypes = + AdditionalSubtypeUtils.createAdditionalSubtypesArray( + AdditionalSubtypeUtils.createPrefSubtypes( + res.getStringArray(R.array.predefined_subtypes))); + mRichImm.setAdditionalInputMethodSubtypes(predefinedAdditionalSubtypes); + + final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById( + getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES); + setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId)); + KeyboardLayoutSet.onKeyboardThemeChanged(); + + mScreenMetrics = Settings.readScreenMetrics(res); + + final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme(); + final int subtypeCount = imi.getSubtypeCount(); + for (int index = 0; index < subtypeCount; index++) { + mAllSubtypesList.add(imi.getSubtypeAt(index)); + } + } + + @Override + protected void tearDown() throws Exception { + // Restore additional subtypes preference. + mRichImm.setAdditionalInputMethodSubtypes(mSavedAdditionalSubtypes); + super.tearDown(); + } + + protected final ArrayList<InputMethodSubtype> getAllSubtypesList() { + return mAllSubtypesList; + } + + protected final ArrayList<InputMethodSubtype> getSubtypesFilteredBy( + final SubtypeFilter filter) { + final ArrayList<InputMethodSubtype> list = new ArrayList<>(); + for (final InputMethodSubtype subtype : mAllSubtypesList) { + if (filter.accept(subtype)) { + list.add(subtype); + } + } + return list; + } + + protected final boolean isPhone() { + return Constants.isPhone(mScreenMetrics); + } + + protected final InputMethodSubtype getSubtype(final Locale locale, + final String keyboardLayout) { + for (final InputMethodSubtype subtype : mAllSubtypesList) { + final Locale subtypeLocale = SubtypeLocaleUtils.getSubtypeLocale(subtype); + final String subtypeLayout = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype); + if (locale.equals(subtypeLocale) && keyboardLayout.equals(subtypeLayout)) { + // Found subtype that matches locale and keyboard layout. + return subtype; + } + } + for (final InputMethodSubtype subtype : getSubtypesFilteredBy(FILTER_IS_ASCII_CAPABLE)) { + final Locale subtypeLocale = SubtypeLocaleUtils.getSubtypeLocale(subtype); + if (locale.equals(subtypeLocale)) { + // Create additional subtype. + return AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + locale.toString(), keyboardLayout); + } + } + throw new RuntimeException( + "Unknown subtype: locale=" + locale + " keyboardLayout=" + keyboardLayout); + } + + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo) { + return createKeyboardLayoutSet(subtype, editorInfo, false /* voiceInputKeyEnabled */, + false /* languageSwitchKeyEnabled */, false /* splitLayoutEnabled */); + } + + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { + final Context context = getContext(); + final Resources res = context.getResources(); + final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(context); + final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); + final Builder builder = new Builder(context, editorInfo); + builder.setKeyboardGeometry(keyboardWidth, keyboardHeight) + .setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype)) + .setVoiceInputKeyEnabled(voiceInputKeyEnabled) + .setLanguageSwitchKeyEnabled(languageSwitchKeyEnabled) + .setSplitLayoutEnabledByUser(splitLayoutEnabled); + return builder.build(); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutTest.java b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutTest.java new file mode 100644 index 000000000..eb0754a60 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/KeyboardLayoutTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2015 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 org.kelar.inputmethod.keyboard; + +import static org.junit.Assert.assertEquals; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class KeyboardLayoutTest { + @Test + public void testNewKeyboardLayout() { + KeyboardLayout keyboardLayout = KeyboardLayout + .newKeyboardLayout(new ArrayList<Key>(), 11, 12, 13, 14); + + assertEquals(11, keyboardLayout.mMostCommonKeyWidth); + assertEquals(12, keyboardLayout.mMostCommonKeyHeight); + assertEquals(13, keyboardLayout.mKeyboardWidth); + assertEquals(14, keyboardLayout.mKeyboardHeight); + + assertEquals(0, keyboardLayout.getKeyCodes().length); + assertEquals(0, keyboardLayout.getKeyWidths().length); + assertEquals(0, keyboardLayout.getKeyHeights().length); + assertEquals(0, keyboardLayout.getKeyXCoordinates().length); + assertEquals(0, keyboardLayout.getKeyYCoordinates().length); + + Key key1 = new Key("label1", 101, 102, "101", "101hint", 103, 104, 105, 106, 1100, 1101, + 10, 10); + Key key2 = new Key("label2", 201, 103, "201", "201hint", 203, 204, 205, 206, 2100, 2101, + 10, 10); + + ArrayList<Key> sortedKeys = new ArrayList<>(2); + sortedKeys.add(key1); + sortedKeys.add(key2); + keyboardLayout = KeyboardLayout.newKeyboardLayout(sortedKeys, 11, 12, 13, 14); + assertEquals(2, keyboardLayout.getKeyCodes().length); + assertEquals(2, keyboardLayout.getKeyWidths().length); + assertEquals(2, keyboardLayout.getKeyHeights().length); + assertEquals(2, keyboardLayout.getKeyXCoordinates().length); + assertEquals(2, keyboardLayout.getKeyYCoordinates().length); + + assertEquals(102, keyboardLayout.getKeyCodes()[0]); + // xCo + horizontalGap/2 + assertEquals(105 + 5, keyboardLayout.getKeyXCoordinates()[0]); + assertEquals(106, keyboardLayout.getKeyYCoordinates()[0]); + // width - horizontalGap + assertEquals(1100 - 10, keyboardLayout.getKeyWidths()[0]); + // height - verticalGap + assertEquals(1101 - 10, keyboardLayout.getKeyHeights()[0]); + + assertEquals(103, keyboardLayout.getKeyCodes()[1]); + // xCo + horizontalGap/2 + assertEquals(205 + 5, keyboardLayout.getKeyXCoordinates()[1]); + assertEquals(206, keyboardLayout.getKeyYCoordinates()[1]); + // width - horizontalGap + assertEquals(2100 - 10, keyboardLayout.getKeyWidths()[1]); + // height - verticalGap + assertEquals(2101 - 10, keyboardLayout.getKeyHeights()[1]); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/KeyboardThemeTests.java b/tests/src/org/kelar/inputmethod/keyboard/KeyboardThemeTests.java new file mode 100644 index 000000000..ffc5cc9ed --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/KeyboardThemeTests.java @@ -0,0 +1,461 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard; + +import static org.kelar.inputmethod.keyboard.KeyboardTheme.THEME_ID_ICS; +import static org.kelar.inputmethod.keyboard.KeyboardTheme.THEME_ID_KLP; +import static org.kelar.inputmethod.keyboard.KeyboardTheme.THEME_ID_LXX_DARK; +import static org.kelar.inputmethod.keyboard.KeyboardTheme.THEME_ID_LXX_LIGHT; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Build; +import android.os.Build.VERSION_CODES; +import android.preference.PreferenceManager; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class KeyboardThemeTests { + private SharedPreferences mPrefs; + + private static final int THEME_ID_NULL = -1; + private static final int THEME_ID_UNKNOWN = -2; + private static final int THEME_ID_ILLEGAL = -3; + private static final String ILLEGAL_THEME_ID_STRING = "ThisCausesNumberFormatExecption"; + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + @Before + public void setUp() throws Exception { + mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + } + + /* + * Helper functions. + */ + + private static boolean isValidKeyboardThemeId(final int themeId) { + switch (themeId) { + case THEME_ID_ICS: + case THEME_ID_KLP: + case THEME_ID_LXX_LIGHT: + case THEME_ID_LXX_DARK: + return true; + default: + return false; + } + } + + private void setKeyboardThemePreference(final String prefKey, final int themeId) { + final String themeIdString = Integer.toString(themeId); + if (isValidKeyboardThemeId(themeId) || themeId == THEME_ID_UNKNOWN) { + // Set valid theme id to preference. + mPrefs.edit().putString(prefKey, themeIdString).apply(); + return; + } + if (themeId == THEME_ID_NULL) { + // Simulate undefined preference. + mPrefs.edit().remove(prefKey).apply(); + return; + } + // themeId == THEME_ID_ILLEGAL + // Simulate illegal format theme id in preference. + mPrefs.edit().putString(prefKey, ILLEGAL_THEME_ID_STRING).apply(); + } + + private void assertKeyboardTheme(final int sdkVersion, final int expectedThemeId) { + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES); + assertEquals(expectedThemeId, actualTheme.mThemeId); + } + + /* + * Test keyboard theme preference on the same platform version and the same keyboard version. + */ + + private void assertKeyboardThemePreference(final int sdkVersion, final int previousThemeId, + final int expectedThemeId) { + // Clear preferences before testing. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + // Set the preference of the sdkVersion to previousThemeId. + final String prefKey = KeyboardTheme.getPreferenceKey(sdkVersion); + setKeyboardThemePreference(prefKey, previousThemeId); + assertKeyboardTheme(sdkVersion, expectedThemeId); + } + + private void assertKeyboardThemePreferenceOnKlp(final int sdkVersion) { + final int defaultThemeId = THEME_ID_KLP; + assertKeyboardThemePreference(sdkVersion, THEME_ID_NULL, defaultThemeId); + assertKeyboardThemePreference(sdkVersion, THEME_ID_ICS, THEME_ID_ICS); + assertKeyboardThemePreference(sdkVersion, THEME_ID_KLP, THEME_ID_KLP); + assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_LIGHT, THEME_ID_LXX_LIGHT); + assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_DARK, THEME_ID_LXX_DARK); + assertKeyboardThemePreference(sdkVersion, THEME_ID_UNKNOWN, defaultThemeId); + assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId); + } + + @Test + public void testKeyboardThemePreferenceOnKlp() { + assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH); + assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1); + assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN); + assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN_MR1); + assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN_MR2); + assertKeyboardThemePreferenceOnKlp(VERSION_CODES.KITKAT); + } + + private void assertKeyboardThemePreferenceOnLxx(final int sdkVersion) { + final int defaultThemeId = THEME_ID_LXX_LIGHT; + assertKeyboardThemePreference(sdkVersion, THEME_ID_NULL, defaultThemeId); + assertKeyboardThemePreference(sdkVersion, THEME_ID_ICS, THEME_ID_ICS); + assertKeyboardThemePreference(sdkVersion, THEME_ID_KLP, THEME_ID_KLP); + assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_LIGHT, THEME_ID_LXX_LIGHT); + assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_DARK, THEME_ID_LXX_DARK); + assertKeyboardThemePreference(sdkVersion, THEME_ID_UNKNOWN, defaultThemeId); + assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId); + } + + @Test + public void testKeyboardThemePreferenceOnLxx() { + assertKeyboardThemePreferenceOnLxx(Build.VERSION_CODES.LOLLIPOP); + } + + /* + * Test default keyboard theme based on the platform version. + */ + + private void assertDefaultKeyboardTheme(final int sdkVersion, final int previousThemeId, + final int expectedThemeId) { + final String oldPrefKey = KeyboardTheme.KLP_KEYBOARD_THEME_KEY; + setKeyboardThemePreference(oldPrefKey, previousThemeId); + + final KeyboardTheme defaultTheme = KeyboardTheme.getDefaultKeyboardTheme( + mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES); + + assertNotNull(defaultTheme); + assertEquals(expectedThemeId, defaultTheme.mThemeId); + if (sdkVersion <= VERSION_CODES.KITKAT) { + // Old preference must be retained if it is valid. Otherwise it must be pruned. + assertEquals(isValidKeyboardThemeId(previousThemeId), mPrefs.contains(oldPrefKey)); + return; + } + // Old preference must be removed. + assertFalse(mPrefs.contains(oldPrefKey)); + } + + private void assertDefaultKeyboardThemeOnKlp(final int sdkVersion) { + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_KLP); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_ICS); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_KLP); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_KLP); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_KLP); + } + + @Test + public void testDefaultKeyboardThemeOnKlp() { + assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH); + assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1); + assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN); + assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN_MR1); + assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN_MR2); + assertDefaultKeyboardThemeOnKlp(VERSION_CODES.KITKAT); + } + + private void assertDefaultKeyboardThemeOnLxx(final int sdkVersion) { + // Forced to switch to LXX theme. + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_LXX_LIGHT); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_LXX_LIGHT); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT); + assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT); + } + + @Test + public void testDefaultKeyboardThemeOnLxx() { + assertDefaultKeyboardThemeOnLxx(Build.VERSION_CODES.LOLLIPOP); + } + + /* + * Test keyboard theme preference while upgrading the keyboard that doesn't support LXX theme + * to the keyboard that supports LXX theme. + */ + + private void assertUpgradeKeyboardToLxxOn(final int sdkVersion, final int previousThemeId, + final int expectedThemeId) { + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, previousThemeId); + // Clean up new keyboard theme preference to simulate "upgrade to LXX keyboard". + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final KeyboardTheme theme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES); + + assertNotNull(theme); + assertEquals(expectedThemeId, theme.mThemeId); + if (sdkVersion <= VERSION_CODES.KITKAT) { + // New preference must not exist. + assertFalse(mPrefs.contains(KeyboardTheme.LXX_KEYBOARD_THEME_KEY)); + // Old preference must be retained if it is valid. Otherwise it must be pruned. + assertEquals(isValidKeyboardThemeId(previousThemeId), + mPrefs.contains(KeyboardTheme.KLP_KEYBOARD_THEME_KEY)); + if (isValidKeyboardThemeId(previousThemeId)) { + // Old preference must have an expected value. + assertEquals(mPrefs.getString(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, null), + Integer.toString(expectedThemeId)); + } + return; + } + // Old preference must be removed. + assertFalse(mPrefs.contains(KeyboardTheme.KLP_KEYBOARD_THEME_KEY)); + // New preference must not exist. + assertFalse(mPrefs.contains(KeyboardTheme.LXX_KEYBOARD_THEME_KEY)); + } + + private void assertUpgradeKeyboardToLxxOnKlp(final int sdkVersion) { + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_NULL, THEME_ID_KLP); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ICS, THEME_ID_ICS); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_KLP, THEME_ID_KLP); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_KLP); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_KLP); + } + + // Upgrading keyboard on I,J and K. + @Test + public void testUpgradeKeyboardToLxxOnKlp() { + assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH); + assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1); + assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN); + assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN_MR1); + assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN_MR2); + assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.KITKAT); + } + + private void assertUpgradeKeyboardToLxxOnLxx(final int sdkVersion) { + // Forced to switch to LXX theme. + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ICS, THEME_ID_LXX_LIGHT); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_KLP, THEME_ID_LXX_LIGHT); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT); + assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT); + } + + // Upgrading keyboard on L. + @Test + public void testUpgradeKeyboardToLxxOnLxx() { + assertUpgradeKeyboardToLxxOnLxx(Build.VERSION_CODES.LOLLIPOP); + } + + /* + * Test keyboard theme preference while upgrading platform version. + */ + + private void assertUpgradePlatformFromTo(final int oldSdkVersion, final int newSdkVersion, + final int previousThemeId, final int expectedThemeId) { + if (newSdkVersion < oldSdkVersion) { + // No need to test. + return; + } + // Clean up preferences. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final String oldPrefKey = KeyboardTheme.getPreferenceKey(oldSdkVersion); + setKeyboardThemePreference(oldPrefKey, previousThemeId); + + assertKeyboardTheme(newSdkVersion, expectedThemeId); + } + + private void assertUpgradePlatformFromKlpToKlp(final int oldSdkVersion, + final int newSdkVersion) { + assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_KLP); + assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ICS, THEME_ID_ICS); + assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_KLP, THEME_ID_KLP); + assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_KLP); + assertUpgradePlatformFromTo(oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_KLP); + } + + private void assertUpgradePlatformToKlpFrom(final int oldSdkVersion) { + assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.ICE_CREAM_SANDWICH); + assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.ICE_CREAM_SANDWICH_MR1); + assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN); + assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN_MR1); + assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN_MR2); + assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.KITKAT); + } + + // Update platform from I,J, and K to I,J, and K + @Test + public void testUpgradePlatformToKlpFromKlp() { + assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH); + assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1); + assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN); + assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN_MR1); + assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN_MR2); + assertUpgradePlatformToKlpFrom(VERSION_CODES.KITKAT); + } + + private void assertUpgradePlatformToLxxFrom(final int oldSdkVersion) { + // Forced to switch to LXX theme. + final int newSdkVersion = Build.VERSION_CODES.LOLLIPOP; + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_ICS, THEME_ID_LXX_LIGHT); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_KLP, THEME_ID_LXX_LIGHT); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT); + } + + // Update platform from I,J, and K to L + @Test + public void testUpgradePlatformToLxx() { + assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH); + assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1); + assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN); + assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN_MR1); + assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN_MR2); + assertUpgradePlatformToLxxFrom(VERSION_CODES.KITKAT); + } + + // Update platform from L to L. + @Test + public void testUpgradePlatformToLxxFromLxx() { + final int oldSdkVersion = Build.VERSION_CODES.LOLLIPOP; + final int newSdkVersion = Build.VERSION_CODES.LOLLIPOP; + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_ICS, THEME_ID_ICS); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_KLP, THEME_ID_KLP); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_LXX_LIGHT, THEME_ID_LXX_LIGHT); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_LXX_DARK, THEME_ID_LXX_DARK); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT); + assertUpgradePlatformFromTo( + oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT); + } + + /* + * Test that KeyboardTheme array should be sorted by descending order of + * {@link KeyboardTheme#mMinApiVersion}. + */ + private static void assertSortedKeyboardThemeArray(final KeyboardTheme[] array) { + assertNotNull(array); + final int length = array.length; + assertTrue("array length=" + length, length > 0); + for (int index = 0; index < length - 1; index++) { + final KeyboardTheme theme = array[index]; + final KeyboardTheme nextTheme = array[index + 1]; + assertTrue("sorted MinApiVersion: " + + theme.mThemeName + ": minApiVersion=" + theme.mMinApiVersion, + theme.mMinApiVersion >= nextTheme.mMinApiVersion); + } + } + + @Test + public void testSortedKeyboardTheme() { + assertSortedKeyboardThemeArray(KeyboardTheme.KEYBOARD_THEMES); + } + + @Test + public void testSortedAvailableKeyboardTheme() { + assertSortedKeyboardThemeArray(KeyboardTheme.getAvailableThemeArray(getContext())); + } + + /* + * Test for missing selected theme. + */ + private static KeyboardTheme[] LIMITED_THEMES = { + KeyboardTheme.searchKeyboardThemeById(THEME_ID_ICS, KeyboardTheme.KEYBOARD_THEMES), + KeyboardTheme.searchKeyboardThemeById(THEME_ID_KLP, KeyboardTheme.KEYBOARD_THEMES) + }; + static { + Arrays.sort(LIMITED_THEMES); + assertSortedKeyboardThemeArray(LIMITED_THEMES); + } + + @Test + public void testMissingSelectedThemeIcs() { + // Clean up preferences. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final int sdkVersion = VERSION_CODES.ICE_CREAM_SANDWICH; + final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion); + setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_LIGHT); + + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, LIMITED_THEMES); + // LXX_LIGHT is missing, fall-back to KLP. + assertEquals(THEME_ID_KLP, actualTheme.mThemeId); + } + + @Test + public void testMissingSelectedThemeKlp() { + // Clean up preferences. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final int sdkVersion = VERSION_CODES.KITKAT; + final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion); + setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_LIGHT); + + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, LIMITED_THEMES); + // LXX_LIGHT is missing, fall-back to KLP. + assertEquals(THEME_ID_KLP, actualTheme.mThemeId); + } + + @Test + public void testMissingSelectedThemeLxx() { + // Clean up preferences. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final int sdkVersion = Build.VERSION_CODES.LOLLIPOP; + final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion); + setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_DARK); + + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, LIMITED_THEMES); + // LXX_DARK is missing, fall-back to KLP. + assertEquals(THEME_ID_KLP, actualTheme.mThemeId); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderAutoOrderTests.java b/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderAutoOrderTests.java new file mode 100644 index 000000000..15d594daa --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderAutoOrderTests.java @@ -0,0 +1,2604 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.keyboard.MoreKeysKeyboard.MoreKeysKeyboardParams; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@MediumTest +@RunWith(AndroidJUnit4.class) +public class MoreKeysKeyboardBuilderAutoOrderTests { + private static final int WIDTH = 10; + private static final int HEIGHT = 10; + + private static final int KEYBOARD_WIDTH = WIDTH * 10; + private static final int XPOS_L0 = WIDTH * 0 + WIDTH / 2; + private static final int XPOS_L1 = WIDTH * 1 + WIDTH / 2; + private static final int XPOS_L2 = WIDTH * 2 + WIDTH / 2; + private static final int XPOS_L3 = WIDTH * 3 + WIDTH / 2; + private static final int XPOS_M0 = WIDTH * 4 + WIDTH / 2; + private static final int XPOS_M1 = WIDTH * 5 + WIDTH / 2; + private static final int XPOS_R3 = WIDTH * 6 + WIDTH / 2; + private static final int XPOS_R2 = WIDTH * 7 + WIDTH / 2; + private static final int XPOS_R1 = WIDTH * 8 + WIDTH / 2; + private static final int XPOS_R0 = WIDTH * 9 + WIDTH / 2; + + private static MoreKeysKeyboardParams createParams(final int numKeys, final int columnNum, + final int coordXInParent) { + final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams(); + params.setParameters(numKeys, columnNum, WIDTH, HEIGHT, coordXInParent, KEYBOARD_WIDTH, + true /* isMoreKeysFixedColumn */, false /* isMoreKeysFixedOrder */, + 0 /* dividerWidth */); + return params; + } + + @Test + public void testLayoutError() { + MoreKeysKeyboardParams params = null; + try { + final int maxColumns = KEYBOARD_WIDTH / WIDTH; + params = createParams(maxColumns + 1, maxColumns + 1, HEIGHT); + fail("Should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Too small keyboard to hold more keys keyboard. + } + assertNull("Too small keyboard to hold more keys keyboard", params); + } + + // More keys keyboard layout test. + // "[n]" represents n-th key position in more keys keyboard. + // "<1>" is the default key. + + // <1> + @Test + public void testLayout1KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_M0); + assertEquals("1 key auto 5 M0 columns", 1, params.mNumColumns); + assertEquals("1 key auto 5 M0 rows", 1, params.mNumRows); + assertEquals("1 key auto 5 M0 left", 0, params.mLeftKeys); + assertEquals("1 key auto 5 M0 right", 1, params.mRightKeys); + assertEquals("1 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key auto 5 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |<1> + @Test + public void testLayout1KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L0); + assertEquals("1 key auto 5 L0 columns", 1, params.mNumColumns); + assertEquals("1 key auto 5 L0 rows", 1, params.mNumRows); + assertEquals("1 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("1 key auto 5 L0 right", 1, params.mRightKeys); + assertEquals("1 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> + @Test + public void testLayout1KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L1); + assertEquals("1 key auto 5 L1 columns", 1, params.mNumColumns); + assertEquals("1 key auto 5 L1 rows", 1, params.mNumRows); + assertEquals("1 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("1 key auto 5 L1 right", 1, params.mRightKeys); + assertEquals("1 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ <1> + @Test + public void testLayout1KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L2); + assertEquals("1 key auto 5 L2 columns", 1, params.mNumColumns); + assertEquals("1 key auto 5 L2 rows", 1, params.mNumRows); + assertEquals("1 key auto 5 L2 left", 0, params.mLeftKeys); + assertEquals("1 key auto 5 L2 right", 1, params.mRightKeys); + assertEquals("1 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key auto 5 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1>| + @Test + public void testLayout1KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R0); + assertEquals("1 key auto 5 R0 columns", 1, params.mNumColumns); + assertEquals("1 key auto 5 R0 rows", 1, params.mNumRows); + assertEquals("1 key auto 5 R0 left", 0, params.mLeftKeys); + assertEquals("1 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("1 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key auto 5 R0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> ___| + @Test + public void testLayout1KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R1); + assertEquals("1 key auto 5 R1 columns", 1, params.mNumColumns); + assertEquals("1 key auto 5 R1 rows", 1, params.mNumRows); + assertEquals("1 key auto 5 R1 left", 0, params.mLeftKeys); + assertEquals("1 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("1 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key auto 5 R1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> ___ ___| + @Test + public void testLayout1KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R2); + assertEquals("1 key auto 5 R2 columns", 1, params.mNumColumns); + assertEquals("1 key auto 5 R2 rows", 1, params.mNumRows); + assertEquals("1 key auto 5 R2 left", 0, params.mLeftKeys); + assertEquals("1 key auto 5 R2 right", 1, params.mRightKeys); + assertEquals("1 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key auto 5 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> [2] + @Test + public void testLayout2KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_M0); + assertEquals("2 key auto 5 M0 columns", 2, params.mNumColumns); + assertEquals("2 key auto 5 M0 rows", 1, params.mNumRows); + assertEquals("2 key auto 5 M0 left", 0, params.mLeftKeys); + assertEquals("2 key auto 5 M0 right", 2, params.mRightKeys); + assertEquals("2 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key auto 5 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |<1> [2] + @Test + public void testLayout2KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L0); + assertEquals("2 key auto 5 L0 columns", 2, params.mNumColumns); + assertEquals("2 key auto 5 L0 rows", 1, params.mNumRows); + assertEquals("2 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("2 key auto 5 L0 right", 2, params.mRightKeys); + assertEquals("2 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] + @Test + public void testLayout2KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L1); + assertEquals("2 key auto 5 L1 columns", 2, params.mNumColumns); + assertEquals("2 key auto 5 L1 rows", 1, params.mNumRows); + assertEquals("2 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("2 key auto 5 L1 right", 2, params.mRightKeys); + assertEquals("2 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ <1> [2] + @Test + public void testLayout2KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L2); + assertEquals("2 key auto 5 L2 columns", 2, params.mNumColumns); + assertEquals("2 key auto 5 L2 rows", 1, params.mNumRows); + assertEquals("2 key auto 5 L2 left", 0, params.mLeftKeys); + assertEquals("2 key auto 5 L2 right", 2, params.mRightKeys); + assertEquals("2 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key auto 5 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [2] <1>| + @Test + public void testLayout2KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R0); + assertEquals("2 key auto 5 R0 columns", 2, params.mNumColumns); + assertEquals("2 key auto 5 R0 rows", 1, params.mNumRows); + assertEquals("2 key auto 5 R0 left", 1, params.mLeftKeys); + assertEquals("2 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("2 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("2 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key auto 5 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [2] <1> ___| + @Test + public void testLayout2KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R1); + assertEquals("2 key auto 5 R1 columns", 2, params.mNumColumns); + assertEquals("2 key auto 5 R1 rows", 1, params.mNumRows); + assertEquals("2 key auto 5 R1 left", 1, params.mLeftKeys); + assertEquals("2 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("2 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("2 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key auto 5 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // <1> [2] ___| + @Test + public void testLayout2KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R2); + assertEquals("2 key auto 5 R2 columns", 2, params.mNumColumns); + assertEquals("2 key auto 5 R2 rows", 1, params.mNumRows); + assertEquals("2 key auto 5 R2 left", 0, params.mLeftKeys); + assertEquals("2 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("2 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key auto 5 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] + @Test + public void testLayout3KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_M0); + assertEquals("3 key auto 5 M0 columns", 3, params.mNumColumns); + assertEquals("3 key auto 5 M0 rows", 1, params.mNumRows); + assertEquals("3 key auto 5 M0 left", 1, params.mLeftKeys); + assertEquals("3 key auto 5 M0 right", 2, params.mRightKeys); + assertEquals("3 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] + @Test + public void testLayout3KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L0); + assertEquals("3 key auto 5 L0 columns", 3, params.mNumColumns); + assertEquals("3 key auto 5 L0 rows", 1, params.mNumRows); + assertEquals("3 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("3 key auto 5 L0 right", 3, params.mRightKeys); + assertEquals("3 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] + @Test + public void testLayout3KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L1); + assertEquals("3 key auto 5 L1 columns", 3, params.mNumColumns); + assertEquals("3 key auto 5 L1 rows", 1, params.mNumRows); + assertEquals("3 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("3 key auto 5 L1 right", 3, params.mRightKeys); + assertEquals("3 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] + @Test + public void testLayout3KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L2); + assertEquals("3 key auto 5 L2 columns", 3, params.mNumColumns); + assertEquals("3 key auto 5 L2 rows", 1, params.mNumRows); + assertEquals("3 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("3 key auto 5 L2 right", 2, params.mRightKeys); + assertEquals("3 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] [2] <1>| + @Test + public void testLayout3KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R0); + assertEquals("3 key auto 5 R0 columns", 3, params.mNumColumns); + assertEquals("3 key auto 5 R0 rows", 1, params.mNumRows); + assertEquals("3 key auto 5 R0 left", 2, params.mLeftKeys); + assertEquals("3 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("3 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("3 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 5 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] [2] <1> ___| + @Test + public void testLayout3KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R1); + assertEquals("3 key auto 5 R1 columns", 3, params.mNumColumns); + assertEquals("3 key auto 5 R1 rows", 1, params.mNumRows); + assertEquals("3 key auto 5 R1 left", 2, params.mLeftKeys); + assertEquals("3 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("3 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("3 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 5 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] ___| + @Test + public void testLayout3KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R2); + assertEquals("3 key auto 5 R2 columns", 3, params.mNumColumns); + assertEquals("3 key auto 5 R2 rows", 1, params.mNumRows); + assertEquals("3 key auto 5 R2 left", 1, params.mLeftKeys); + assertEquals("3 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("3 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 5 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] + // <1> [2] + @Test + public void testLayout3KeyAuto2M0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_M0); + assertEquals("3 key auto 2 M0 columns", 2, params.mNumColumns); + assertEquals("3 key auto 2 M0 rows", 2, params.mNumRows); + assertEquals("3 key auto 2 M0 left", 0, params.mLeftKeys); + assertEquals("3 key auto 2 M0 right", 2, params.mRightKeys); + assertEquals("3 key auto 2 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 2 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 2 M0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key auto 2 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 2 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |[3] + // |<1> [2] + @Test + public void testLayout3KeyAuto2L0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L0); + assertEquals("3 key auto 2 L0 columns", 2, params.mNumColumns); + assertEquals("3 key auto 2 L0 rows", 2, params.mNumRows); + assertEquals("3 key auto 2 L0 left", 0, params.mLeftKeys); + assertEquals("3 key auto 2 L0 right", 2, params.mRightKeys); + assertEquals("3 key auto 2 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 2 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 2 L0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key auto 2 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 2 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] + // |___ <1> [2] + @Test + public void testLayout3KeyAuto2L1() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L1); + assertEquals("3 key auto 2 L1 columns", 2, params.mNumColumns); + assertEquals("3 key auto 2 L1 rows", 2, params.mNumRows); + assertEquals("3 key auto 2 L1 left", 0, params.mLeftKeys); + assertEquals("3 key auto 2 L1 right", 2, params.mRightKeys); + assertEquals("3 key auto 2 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 2 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 2 L1 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key auto 2 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 2 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // | [3] + // |___ ___ <1> [2] + @Test + public void testLayout3KeyAuto2L2() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L2); + assertEquals("3 key auto 2 L2 columns", 2, params.mNumColumns); + assertEquals("3 key auto 2 L2 rows", 2, params.mNumRows); + assertEquals("3 key auto 2 L2 left", 0, params.mLeftKeys); + assertEquals("3 key auto 2 L2 right", 2, params.mRightKeys); + assertEquals("3 key auto 2 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 2 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 2 L2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key auto 2 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 2 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3]| + // [2] <1>| + @Test + public void testLayout3KeyAuto2R0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R0); + assertEquals("3 key auto 2 R0 columns", 2, params.mNumColumns); + assertEquals("3 key auto 2 R0 rows", 2, params.mNumRows); + assertEquals("3 key auto 2 R0 left", 1, params.mLeftKeys); + assertEquals("3 key auto 2 R0 right", 1, params.mRightKeys); + assertEquals("3 key auto 2 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 2 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key auto 2 R0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key auto 2 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 2 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] | + // [2] <1> ___| + @Test + public void testLayout3KeyAuto2R1() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R1); + assertEquals("3 key auto 2 R1 columns", 2, params.mNumColumns); + assertEquals("3 key auto 2 R1 rows", 2, params.mNumRows); + assertEquals("3 key auto 2 R1 left", 1, params.mLeftKeys); + assertEquals("3 key auto 2 R1 right", 1, params.mRightKeys); + assertEquals("3 key auto 2 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 2 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key auto 2 R1 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key auto 2 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 2 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] | + // <1> [2] ___| + @Test + public void testLayout3KeyAuto2R2() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R2); + assertEquals("3 key auto 2 R2 columns", 2, params.mNumColumns); + assertEquals("3 key auto 2 R2 rows", 2, params.mNumRows); + assertEquals("3 key auto 2 R2 left", 0, params.mLeftKeys); + assertEquals("3 key auto 2 R2 right", 2, params.mRightKeys); + assertEquals("3 key auto 2 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key auto 2 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key auto 2 R2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key auto 2 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key auto 2 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [4] + // [3] <1> [2] + @Test + public void testLayout4KeyAuto3M0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_M0); + assertEquals("4 key auto 3 M0 columns", 3, params.mNumColumns); + assertEquals("4 key auto 3 M0 rows", 2, params.mNumRows); + assertEquals("4 key auto 3 M0 left", 1, params.mLeftKeys); + assertEquals("4 key auto 3 M0 right", 2, params.mRightKeys); + assertEquals("4 key auto 3 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 3 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 3 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 3 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key auto 3 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] + // |<1> [2] [3] + @Test + public void testLayout4KeyAuto3L0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L0); + assertEquals("4 key auto 3 L0 columns", 3, params.mNumColumns); + assertEquals("4 key auto 3 L0 rows", 2, params.mNumRows); + assertEquals("4 key auto 3 L0 left", 0, params.mLeftKeys); + assertEquals("4 key auto 3 L0 right", 3, params.mRightKeys); + assertEquals("4 key auto 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key auto 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key auto 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] + // |___ <1> [2] [3] + @Test + public void testLayout4KeyAuto3L1() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L1); + assertEquals("4 key auto 3 L1 columns", 3, params.mNumColumns); + assertEquals("4 key auto 3 L1 rows", 2, params.mNumRows); + assertEquals("4 key auto 3 L1 left", 0, params.mLeftKeys); + assertEquals("4 key auto 3 L1 right", 3, params.mRightKeys); + assertEquals("4 key auto 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key auto 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key auto 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [4] + // |___ [3] <1> [2] + @Test + public void testLayout4KeyAuto3L2() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L2); + assertEquals("4 key auto 3 L2 columns", 3, params.mNumColumns); + assertEquals("4 key auto 3 L2 rows", 2, params.mNumRows); + assertEquals("4 key auto 3 L2 left", 1, params.mLeftKeys); + assertEquals("4 key auto 3 L2 right", 2, params.mRightKeys); + assertEquals("4 key auto 3 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 3 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 3 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 3 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key auto 3 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4]| + // [3] [2] <1>| + @Test + public void testLayout4KeyAuto3R0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R0); + assertEquals("4 key auto 3 R0 columns", 3, params.mNumColumns); + assertEquals("4 key auto 3 R0 rows", 2, params.mNumRows); + assertEquals("4 key auto 3 R0 left", 2, params.mLeftKeys); + assertEquals("4 key auto 3 R0 right", 1, params.mRightKeys); + assertEquals("4 key auto 3 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key auto 3 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key auto 3 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key auto 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout4KeyAuto3R1() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R1); + assertEquals("4 key auto 3 R1 columns", 3, params.mNumColumns); + assertEquals("4 key auto 3 R1 rows", 2, params.mNumRows); + assertEquals("4 key auto 3 R1 left", 2, params.mLeftKeys); + assertEquals("4 key auto 3 R1 right", 1, params.mRightKeys); + assertEquals("4 key auto 3 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key auto 3 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key auto 3 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key auto 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] ___| + // [3] <1> [2] ___| + @Test + public void testLayout4KeyAuto3R2() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R2); + assertEquals("4 key auto 3 R2 columns", 3, params.mNumColumns); + assertEquals("4 key auto 3 R2 rows", 2, params.mNumRows); + assertEquals("4 key auto 3 R2 left", 1, params.mLeftKeys); + assertEquals("4 key auto 3 R2 right", 2, params.mRightKeys); + assertEquals("4 key auto 3 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 3 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 3 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 3 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key auto 3 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] [4] + @Test + public void testLayout4KeyAuto4M0() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_M0); + assertEquals("4 key auto 4 M0 columns", 4, params.mNumColumns); + assertEquals("4 key auto 4 M0 rows", 1, params.mNumRows); + assertEquals("4 key auto 4 M0 left", 1, params.mLeftKeys); + assertEquals("4 key auto 4 M0 right", 3, params.mRightKeys); + assertEquals("4 key auto 4 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 4 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 4 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key auto 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] + @Test + public void testLayout4KeyAuto4L0() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_L0); + assertEquals("4 key auto 4 L0 columns", 4, params.mNumColumns); + assertEquals("4 key auto 4 L0 rows", 1, params.mNumRows); + assertEquals("4 key auto 4 L0 left", 0, params.mLeftKeys); + assertEquals("4 key auto 4 L0 right", 4, params.mRightKeys); + assertEquals("4 key auto 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key auto 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key auto 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] + @Test + public void testLayout4KeyAuto4L1() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_L1); + assertEquals("4 key auto 4 L1 columns", 4, params.mNumColumns); + assertEquals("4 key auto 4 L1 rows", 1, params.mNumRows); + assertEquals("4 key auto 4 L1 left", 0, params.mLeftKeys); + assertEquals("4 key auto 4 L1 right", 4, params.mRightKeys); + assertEquals("4 key auto 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key auto 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key auto 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] + @Test + public void testLayout4KeyAuto4L2() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_L2); + assertEquals("4 key auto 4 L2 columns", 4, params.mNumColumns); + assertEquals("4 key auto 4 L2 rows", 1, params.mNumRows); + assertEquals("4 key auto 4 L2 left", 1, params.mLeftKeys); + assertEquals("4 key auto 4 L2 right", 3, params.mRightKeys); + assertEquals("4 key auto 4 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 4 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 4 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key auto 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1>| + @Test + public void testLayout4KeyAuto4R0() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_R0); + assertEquals("4 key auto 4 R0 columns", 4, params.mNumColumns); + assertEquals("4 key auto 4 R0 rows", 1, params.mNumRows); + assertEquals("4 key auto 4 R0 left", 3, params.mLeftKeys); + assertEquals("4 key auto 4 R0 right", 1, params.mRightKeys); + assertEquals("4 key auto 4 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 4 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key auto 4 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key auto 4 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key auto 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1> ___| + @Test + public void testLayout4KeyAuto4R1() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_R1); + assertEquals("4 key auto 4 R1 columns", 4, params.mNumColumns); + assertEquals("4 key auto 4 R1 rows", 1, params.mNumRows); + assertEquals("4 key auto 4 R1 left", 3, params.mLeftKeys); + assertEquals("4 key auto 4 R1 right", 1, params.mRightKeys); + assertEquals("4 key auto 4 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 4 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key auto 4 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key auto 4 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key auto 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] <1> [2] ___| + @Test + public void testLayout4KeyAuto4R2() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_R2); + assertEquals("4 key auto 4 R2 columns", 4, params.mNumColumns); + assertEquals("4 key auto 4 R2 rows", 1, params.mNumRows); + assertEquals("4 key auto 4 R2 left", 2, params.mLeftKeys); + assertEquals("4 key auto 4 R2 right", 2, params.mRightKeys); + assertEquals("4 key auto 4 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 4 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 4 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 4 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("4 key auto 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] [4] + @Test + public void testLayout4KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_M0); + assertEquals("4 key auto 5 M0 columns", 4, params.mNumColumns); + assertEquals("4 key auto 5 M0 rows", 1, params.mNumRows); + assertEquals("4 key auto 5 M0 left", 1, params.mLeftKeys); + assertEquals("4 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("4 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] + @Test + public void testLayout4KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L0); + assertEquals("4 key auto 5 L0 columns", 4, params.mNumColumns); + assertEquals("4 key auto 5 L0 rows", 1, params.mNumRows); + assertEquals("4 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("4 key auto 5 L0 right", 4, params.mRightKeys); + assertEquals("4 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key auto 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] + @Test + public void testLayout4KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L1); + assertEquals("4 key auto 5 L1 columns", 4, params.mNumColumns); + assertEquals("4 key auto 5 L1 rows", 1, params.mNumRows); + assertEquals("4 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("4 key auto 5 L1 right", 4, params.mRightKeys); + assertEquals("4 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key auto 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] + @Test + public void testLayout4KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L2); + assertEquals("4 key auto 5 L2 columns", 4, params.mNumColumns); + assertEquals("4 key auto 5 L2 rows", 1, params.mNumRows); + assertEquals("4 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("4 key auto 5 L2 right", 3, params.mRightKeys); + assertEquals("4 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1>| + @Test + public void testLayout4KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R0); + assertEquals("4 key auto 5 R0 columns", 4, params.mNumColumns); + assertEquals("4 key auto 5 R0 rows", 1, params.mNumRows); + assertEquals("4 key auto 5 R0 left", 3, params.mLeftKeys); + assertEquals("4 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("4 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key auto 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 5 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1> ___| + @Test + public void testLayout4KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R1); + assertEquals("4 key auto 5 R1 columns", 4, params.mNumColumns); + assertEquals("4 key auto 5 R1 rows", 1, params.mNumRows); + assertEquals("4 key auto 5 R1 left", 3, params.mLeftKeys); + assertEquals("4 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("4 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key auto 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 5 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] <1> [2] ___| + @Test + public void testLayout4KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R2); + assertEquals("4 key auto 5 R2 columns", 4, params.mNumColumns); + assertEquals("4 key auto 5 R2 rows", 1, params.mNumRows); + assertEquals("4 key auto 5 R2 left", 2, params.mLeftKeys); + assertEquals("4 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("4 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key auto 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("4 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key auto 5 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] + // [3] <1> [2] + @Test + public void testLayout5KeyAuto3M0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_M0); + assertEquals("5 key auto 3 M0 columns", 3, params.mNumColumns); + assertEquals("5 key auto 3 M0 rows", 2, params.mNumRows); + assertEquals("5 key auto 3 M0 left", 1, params.mLeftKeys); + assertEquals("5 key auto 3 M0 right", 2, params.mRightKeys); + assertEquals("5 key auto 3 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 3 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 3 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 3 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key auto 3 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key auto 3 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key auto 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] + // |<1> [2] [3] + @Test + public void testLayout5KeyAuto3L0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L0); + assertEquals("5 key auto 3 L0 columns", 3, params.mNumColumns); + assertEquals("5 key auto 3 L0 rows", 2, params.mNumRows); + assertEquals("5 key auto 3 L0 left", 0, params.mLeftKeys); + assertEquals("5 key auto 3 L0 right", 3, params.mRightKeys); + assertEquals("5 key auto 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key auto 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key auto 3 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key auto 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ <1> [2] [3] + @Test + public void testLayout5KeyAuto3L1() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L1); + assertEquals("5 key auto 3 L1 columns", 3, params.mNumColumns); + assertEquals("5 key auto 3 L1 rows", 2, params.mNumRows); + assertEquals("5 key auto 3 L1 left", 0, params.mLeftKeys); + assertEquals("5 key auto 3 L1 right", 3, params.mRightKeys); + assertEquals("5 key auto 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key auto 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key auto 3 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key auto 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ [3] <1> [2] + @Test + public void testLayout5KeyAuto3L2() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L2); + assertEquals("5 key auto 3 L2 columns", 3, params.mNumColumns); + assertEquals("5 key auto 3 L2 rows", 2, params.mNumRows); + assertEquals("5 key auto 3 L2 left", 1, params.mLeftKeys); + assertEquals("5 key auto 3 L2 right", 2, params.mRightKeys); + assertEquals("5 key auto 3 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 3 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 3 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 3 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key auto 3 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key auto 3 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key auto 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [4]| + // [3] [2] <1>| + @Test + public void testLayout5KeyAuto3R0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R0); + assertEquals("5 key auto 3 R0 columns", 3, params.mNumColumns); + assertEquals("5 key auto 3 R0 rows", 2, params.mNumRows); + assertEquals("5 key auto 3 R0 left", 2, params.mLeftKeys); + assertEquals("5 key auto 3 R0 right", 1, params.mRightKeys); + assertEquals("5 key auto 3 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key auto 3 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key auto 3 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key auto 3 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("5 key auto 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout5KeyAuto3R1() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R1); + assertEquals("5 key auto 3 R1 columns", 3, params.mNumColumns); + assertEquals("5 key auto 3 R1 rows", 2, params.mNumRows); + assertEquals("5 key auto 3 R1 left", 2, params.mLeftKeys); + assertEquals("5 key auto 3 R1 right", 1, params.mRightKeys); + assertEquals("5 key auto 3 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key auto 3 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key auto 3 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key auto 3 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("5 key auto 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] ___| + // [3] <1> [2] ___| + @Test + public void testLayout5KeyAuto3R2() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R2); + assertEquals("5 key auto 3 R2 columns", 3, params.mNumColumns); + assertEquals("5 key auto 3 R2 rows", 2, params.mNumRows); + assertEquals("5 key auto 3 R2 left", 1, params.mLeftKeys); + assertEquals("5 key auto 3 R2 right", 2, params.mRightKeys); + assertEquals("5 key auto 3 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 3 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 3 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 3 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key auto 3 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key auto 3 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key auto 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] + // [3] <1> [2] [4] + @Test + public void testLayout5KeyAuto4M0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_M0); + assertEquals("5 key auto 4 M0 columns", 4, params.mNumColumns); + assertEquals("5 key auto 4 M0 rows", 2, params.mNumRows); + assertEquals("5 key auto 4 M0 left", 1, params.mLeftKeys); + assertEquals("5 key auto 4 M0 right", 3, params.mRightKeys); + assertEquals("5 key auto 4 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 4 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 4 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key auto 4 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key auto 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] + // |<1> [2] [3] [4] + @Test + public void testLayout5KeyAuto4L0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L0); + assertEquals("5 key auto 4 L0 columns", 4, params.mNumColumns); + assertEquals("5 key auto 4 L0 rows", 2, params.mNumRows); + assertEquals("5 key auto 4 L0 left", 0, params.mLeftKeys); + assertEquals("5 key auto 4 L0 right", 4, params.mRightKeys); + assertEquals("5 key auto 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key auto 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key auto 4 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key auto 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] + // |___ <1> [2] [3] [4] + @Test + public void testLayout5KeyAuto4L1() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L1); + assertEquals("5 key auto 4 L1 columns", 4, params.mNumColumns); + assertEquals("5 key auto 4 L1 rows", 2, params.mNumRows); + assertEquals("5 key auto 4 L1 left", 0, params.mLeftKeys); + assertEquals("5 key auto 4 L1 right", 4, params.mRightKeys); + assertEquals("5 key auto 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key auto 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key auto 4 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key auto 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] + // |___ [3] <1> [2] [4] + @Test + public void testLayout5KeyAuto4L2() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L2); + assertEquals("5 key auto 4 L2 columns", 4, params.mNumColumns); + assertEquals("5 key auto 4 L2 rows", 2, params.mNumRows); + assertEquals("5 key auto 4 L2 left", 1, params.mLeftKeys); + assertEquals("5 key auto 4 L2 right", 3, params.mRightKeys); + assertEquals("5 key auto 4 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 4 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 4 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key auto 4 L2 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key auto 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5]| + // [4] [3] [2] <1>| + @Test + public void testLayout5KeyAuto4R0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R0); + assertEquals("5 key auto 4 R0 columns", 4, params.mNumColumns); + assertEquals("5 key auto 4 R0 rows", 2, params.mNumRows); + assertEquals("5 key auto 4 R0 left", 3, params.mLeftKeys); + assertEquals("5 key auto 4 R0 right", 1, params.mRightKeys); + assertEquals("5 key auto 4 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 4 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key auto 4 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key auto 4 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key auto 4 R0 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key auto 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] ___| + // [4] [3] [2] <1> ___| + @Test + public void testLayout5KeyAuto4R1() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R1); + assertEquals("5 key auto 4 R1 columns", 4, params.mNumColumns); + assertEquals("5 key auto 4 R1 rows", 2, params.mNumRows); + assertEquals("5 key auto 4 R1 left", 3, params.mLeftKeys); + assertEquals("5 key auto 4 R1 right", 1, params.mRightKeys); + assertEquals("5 key auto 4 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 4 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key auto 4 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key auto 4 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key auto 4 R1 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key auto 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] ___| + // [4] [3] <1> [2] ___| + @Test + public void testLayout5KeyAuto4R2() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R2); + assertEquals("5 key auto 4 R2 columns", 4, params.mNumColumns); + assertEquals("5 key auto 4 R2 rows", 2, params.mNumRows); + assertEquals("5 key auto 4 R2 left", 2, params.mLeftKeys); + assertEquals("5 key auto 4 R2 right", 2, params.mRightKeys); + assertEquals("5 key auto 4 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 4 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 4 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 4 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("5 key auto 4 R2 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key auto 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [3] <1> [2] [4] + @Test + public void testLayout5KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_M0); + assertEquals("5 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("5 key auto 5 M0 rows", 1, params.mNumRows); + assertEquals("5 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("5 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("5 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("5 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] [5] + @Test + public void testLayout5KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L0); + assertEquals("5 key auto 5 L0 columns", 5, params.mNumColumns); + assertEquals("5 key auto 5 L0 rows", 1, params.mNumRows); + assertEquals("5 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("5 key auto 5 L0 right", 5, params.mRightKeys); + assertEquals("5 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key auto 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key auto 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout5KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L1); + assertEquals("5 key auto 5 L1 columns", 5, params.mNumColumns); + assertEquals("5 key auto 5 L1 rows", 1, params.mNumRows); + assertEquals("5 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("5 key auto 5 L1 right", 5, params.mRightKeys); + assertEquals("5 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key auto 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key auto 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout5KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L2); + assertEquals("5 key auto 5 L2 columns", 5, params.mNumColumns); + assertEquals("5 key auto 5 L2 rows", 1, params.mNumRows); + assertEquals("5 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("5 key auto 5 L2 right", 4, params.mRightKeys); + assertEquals("5 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key auto 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("5 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] [2] <1>| + @Test + public void testLayout5KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R0); + assertEquals("5 key auto 5 R0 columns", 5, params.mNumColumns); + assertEquals("5 key auto 5 R0 rows", 1, params.mNumRows); + assertEquals("5 key auto 5 R0 left", 4, params.mLeftKeys); + assertEquals("5 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("5 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key auto 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key auto 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("5 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout5KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R1); + assertEquals("5 key auto 5 R1 columns", 5, params.mNumColumns); + assertEquals("5 key auto 5 R1 rows", 1, params.mNumRows); + assertEquals("5 key auto 5 R1 left", 4, params.mLeftKeys); + assertEquals("5 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("5 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key auto 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key auto 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("5 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout5KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R2); + assertEquals("5 key auto 5 R2 columns", 5, params.mNumColumns); + assertEquals("5 key auto 5 R2 rows", 1, params.mNumRows); + assertEquals("5 key auto 5 R2 left", 3, params.mLeftKeys); + assertEquals("5 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("5 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key auto 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("5 key auto 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("5 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key auto 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] + // [3] <1> [2] [4] + @Test + public void testLayout6KeyAuto4M0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_M0); + assertEquals("6 key auto 4 M0 columns", 4, params.mNumColumns); + assertEquals("6 key auto 4 M0 rows", 2, params.mNumRows); + assertEquals("6 key auto 4 M0 left", 1, params.mLeftKeys); + assertEquals("6 key auto 4 M0 right", 3, params.mRightKeys); + assertEquals("6 key auto 4 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 4 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 4 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key auto 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("6 key auto 4 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key auto 4 M0 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key auto 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] + // |<1> [2] [3] [4] + @Test + public void testLayout6KeyAuto4L0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L0); + assertEquals("6 key auto 4 L0 columns", 4, params.mNumColumns); + assertEquals("6 key auto 4 L0 rows", 2, params.mNumRows); + assertEquals("6 key auto 4 L0 left", 0, params.mLeftKeys); + assertEquals("6 key auto 4 L0 right", 4, params.mRightKeys); + assertEquals("6 key auto 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key auto 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key auto 4 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key auto 4 L0 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key auto 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] + // |___ <1> [2] [3] [4] + @Test + public void testLayout6KeyAuto4L1() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L1); + assertEquals("6 key auto 4 L1 columns", 4, params.mNumColumns); + assertEquals("6 key auto 4 L1 rows", 2, params.mNumRows); + assertEquals("6 key auto 4 L1 left", 0, params.mLeftKeys); + assertEquals("6 key auto 4 L1 right", 4, params.mRightKeys); + assertEquals("6 key auto 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key auto 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key auto 4 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key auto 4 L1 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key auto 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] + // |___ [3] <1> [2] [4] + @Test + public void testLayout6KeyAuto4L2() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L2); + assertEquals("6 key auto 4 L2 columns", 4, params.mNumColumns); + assertEquals("6 key auto 4 L2 rows", 2, params.mNumRows); + assertEquals("6 key auto 4 L2 left", 1, params.mLeftKeys); + assertEquals("6 key auto 4 L2 right", 3, params.mRightKeys); + assertEquals("6 key auto 4 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 4 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 4 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key auto 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("6 key auto 4 L2 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key auto 4 L2 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key auto 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [5]| + // [4] [3] [2] <1>| + @Test + public void testLayout6KeyAuto4R0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R0); + assertEquals("6 key auto 4 R0 columns", 4, params.mNumColumns); + assertEquals("6 key auto 4 R0 rows", 2, params.mNumRows); + assertEquals("6 key auto 4 R0 left", 3, params.mLeftKeys); + assertEquals("6 key auto 4 R0 right", 1, params.mRightKeys); + assertEquals("6 key auto 4 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 4 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key auto 4 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key auto 4 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("6 key auto 4 R0 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key auto 4 R0 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key auto 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] [5] ___| + // [4] [3] [2] <1> ___| + @Test + public void testLayout6KeyAuto4R1() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R1); + assertEquals("6 key auto 4 R1 columns", 4, params.mNumColumns); + assertEquals("6 key auto 4 R1 rows", 2, params.mNumRows); + assertEquals("6 key auto 4 R1 left", 3, params.mLeftKeys); + assertEquals("6 key auto 4 R1 right", 1, params.mRightKeys); + assertEquals("6 key auto 4 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 4 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key auto 4 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key auto 4 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("6 key auto 4 R1 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key auto 4 R1 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key auto 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] ___| + // [4] [3] <1> [2] ___| + @Test + public void testLayout6KeyAuto4R2() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R2); + assertEquals("6 key auto 4 R2 columns", 4, params.mNumColumns); + assertEquals("6 key auto 4 R2 rows", 2, params.mNumRows); + assertEquals("6 key auto 4 R2 left", 2, params.mLeftKeys); + assertEquals("6 key auto 4 R2 right", 2, params.mRightKeys); + assertEquals("6 key auto 4 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 4 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 4 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key auto 4 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("6 key auto 4 R2 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key auto 4 R2 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key auto 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [6] + // [5] [3] <1> [2] [4] + @Test + public void testLayout6KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_M0); + assertEquals("6 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("6 key auto 5 M0 rows", 2, params.mNumRows); + assertEquals("6 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("6 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("6 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("6 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("6 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout6KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L0); + assertEquals("6 key auto 5 L0 columns", 5, params.mNumColumns); + assertEquals("6 key auto 5 L0 rows", 2, params.mNumRows); + assertEquals("6 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("6 key auto 5 L0 right", 5, params.mRightKeys); + assertEquals("6 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key auto 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key auto 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("6 key auto 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout6KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L1); + assertEquals("6 key auto 5 L1 columns", 5, params.mNumColumns); + assertEquals("6 key auto 5 L1 rows", 2, params.mNumRows); + assertEquals("6 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("6 key auto 5 L1 right", 5, params.mRightKeys); + assertEquals("6 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key auto 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key auto 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("6 key auto 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout6KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L2); + assertEquals("6 key auto 5 L2 columns", 5, params.mNumColumns); + assertEquals("6 key auto 5 L2 rows", 2, params.mNumRows); + assertEquals("6 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("6 key auto 5 L2 right", 4, params.mRightKeys); + assertEquals("6 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key auto 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("6 key auto 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("6 key auto 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6]| + // [5] [4] [3] [2] <1>| + @Test + public void testLayout6KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R0); + assertEquals("6 key auto 5 R0 columns", 5, params.mNumColumns); + assertEquals("6 key auto 5 R0 rows", 2, params.mNumRows); + assertEquals("6 key auto 5 R0 left", 4, params.mLeftKeys); + assertEquals("6 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("6 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key auto 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("6 key auto 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("6 key auto 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] ___| + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout6KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R1); + assertEquals("6 key auto 5 R1 columns", 5, params.mNumColumns); + assertEquals("6 key auto 5 R1 rows", 2, params.mNumRows); + assertEquals("6 key auto 5 R1 left", 4, params.mLeftKeys); + assertEquals("6 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("6 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key auto 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("6 key auto 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("6 key auto 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] ___| + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout6KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R2); + assertEquals("6 key auto 5 R2 columns", 5, params.mNumColumns); + assertEquals("6 key auto 5 R2 rows", 2, params.mNumRows); + assertEquals("6 key auto 5 R2 left", 3, params.mLeftKeys); + assertEquals("6 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("6 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key auto 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("6 key auto 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("6 key auto 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key auto 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] [5] [6] [7] ___ ___ ___| + @Test + public void testLayout7KeyAuto7L0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L0); + assertEquals("7 key auto 7 L0 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 L0 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 L0 left", 0, params.mLeftKeys); + assertEquals("7 key auto 7 L0 right", 7, params.mRightKeys); + assertEquals("7 key auto 7 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key auto 7 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key auto 7 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key auto 7 L0 [6]", 5, params.getColumnPos(5)); + assertEquals("7 key auto 7 L0 [7]", 6, params.getColumnPos(6)); + assertEquals("7 key auto 7 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] [5] [6] [7] ___ ___| + @Test + public void testLayout7KeyAuto7L1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L1); + assertEquals("7 key auto 7 L1 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 L1 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 L1 left", 0, params.mLeftKeys); + assertEquals("7 key auto 7 L1 right", 7, params.mRightKeys); + assertEquals("7 key auto 7 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key auto 7 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key auto 7 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key auto 7 L1 [6]", 5, params.getColumnPos(5)); + assertEquals("7 key auto 7 L1 [7]", 6, params.getColumnPos(6)); + assertEquals("7 key auto 7 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] [5] [6] [7] ___ ___| + @Test + public void testLayout7KeyAuto7L2() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L2); + assertEquals("7 key auto 7 L2 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 L2 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 L2 left", 1, params.mLeftKeys); + assertEquals("7 key auto 7 L2 right", 6, params.mRightKeys); + assertEquals("7 key auto 7 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 7 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key auto 7 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("7 key auto 7 L2 [6]", 4, params.getColumnPos(5)); + assertEquals("7 key auto 7 L2 [7]", 5, params.getColumnPos(6)); + assertEquals("7 key auto 7 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |___ [5] [3] <1> [2] [4] [6] [7] ___ ___| + @Test + public void testLayout7KeyAuto7L3() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L3); + assertEquals("7 key auto 7 L3 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 L3 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 L3 left", 2, params.mLeftKeys); + assertEquals("7 key auto 7 L3 right", 5, params.mRightKeys); + assertEquals("7 key auto 7 L3 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 L3 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 L3 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 7 L3 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key auto 7 L3 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key auto 7 L3 [6]", 3, params.getColumnPos(5)); + assertEquals("7 key auto 7 L3 [7]", 4, params.getColumnPos(6)); + assertEquals("7 key auto 7 L3 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 L3 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |___ [7] [5] [3] <1> [2] [4] [6] ___ ___| + @Test + public void testLayout7KeyAuto7M0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_M0); + assertEquals("7 key auto 7 M0 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 M0 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 M0 left", 3, params.mLeftKeys); + assertEquals("7 key auto 7 M0 right", 4, params.mRightKeys); + assertEquals("7 key auto 7 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 7 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key auto 7 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key auto 7 M0 [6]", 3, params.getColumnPos(5)); + assertEquals("7 key auto 7 M0 [7]", -3, params.getColumnPos(6)); + assertEquals("7 key auto 7 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 M0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [5] [3] <1> [2] [4] [6] ___| + @Test + public void testLayout7KeyAuto7M1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_M1); + assertEquals("7 key auto 7 M1 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 M1 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 M1 left", 3, params.mLeftKeys); + assertEquals("7 key auto 7 M1 right", 4, params.mRightKeys); + assertEquals("7 key auto 7 M1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 M1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 M1 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 7 M1 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key auto 7 M1 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key auto 7 M1 [6]", 3, params.getColumnPos(5)); + assertEquals("7 key auto 7 M1 [7]", -3, params.getColumnPos(6)); + assertEquals("7 key auto 7 M1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 M1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [3] <1> [2] [4] ___| + @Test + public void testLayout7KeyAuto7R3() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R3); + assertEquals("7 key auto 7 R3 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 R3 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 R3 left", 4, params.mLeftKeys); + assertEquals("7 key auto 7 R3 right", 3, params.mRightKeys); + assertEquals("7 key auto 7 R3 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 R3 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 R3 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 7 R3 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key auto 7 R3 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key auto 7 R3 [6]", -3, params.getColumnPos(5)); + assertEquals("7 key auto 7 R3 [7]", -4, params.getColumnPos(6)); + assertEquals("7 key auto 7 R3 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 R3 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [4] [3] <1> [2] ___| + @Test + public void testLayout7KeyAuto7R2() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R2); + assertEquals("7 key auto 7 R2 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 R2 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 R2 left", 5, params.mLeftKeys); + assertEquals("7 key auto 7 R2 right", 2, params.mRightKeys); + assertEquals("7 key auto 7 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 7 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 7 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("7 key auto 7 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("7 key auto 7 R2 [6]", -4, params.getColumnPos(5)); + assertEquals("7 key auto 7 R2 [7]", -5, params.getColumnPos(6)); + assertEquals("7 key auto 7 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 R2 default", WIDTH * 5, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [4] [3] [2] <1> ___| + @Test + public void testLayout7KeyAuto7R1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R1); + assertEquals("7 key auto 7 R1 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 R1 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 R1 left", 6, params.mLeftKeys); + assertEquals("7 key auto 7 R1 right", 1, params.mRightKeys); + assertEquals("7 key auto 7 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key auto 7 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key auto 7 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key auto 7 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("7 key auto 7 R1 [6]", -5, params.getColumnPos(5)); + assertEquals("7 key auto 7 R1 [7]", -6, params.getColumnPos(6)); + assertEquals("7 key auto 7 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 R1 default", WIDTH * 6, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [4] [3] [2] <1>| + @Test + public void testLayout7KeyAuto7R0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R0); + assertEquals("7 key auto 7 R0 columns", 7, params.mNumColumns); + assertEquals("7 key auto 7 R0 rows", 1, params.mNumRows); + assertEquals("7 key auto 7 R0 left", 6, params.mLeftKeys); + assertEquals("7 key auto 7 R0 right", 1, params.mRightKeys); + assertEquals("7 key auto 7 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 7 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key auto 7 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key auto 7 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key auto 7 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("7 key auto 7 R0 [6]", -5, params.getColumnPos(5)); + assertEquals("7 key auto 7 R0 [7]", -6, params.getColumnPos(6)); + assertEquals("7 key auto 7 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 7 R0 default", WIDTH * 6, params.getDefaultKeyCoordX()); + } + + // [6] [7] + // [5] [3] <1> [2] [4] + @Test + public void testLayout7KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_M0); + assertEquals("7 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("7 key auto 5 M0 rows", 2, params.mNumRows); + assertEquals("7 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("7 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("7 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key auto 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout7KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L0); + assertEquals("7 key auto 5 L0 columns", 5, params.mNumColumns); + assertEquals("7 key auto 5 L0 rows", 2, params.mNumRows); + assertEquals("7 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("7 key auto 5 L0 right", 5, params.mRightKeys); + assertEquals("7 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key auto 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key auto 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key auto 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key auto 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout7KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L1); + assertEquals("7 key auto 5 L1 columns", 5, params.mNumColumns); + assertEquals("7 key auto 5 L1 rows", 2, params.mNumRows); + assertEquals("7 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("7 key auto 5 L1 right", 5, params.mRightKeys); + assertEquals("7 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key auto 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key auto 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key auto 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key auto 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout7KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L2); + assertEquals("7 key auto 5 L2 columns", 5, params.mNumColumns); + assertEquals("7 key auto 5 L2 rows", 2, params.mNumRows); + assertEquals("7 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("7 key auto 5 L2 right", 4, params.mRightKeys); + assertEquals("7 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key auto 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("7 key auto 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key auto 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key auto 5 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [7] [6]| + // [5] [4] [3] [2] <1>| + @Test + public void testLayout7KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R0); + assertEquals("7 key auto 5 R0 columns", 5, params.mNumColumns); + assertEquals("7 key auto 5 R0 rows", 2, params.mNumRows); + assertEquals("7 key auto 5 R0 left", 4, params.mLeftKeys); + assertEquals("7 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("7 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key auto 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key auto 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("7 key auto 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key auto 5 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("7 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [7] [6] ___| + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout7KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R1); + assertEquals("7 key auto 5 R1 columns", 5, params.mNumColumns); + assertEquals("7 key auto 5 R1 rows", 2, params.mNumRows); + assertEquals("7 key auto 5 R1 left", 4, params.mLeftKeys); + assertEquals("7 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("7 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key auto 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key auto 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("7 key auto 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key auto 5 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("7 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] ___| + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout7KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R2); + assertEquals("7 key auto 5 R2 columns", 5, params.mNumColumns); + assertEquals("7 key auto 5 R2 rows", 2, params.mNumRows); + assertEquals("7 key auto 5 R2 left", 3, params.mLeftKeys); + assertEquals("7 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("7 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("7 key auto 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("7 key auto 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key auto 5 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key auto 5 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key auto 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [7] + // [6] [4] [5] + // [3] <1> [2] + @Test + public void testLayout7KeyAuto3M0() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_M0); + assertEquals("7 key auto 3 M0 columns", 3, params.mNumColumns); + assertEquals("7 key auto 3 M0 rows", 3, params.mNumRows); + assertEquals("7 key auto 3 M0 left", 1, params.mLeftKeys); + assertEquals("7 key auto 3 M0 right", 2, params.mRightKeys); + assertEquals("7 key auto 3 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 3 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 3 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 3 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key auto 3 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key auto 3 M0 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key auto 3 M0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key auto 3 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[7] + // |[4] [5] [6] + // |<1> [2] [3] + @Test + public void testLayout7KeyAuto3L0() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_L0); + assertEquals("7 key auto 3 L0 columns", 3, params.mNumColumns); + assertEquals("7 key auto 3 L0 rows", 3, params.mNumRows); + assertEquals("7 key auto 3 L0 left", 0, params.mLeftKeys); + assertEquals("7 key auto 3 L0 right", 3, params.mRightKeys); + assertEquals("7 key auto 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key auto 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key auto 3 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key auto 3 L0 [6]", 2, params.getColumnPos(5)); + assertEquals("7 key auto 3 L0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key auto 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [7] + // |___ [4] [5] [6] + // |___ <1> [2] [3] + @Test + public void testLayout7KeyAuto3L1() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_L1); + assertEquals("7 key auto 3 L1 columns", 3, params.mNumColumns); + assertEquals("7 key auto 3 L1 rows", 3, params.mNumRows); + assertEquals("7 key auto 3 L1 left", 0, params.mLeftKeys); + assertEquals("7 key auto 3 L1 right", 3, params.mRightKeys); + assertEquals("7 key auto 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key auto 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key auto 3 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key auto 3 L1 [6]", 2, params.getColumnPos(5)); + assertEquals("7 key auto 3 L1 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key auto 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [7] + // |___ [6] [4] [5] + // |___ [3] <1> [2] + @Test + public void testLayout7KeyAuto3L2() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_L2); + assertEquals("7 key auto 3 L2 columns", 3, params.mNumColumns); + assertEquals("7 key auto 3 L2 rows", 3, params.mNumRows); + assertEquals("7 key auto 3 L2 left", 1, params.mLeftKeys); + assertEquals("7 key auto 3 L2 right", 2, params.mRightKeys); + assertEquals("7 key auto 3 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 3 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 3 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 3 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key auto 3 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key auto 3 L2 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key auto 3 L2 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key auto 3 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [7]| + // [6] [5] [4]| + // [3] [2] <1>| + @Test + public void testLayout7KeyAuto3R0() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_R0); + assertEquals("7 key auto 3 R0 columns", 3, params.mNumColumns); + assertEquals("7 key auto 3 R0 rows", 3, params.mNumRows); + assertEquals("7 key auto 3 R0 left", 2, params.mLeftKeys); + assertEquals("7 key auto 3 R0 right", 1, params.mRightKeys); + assertEquals("7 key auto 3 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key auto 3 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key auto 3 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key auto 3 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key auto 3 R0 [6]", -2, params.getColumnPos(5)); + assertEquals("7 key auto 3 R0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key auto 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [7] ___| + // [6] [5] [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout7KeyAuto3R1() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_R1); + assertEquals("7 key auto 3 R1 columns", 3, params.mNumColumns); + assertEquals("7 key auto 3 R1 rows", 3, params.mNumRows); + assertEquals("7 key auto 3 R1 left", 2, params.mLeftKeys); + assertEquals("7 key auto 3 R1 right", 1, params.mRightKeys); + assertEquals("7 key auto 3 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key auto 3 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key auto 3 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key auto 3 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key auto 3 R1 [6]", -2, params.getColumnPos(5)); + assertEquals("7 key auto 3 R1 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key auto 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [7] ___| + // [6] [4] [5] ___| + // [3] <1> [2] ___| + @Test + public void testLayout7KeyAuto3R2() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_R2); + assertEquals("7 key auto 3 R2 columns", 3, params.mNumColumns); + assertEquals("7 key auto 3 R2 rows", 3, params.mNumRows); + assertEquals("7 key auto 3 R2 left", 1, params.mLeftKeys); + assertEquals("7 key auto 3 R2 right", 2, params.mRightKeys); + assertEquals("7 key auto 3 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key auto 3 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key auto 3 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key auto 3 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key auto 3 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key auto 3 R2 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key auto 3 R2 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key auto 3 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key auto 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [8] [6] [7] + // [5] [3] <1> [2] [4] + @Test + public void testLayout8KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_M0); + assertEquals("8 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("8 key auto 5 M0 rows", 2, params.mNumRows); + assertEquals("8 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("8 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("8 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("8 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key auto 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("8 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout8KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L0); + assertEquals("8 key auto 5 L0 columns", 5, params.mNumColumns); + assertEquals("8 key auto 5 L0 rows", 2, params.mNumRows); + assertEquals("8 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("8 key auto 5 L0 right", 5, params.mRightKeys); + assertEquals("8 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key auto 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key auto 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("8 key auto 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key auto 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key auto 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout8KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L1); + assertEquals("8 key auto 5 L1 columns", 5, params.mNumColumns); + assertEquals("8 key auto 5 L1 rows", 2, params.mNumRows); + assertEquals("8 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("8 key auto 5 L1 right", 5, params.mRightKeys); + assertEquals("8 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key auto 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key auto 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("8 key auto 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key auto 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key auto 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [8] [6] [7] + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout8KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L2); + assertEquals("8 key auto 5 L2 columns", 5, params.mNumColumns); + assertEquals("8 key auto 5 L2 rows", 2, params.mNumRows); + assertEquals("8 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("8 key auto 5 L2 right", 4, params.mRightKeys); + assertEquals("8 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key auto 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key auto 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("8 key auto 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key auto 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key auto 5 L2 [8]", -1, params.getColumnPos(7)); + assertEquals("8 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [8] [7] [6]| + // [5] [4] [3] [2] <1>| + @Test + public void testLayout8KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R0); + assertEquals("8 key auto 5 R0 columns", 5, params.mNumColumns); + assertEquals("8 key auto 5 R0 rows", 2, params.mNumRows); + assertEquals("8 key auto 5 R0 left", 4, params.mLeftKeys); + assertEquals("8 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("8 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key auto 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("8 key auto 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("8 key auto 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key auto 5 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key auto 5 R0 [8]", -2, params.getColumnPos(7)); + assertEquals("8 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key auto 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [8] [7] [6] ___| + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout8KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R1); + assertEquals("8 key auto 5 R1 columns", 5, params.mNumColumns); + assertEquals("8 key auto 5 R1 rows", 2, params.mNumRows); + assertEquals("8 key auto 5 R1 left", 4, params.mLeftKeys); + assertEquals("8 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("8 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key auto 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("8 key auto 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("8 key auto 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key auto 5 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key auto 5 R1 [8]", -2, params.getColumnPos(7)); + assertEquals("8 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key auto 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [8] [6] [7] ___| + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout8KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R2); + assertEquals("8 key auto 5 R2 columns", 5, params.mNumColumns); + assertEquals("8 key auto 5 R2 rows", 2, params.mNumRows); + assertEquals("8 key auto 5 R2 left", 3, params.mLeftKeys); + assertEquals("8 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("8 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key auto 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("8 key auto 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("8 key auto 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key auto 5 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key auto 5 R2 [8]", -1, params.getColumnPos(7)); + assertEquals("8 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key auto 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout9KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_M0); + assertEquals("9 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("9 key auto 5 M0 rows", 2, params.mNumRows); + assertEquals("9 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("9 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("9 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("9 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("9 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key auto 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key auto 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("9 key auto 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout9KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L0); + assertEquals("9 key auto 5 L0 columns", 5, params.mNumColumns); + assertEquals("9 key auto 5 L0 rows", 2, params.mNumRows); + assertEquals("9 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("9 key auto 5 L0 right", 5, params.mRightKeys); + assertEquals("9 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key auto 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key auto 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key auto 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key auto 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key auto 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key auto 5 L0 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout9KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L1); + assertEquals("9 key auto 5 L1 columns", 5, params.mNumColumns); + assertEquals("9 key auto 5 L1 rows", 2, params.mNumRows); + assertEquals("9 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("9 key auto 5 L1 right", 5, params.mRightKeys); + assertEquals("9 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key auto 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key auto 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key auto 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key auto 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key auto 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key auto 5 L1 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key auto 5 L1 adjust",0, params.mTopRowAdjustment); + assertEquals("9 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout9KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L2); + assertEquals("9 key auto 5 L2 columns", 5, params.mNumColumns); + assertEquals("9 key auto 5 L2 rows", 2, params.mNumRows); + assertEquals("9 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("9 key auto 5 L2 right", 4, params.mRightKeys); + assertEquals("9 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key auto 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("9 key auto 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("9 key auto 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key auto 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key auto 5 L2 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key auto 5 L2 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key auto 5 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [9] [8] [7] [6]| + // [5] [4] [3] [2] <1>| + @Test + public void testLayout9KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R0); + assertEquals("9 key auto 5 R0 columns", 5, params.mNumColumns); + assertEquals("9 key auto 5 R0 rows", 2, params.mNumRows); + assertEquals("9 key auto 5 R0 left", 4, params.mLeftKeys); + assertEquals("9 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("9 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("9 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key auto 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("9 key auto 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("9 key auto 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key auto 5 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("9 key auto 5 R0 [8]", -2, params.getColumnPos(7)); + assertEquals("9 key auto 5 R0 [9]", -3, params.getColumnPos(8)); + assertEquals("9 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key auto 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [9] [8] [7] [6] ___| + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout9KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R1); + assertEquals("9 key auto 5 R1 columns", 5, params.mNumColumns); + assertEquals("9 key auto 5 R1 rows", 2, params.mNumRows); + assertEquals("9 key auto 5 R1 left", 4, params.mLeftKeys); + assertEquals("9 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("9 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("9 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key auto 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("9 key auto 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("9 key auto 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key auto 5 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("9 key auto 5 R1 [8]", -2, params.getColumnPos(7)); + assertEquals("9 key auto 5 R1 [9]", -3, params.getColumnPos(8)); + assertEquals("9 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key auto 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [9] [8] [6] [7] ___| + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout9KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R2); + assertEquals("9 key auto 5 R2 columns", 5, params.mNumColumns); + assertEquals("9 key auto 5 R2 rows", 2, params.mNumRows); + assertEquals("9 key auto 5 R2 left", 3, params.mLeftKeys); + assertEquals("9 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("9 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key auto 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("9 key auto 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("9 key auto 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key auto 5 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key auto 5 R2 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key auto 5 R2 [9]", -2, params.getColumnPos(8)); + assertEquals("9 key auto 5 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key auto 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout10KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_M0); + assertEquals("10 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("10 key auto 5 M0 rows", 2, params.mNumRows); + assertEquals("10 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("10 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("10 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("10 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("10 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key auto 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key auto 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("10 key auto 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("10 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] [A] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout10KeyAuto5L0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L0); + assertEquals("10 key auto 5 L0 columns", 5, params.mNumColumns); + assertEquals("10 key auto 5 L0 rows", 2, params.mNumRows); + assertEquals("10 key auto 5 L0 left", 0, params.mLeftKeys); + assertEquals("10 key auto 5 L0 right", 5, params.mRightKeys); + assertEquals("10 key auto 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key auto 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key auto 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key auto 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key auto 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key auto 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key auto 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key auto 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key auto 5 L0 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key auto 5 L0 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key auto 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key auto 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] [A] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout10KeyAuto5L1() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L1); + assertEquals("10 key auto 5 L1 columns", 5, params.mNumColumns); + assertEquals("10 key auto 5 L1 rows", 2, params.mNumRows); + assertEquals("10 key auto 5 L1 left", 0, params.mLeftKeys); + assertEquals("10 key auto 5 L1 right", 5, params.mRightKeys); + assertEquals("10 key auto 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key auto 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key auto 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key auto 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key auto 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key auto 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key auto 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key auto 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key auto 5 L1 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key auto 5 L1 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key auto 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key auto 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [8] [6] [7] [9] [A] + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout10KeyAuto5L2() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L2); + assertEquals("10 key auto 5 L2 columns", 5, params.mNumColumns); + assertEquals("10 key auto 5 L2 rows", 2, params.mNumRows); + assertEquals("10 key auto 5 L2 left", 1, params.mLeftKeys); + assertEquals("10 key auto 5 L2 right", 4, params.mRightKeys); + assertEquals("10 key auto 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key auto 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key auto 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key auto 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("10 key auto 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("10 key auto 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key auto 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key auto 5 L2 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key auto 5 L2 [9]", 2, params.getColumnPos(8)); + assertEquals("10 key auto 5 L2 [A]", 3, params.getColumnPos(9)); + assertEquals("10 key auto 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key auto 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [7] [6]| + // [5] [4] [3] [2] <1>| + @Test + public void testLayout10KeyAuto5R0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R0); + assertEquals("10 key auto 5 R0 columns", 5, params.mNumColumns); + assertEquals("10 key auto 5 R0 rows", 2, params.mNumRows); + assertEquals("10 key auto 5 R0 left", 4, params.mLeftKeys); + assertEquals("10 key auto 5 R0 right", 1, params.mRightKeys); + assertEquals("10 key auto 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key auto 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("10 key auto 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key auto 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("10 key auto 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("10 key auto 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key auto 5 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("10 key auto 5 R0 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key auto 5 R0 [9]", -3, params.getColumnPos(8)); + assertEquals("10 key auto 5 R0 [A]", -4, params.getColumnPos(9)); + assertEquals("10 key auto 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key auto 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [7] [6] ___| + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout10KeyAuto5R1() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R1); + assertEquals("10 key auto 5 R1 columns", 5, params.mNumColumns); + assertEquals("10 key auto 5 R1 rows", 2, params.mNumRows); + assertEquals("10 key auto 5 R1 left", 4, params.mLeftKeys); + assertEquals("10 key auto 5 R1 right", 1, params.mRightKeys); + assertEquals("10 key auto 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key auto 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("10 key auto 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key auto 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("10 key auto 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("10 key auto 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key auto 5 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("10 key auto 5 R1 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key auto 5 R1 [9]", -3, params.getColumnPos(8)); + assertEquals("10 key auto 5 R1 [A]", -4, params.getColumnPos(9)); + assertEquals("10 key auto 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key auto 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [6] [7] ___| + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout10KeyAuto5R2() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R2); + assertEquals("10 key auto 5 R2 columns", 5, params.mNumColumns); + assertEquals("10 key auto 5 R2 rows", 2, params.mNumRows); + assertEquals("10 key auto 5 R2 left", 3, params.mLeftKeys); + assertEquals("10 key auto 5 R2 right", 2, params.mRightKeys); + assertEquals("10 key auto 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key auto 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key auto 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key auto 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("10 key auto 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("10 key auto 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key auto 5 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key auto 5 R2 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key auto 5 R2 [9]", -2, params.getColumnPos(8)); + assertEquals("10 key auto 5 R2 [A]", -3, params.getColumnPos(9)); + assertEquals("10 key auto 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key auto 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [B] + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout11KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(11, 5, XPOS_M0); + assertEquals("11 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("11 key auto 5 M0 rows", 3, params.mNumRows); + assertEquals("11 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("11 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("11 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("11 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("11 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("11 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("11 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("11 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("11 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("11 key auto 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("11 key auto 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("11 key auto 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("11 key auto 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("11 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("11 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [B] [C] + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout12KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(12, 5, XPOS_M0); + assertEquals("12 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("12 key auto 5 M0 rows", 3, params.mNumRows); + assertEquals("12 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("12 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("12 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("12 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("12 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("12 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("12 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("12 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("12 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("12 key auto 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("12 key auto 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("12 key auto 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("12 key auto 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("12 key auto 5 M0 [C]", 1, params.getColumnPos(11)); + assertEquals("12 key auto 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("12 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [D] [B] [C] + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout13KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(13, 5, XPOS_M0); + assertEquals("13 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("13 key auto 5 M0 rows", 3, params.mNumRows); + assertEquals("13 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("13 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("13 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("13 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("13 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("13 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("13 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("13 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("13 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("13 key auto 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("13 key auto 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("13 key auto 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("13 key auto 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("13 key auto 5 M0 [C]", 1, params.getColumnPos(11)); + assertEquals("13 key auto 5 M0 [D]", -1, params.getColumnPos(12)); + assertEquals("13 key auto 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("13 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [D] [B] [C] [E] + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout14KeyAuto5M0() { + MoreKeysKeyboardParams params = createParams(14, 5, XPOS_M0); + assertEquals("13 key auto 5 M0 columns", 5, params.mNumColumns); + assertEquals("13 key auto 5 M0 rows", 3, params.mNumRows); + assertEquals("13 key auto 5 M0 left", 2, params.mLeftKeys); + assertEquals("13 key auto 5 M0 right", 3, params.mRightKeys); + assertEquals("13 key auto 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("13 key auto 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("13 key auto 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("13 key auto 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("13 key auto 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("13 key auto 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("13 key auto 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("13 key auto 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("13 key auto 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("13 key auto 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("13 key auto 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("13 key auto 5 M0 [C]", 1, params.getColumnPos(11)); + assertEquals("13 key auto 5 M0 [D]", -1, params.getColumnPos(12)); + assertEquals("13 key auto 5 M0 [E]", 2, params.getColumnPos(13)); + assertEquals("13 key auto 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("13 key auto 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [J] [I] [H] ___| + // [G] [F] [E] [D] [C] [B] [A] [9] ___| + // [8] [7] [6] [5] [4] [3] [2] <1> ___| + @Test + public void testLayout19KeyAuto8R1() { + MoreKeysKeyboardParams params = createParams(19, 8, XPOS_R1); + assertEquals("19 key auto 8 R1 columns", 8, params.mNumColumns); + assertEquals("19 key auto 8 R1 rows", 3, params.mNumRows); + assertEquals("19 key auto 8 R1 left", 7, params.mLeftKeys); + assertEquals("19 key auto 8 R1 right", 1, params.mRightKeys); + assertEquals("19 key auto 8 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("19 key auto 8 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("19 key auto 8 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("19 key auto 8 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("19 key auto 8 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("19 key auto 8 R1 [6]", -5, params.getColumnPos(5)); + assertEquals("19 key auto 8 R1 [7]", -6, params.getColumnPos(6)); + assertEquals("19 key auto 8 R1 [8]", -7, params.getColumnPos(7)); + assertEquals("19 key auto 8 R1 [9]", 0, params.getColumnPos(8)); + assertEquals("19 key auto 8 R1 [A]", -1, params.getColumnPos(9)); + assertEquals("19 key auto 8 R1 [B]", -2, params.getColumnPos(10)); + assertEquals("19 key auto 8 R1 [C]", -3, params.getColumnPos(11)); + assertEquals("19 key auto 8 R1 [D]", -4, params.getColumnPos(12)); + assertEquals("19 key auto 8 R1 [E]", -5, params.getColumnPos(13)); + assertEquals("19 key auto 8 R1 [F]", -6, params.getColumnPos(14)); + assertEquals("19 key auto 8 R1 [G]", -7, params.getColumnPos(15)); + assertEquals("19 key auto 8 R1 [H]", 0, params.getColumnPos(16)); + assertEquals("19 key auto 8 R1 [I]", -1, params.getColumnPos(17)); + assertEquals("19 key auto 8 R1 [J]", -2, params.getColumnPos(18)); + assertEquals("19 key auto 8 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("19 key auto 8 R1 default", WIDTH * 7, params.getDefaultKeyCoordX()); + } + + // [J] [H] [I] ___| + // [G] [F] [E] [D] [C] [B] [9] [A] ___| + // [8] [7] [6] [5] [4] [3] <1> [2] ___| + @Test + public void testLayout19KeyAuto8R2() { + MoreKeysKeyboardParams params = createParams(19, 8, XPOS_R2); + assertEquals("19 key auto 8 R2 columns", 8, params.mNumColumns); + assertEquals("19 key auto 8 R2 rows", 3, params.mNumRows); + assertEquals("19 key auto 8 R2 left", 6, params.mLeftKeys); + assertEquals("19 key auto 8 R2 right", 2, params.mRightKeys); + assertEquals("19 key auto 8 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("19 key auto 8 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("19 key auto 8 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("19 key auto 8 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("19 key auto 8 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("19 key auto 8 R2 [6]", -4, params.getColumnPos(5)); + assertEquals("19 key auto 8 R2 [7]", -5, params.getColumnPos(6)); + assertEquals("19 key auto 8 R2 [8]", -6, params.getColumnPos(7)); + assertEquals("19 key auto 8 R2 [9]", 0, params.getColumnPos(8)); + assertEquals("19 key auto 8 R2 [A]", 1, params.getColumnPos(9)); + assertEquals("19 key auto 8 R2 [B]", -1, params.getColumnPos(10)); + assertEquals("19 key auto 8 R2 [C]", -2, params.getColumnPos(11)); + assertEquals("19 key auto 8 R2 [D]", -3, params.getColumnPos(12)); + assertEquals("19 key auto 8 R2 [E]", -4, params.getColumnPos(13)); + assertEquals("19 key auto 8 R2 [F]", -5, params.getColumnPos(14)); + assertEquals("19 key auto 8 R2 [G]", -6, params.getColumnPos(15)); + assertEquals("19 key auto 8 R2 [H]", 0, params.getColumnPos(16)); + assertEquals("19 key auto 8 R2 [I]", 1, params.getColumnPos(17)); + assertEquals("19 key auto 8 R2 [J]", -1, params.getColumnPos(18)); + assertEquals("19 key auto 8 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("19 key auto 8 R2 default", WIDTH * 6, params.getDefaultKeyCoordX()); + } + + // [J] [H] [I] ___| + // [G] [F] [E] [D] [B] [9] [A] [C] ___| + // [8] [7] [6] [5] [3] <1> [2] [4] ___| + @Test + public void testLayout19KeyAuto8R3() { + MoreKeysKeyboardParams params = createParams(19, 8, XPOS_R3); + assertEquals("19 key auto 8 R3 columns", 8, params.mNumColumns); + assertEquals("19 key auto 8 R3 rows", 3, params.mNumRows); + assertEquals("19 key auto 8 R3 left", 5, params.mLeftKeys); + assertEquals("19 key auto 8 R3 right", 3, params.mRightKeys); + assertEquals("19 key auto 8 R3 <1>", 0, params.getColumnPos(0)); + assertEquals("19 key auto 8 R3 [2]", 1, params.getColumnPos(1)); + assertEquals("19 key auto 8 R3 [3]", -1, params.getColumnPos(2)); + assertEquals("19 key auto 8 R3 [4]", 2, params.getColumnPos(3)); + assertEquals("19 key auto 8 R3 [5]", -2, params.getColumnPos(4)); + assertEquals("19 key auto 8 R3 [6]", -3, params.getColumnPos(5)); + assertEquals("19 key auto 8 R3 [7]", -4, params.getColumnPos(6)); + assertEquals("19 key auto 8 R3 [8]", -5, params.getColumnPos(7)); + assertEquals("19 key auto 8 R3 [9]", 0, params.getColumnPos(8)); + assertEquals("19 key auto 8 R3 [A]", 1, params.getColumnPos(9)); + assertEquals("19 key auto 8 R3 [B]", -1, params.getColumnPos(10)); + assertEquals("19 key auto 8 R3 [C]", 2, params.getColumnPos(11)); + assertEquals("19 key auto 8 R3 [D]", -2, params.getColumnPos(12)); + assertEquals("19 key auto 8 R3 [E]", -3, params.getColumnPos(13)); + assertEquals("19 key auto 8 R3 [F]", -4, params.getColumnPos(14)); + assertEquals("19 key auto 8 R3 [G]", -5, params.getColumnPos(15)); + assertEquals("19 key auto 8 R3 [H]", 0, params.getColumnPos(16)); + assertEquals("19 key auto 8 R3 [I]", 1, params.getColumnPos(17)); + assertEquals("19 key auto 8 R3 [J]", -1, params.getColumnPos(18)); + assertEquals("19 key auto 8 R3 adjust", -1, params.mTopRowAdjustment); + assertEquals("19 key auto 8 R3 default", WIDTH * 5, params.getDefaultKeyCoordX()); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java b/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java new file mode 100644 index 000000000..2184ef63e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java @@ -0,0 +1,2785 @@ +/* + * 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 org.kelar.inputmethod.keyboard; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.keyboard.MoreKeysKeyboard.MoreKeysKeyboardParams; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@MediumTest +@RunWith(AndroidJUnit4.class) +public class MoreKeysKeyboardBuilderFixedOrderTests { + private static final int WIDTH = 10; + private static final int HEIGHT = 10; + + private static final int KEYBOARD_WIDTH = WIDTH * 10; + private static final int XPOS_L0 = WIDTH * 0 + WIDTH / 2; + private static final int XPOS_L1 = WIDTH * 1 + WIDTH / 2; + private static final int XPOS_L2 = WIDTH * 2 + WIDTH / 2; + private static final int XPOS_L3 = WIDTH * 3 + WIDTH / 2; + private static final int XPOS_M0 = WIDTH * 4 + WIDTH / 2; + private static final int XPOS_M1 = WIDTH * 5 + WIDTH / 2; + private static final int XPOS_R3 = WIDTH * 6 + WIDTH / 2; + private static final int XPOS_R2 = WIDTH * 7 + WIDTH / 2; + private static final int XPOS_R1 = WIDTH * 8 + WIDTH / 2; + private static final int XPOS_R0 = WIDTH * 9 + WIDTH / 2; + + private static MoreKeysKeyboardParams createParams(final int numKeys, final int columnNum, + final int coordXInParent) { + final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams(); + params.setParameters(numKeys, columnNum, WIDTH, HEIGHT, coordXInParent, KEYBOARD_WIDTH, + true /* isMoreKeysFixedColumn */, true /* isMoreKeysFixedOrder */, + 0 /* dividerWidth */); + return params; + } + + @Test + public void testLayoutError() { + MoreKeysKeyboardParams params = null; + try { + final int fixColumns = KEYBOARD_WIDTH / WIDTH; + params = createParams(fixColumns + 1, fixColumns + 1, HEIGHT); + fail("Should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Too small keyboard to hold more keys keyboard. + } + assertNull("Too small keyboard to hold more keys keyboard", params); + } + + // More keys keyboard layout test. + // "[n]" represents n-th key position in more keys keyboard. + // "<m>" is the default key. + + // <1> + @Test + public void testLayout1KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_M0); + assertEquals("1 key fix 5 M0 columns", 1, params.mNumColumns); + assertEquals("1 key fix 5 M0 rows", 1, params.mNumRows); + assertEquals("1 key fix 5 M0 left", 0, params.mLeftKeys); + assertEquals("1 key fix 5 M0 right", 1, params.mRightKeys); + assertEquals("1 key fix 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key fix 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key fix 5 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |<1> + @Test + public void testLayout1KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L0); + assertEquals("1 key fix 5 L0 columns", 1, params.mNumColumns); + assertEquals("1 key fix 5 L0 rows", 1, params.mNumRows); + assertEquals("1 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("1 key fix 5 L0 right", 1, params.mRightKeys); + assertEquals("1 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> + @Test + public void testLayout1KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L1); + assertEquals("1 key fix 5 L1 columns", 1, params.mNumColumns); + assertEquals("1 key fix 5 L1 rows", 1, params.mNumRows); + assertEquals("1 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("1 key fix 5 L1 right", 1, params.mRightKeys); + assertEquals("1 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ <1> + @Test + public void testLayout1KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L2); + assertEquals("1 key fix 5 L2 columns", 1, params.mNumColumns); + assertEquals("1 key fix 5 L2 rows", 1, params.mNumRows); + assertEquals("1 key fix 5 L2 left", 0, params.mLeftKeys); + assertEquals("1 key fix 5 L2 right", 1, params.mRightKeys); + assertEquals("1 key fix 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key fix 5 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1>| + @Test + public void testLayout1KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R0); + assertEquals("1 key fix 5 R0 columns", 1, params.mNumColumns); + assertEquals("1 key fix 5 R0 rows", 1, params.mNumRows); + assertEquals("1 key fix 5 R0 left", 0, params.mLeftKeys); + assertEquals("1 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("1 key fix 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key fix 5 R0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> ___| + @Test + public void testLayout1KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R1); + assertEquals("1 key fix 5 R1 columns", 1, params.mNumColumns); + assertEquals("1 key fix 5 R1 rows", 1, params.mNumRows); + assertEquals("1 key fix 5 R1 left", 0, params.mLeftKeys); + assertEquals("1 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("1 key fix 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key fix 5 R1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> ___ ___| + @Test + public void testLayout1KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R2); + assertEquals("1 key fix 5 R2 columns", 1, params.mNumColumns); + assertEquals("1 key fix 5 R2 rows", 1, params.mNumRows); + assertEquals("1 key fix 5 R2 left", 0, params.mLeftKeys); + assertEquals("1 key fix 5 R2 right", 1, params.mRightKeys); + assertEquals("1 key fix 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key fix 5 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> [2] + @Test + public void testLayout2KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_M0); + assertEquals("2 key fix 5 M0 columns", 2, params.mNumColumns); + assertEquals("2 key fix 5 M0 rows", 1, params.mNumRows); + assertEquals("2 key fix 5 M0 left", 0, params.mLeftKeys); + assertEquals("2 key fix 5 M0 right", 2, params.mRightKeys); + assertEquals("2 key fix 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key fix 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key fix 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key fix 5 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |<1> [2] + @Test + public void testLayout2KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L0); + assertEquals("2 key fix 5 L0 columns", 2, params.mNumColumns); + assertEquals("2 key fix 5 L0 rows", 1, params.mNumRows); + assertEquals("2 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("2 key fix 5 L0 right", 2, params.mRightKeys); + assertEquals("2 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] + @Test + public void testLayout2KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L1); + assertEquals("2 key fix 5 L1 columns", 2, params.mNumColumns); + assertEquals("2 key fix 5 L1 rows", 1, params.mNumRows); + assertEquals("2 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("2 key fix 5 L1 right", 2, params.mRightKeys); + assertEquals("2 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ <1> [2] + @Test + public void testLayout2KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L2); + assertEquals("2 key fix 5 L2 columns", 2, params.mNumColumns); + assertEquals("2 key fix 5 L2 rows", 1, params.mNumRows); + assertEquals("2 key fix 5 L2 left", 0, params.mLeftKeys); + assertEquals("2 key fix 5 L2 right", 2, params.mRightKeys); + assertEquals("2 key fix 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key fix 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key fix 5 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [1] <2>| + @Test + public void testLayout2KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R0); + assertEquals("2 key fix 5 R0 columns", 2, params.mNumColumns); + assertEquals("2 key fix 5 R0 rows", 1, params.mNumRows); + assertEquals("2 key fix 5 R0 left", 1, params.mLeftKeys); + assertEquals("2 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("2 key fix 5 R0 [1]", -1, params.getColumnPos(0)); + assertEquals("2 key fix 5 R0 <2>", 0, params.getColumnPos(1)); + assertEquals("2 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key fix 5 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [1] <2> ___| + @Test + public void testLayout2KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R1); + assertEquals("2 key fix 5 R1 columns", 2, params.mNumColumns); + assertEquals("2 key fix 5 R1 rows", 1, params.mNumRows); + assertEquals("2 key fix 5 R1 left", 1, params.mLeftKeys); + assertEquals("2 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("2 key fix 5 R1 [1]", -1, params.getColumnPos(0)); + assertEquals("2 key fix 5 R1 <2>", 0, params.getColumnPos(1)); + assertEquals("2 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key fix 5 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // <1> [2] ___| + @Test + public void testLayout2KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R2); + assertEquals("2 key fix 5 R2 columns", 2, params.mNumColumns); + assertEquals("2 key fix 5 R2 rows", 1, params.mNumRows); + assertEquals("2 key fix 5 R2 left", 0, params.mLeftKeys); + assertEquals("2 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("2 key fix 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key fix 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key fix 5 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] + // <1> [2] + @Test + public void testLayout3KeyFix2M0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_M0); + assertEquals("3 key fix 2 M0 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 M0 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 M0 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 M0 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 M0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |[3] + // |<1> [2] + @Test + public void testLayout3KeyFix2L0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L0); + assertEquals("3 key fix 2 L0 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 L0 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 L0 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 L0 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 L0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] + // |___ <1> [2] + @Test + public void testLayout3KeyFix2L1() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L1); + assertEquals("3 key fix 2 L1 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 L1 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 L1 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 L1 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 L1 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // | [3] + // |___ ___ <1> [2] + @Test + public void testLayout3KeyFix2L2() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L2); + assertEquals("3 key fix 2 L2 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 L2 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 L2 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 L2 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 L2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3]| + // [1] <2>| + @Test + public void testLayout3KeyFix2R0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R0); + assertEquals("3 key fix 2 R0 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 R0 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 R0 left", 1, params.mLeftKeys); + assertEquals("3 key fix 2 R0 right", 1, params.mRightKeys); + assertEquals("3 key fix 2 R0 [1]", -1, params.getColumnPos(0)); + assertEquals("3 key fix 2 R0 <2>", 0, params.getColumnPos(1)); + assertEquals("3 key fix 2 R0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] ___| + // [1] <2> ___| + @Test + public void testLayout3KeyFix2R1() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R1); + assertEquals("3 key fix 2 R1 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 R1 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 R1 left", 1, params.mLeftKeys); + assertEquals("3 key fix 2 R1 right", 1, params.mRightKeys); + assertEquals("3 key fix 2 R1 [1]", -1, params.getColumnPos(0)); + assertEquals("3 key fix 2 R1 <2>", 0, params.getColumnPos(1)); + assertEquals("3 key fix 2 R1 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] ___| + // <1> [2] ___| + @Test + public void testLayout3KeyFix2R2() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R2); + assertEquals("3 key fix 2 R2 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 R2 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 R2 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 R2 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 R2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] [4] + // <1> [2] + @Test + public void testLayout4KeyFix2M0() { + MoreKeysKeyboardParams params = createParams(4, 2, XPOS_M0); + assertEquals("3 key fix 2 M0 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 M0 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 M0 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 M0 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 M0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("3 key fix 2 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |[3] [4] + // |<1> [2] + @Test + public void testLayout4KeyFix2L0() { + MoreKeysKeyboardParams params = createParams(4, 2, XPOS_L0); + assertEquals("3 key fix 2 L0 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 L0 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 L0 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 L0 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 L0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 L0 [4]", 1, params.getColumnPos(3)); + assertEquals("3 key fix 2 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] [4] + // |___ <1> [2] + @Test + public void testLayout4KeyFix2L1() { + MoreKeysKeyboardParams params = createParams(4, 2, XPOS_L1); + assertEquals("3 key fix 2 L1 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 L1 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 L1 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 L1 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 L1 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 L1 [4]", 1, params.getColumnPos(3)); + assertEquals("3 key fix 2 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // | [3] [4] + // |___ ___ <1> [2] + @Test + public void testLayout4KeyFix2L2() { + MoreKeysKeyboardParams params = createParams(4, 2, XPOS_L2); + assertEquals("3 key fix 2 L2 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 L2 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 L2 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 L2 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 L2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 L2 [4]", 1, params.getColumnPos(3)); + assertEquals("3 key fix 2 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] [4]| + // [1] <2>| + @Test + public void testLayout4KeyFix2R0() { + MoreKeysKeyboardParams params = createParams(4, 2, XPOS_R0); + assertEquals("3 key fix 2 R0 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 R0 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 R0 left", 1, params.mLeftKeys); + assertEquals("3 key fix 2 R0 right", 1, params.mRightKeys); + assertEquals("3 key fix 2 R0 [1]", -1, params.getColumnPos(0)); + assertEquals("3 key fix 2 R0 <2>", 0, params.getColumnPos(1)); + assertEquals("3 key fix 2 R0 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key fix 2 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("3 key fix 2 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] [4] ___| + // [1] <2> ___| + @Test + public void testLayout4KeyFix2R1() { + MoreKeysKeyboardParams params = createParams(4, 2, XPOS_R1); + assertEquals("3 key fix 2 R1 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 R1 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 R1 left", 1, params.mLeftKeys); + assertEquals("3 key fix 2 R1 right", 1, params.mRightKeys); + assertEquals("3 key fix 2 R1 [1]", -1, params.getColumnPos(0)); + assertEquals("3 key fix 2 R1 <2>", 0, params.getColumnPos(1)); + assertEquals("3 key fix 2 R1 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key fix 2 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("3 key fix 2 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] [4] ___| + // <1> [2] ___| + @Test + public void testLayout4KeyFix2R2() { + MoreKeysKeyboardParams params = createParams(4, 2, XPOS_R2); + assertEquals("3 key fix 2 R2 columns", 2, params.mNumColumns); + assertEquals("3 key fix 2 R2 rows", 2, params.mNumRows); + assertEquals("3 key fix 2 R2 left", 0, params.mLeftKeys); + assertEquals("3 key fix 2 R2 right", 2, params.mRightKeys); + assertEquals("3 key fix 2 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 2 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 2 R2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key fix 2 R2 [4]", 1, params.getColumnPos(3)); + assertEquals("3 key fix 2 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 2 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [1] <2> [3] + @Test + public void testLayout3KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_M0); + assertEquals("3 key fix 5 columns", 3, params.mNumColumns); + assertEquals("3 key fix 5 rows", 1, params.mNumRows); + assertEquals("3 key fix 5 left", 1, params.mLeftKeys); + assertEquals("3 key fix 5 right", 2, params.mRightKeys); + assertEquals("3 key fix 5 [1]", -1, params.getColumnPos(0)); + assertEquals("3 key fix 5 <2>", 0, params.getColumnPos(1)); + assertEquals("3 key fix 5 [3]", 1, params.getColumnPos(2)); + assertEquals("3 key fix 5 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 5 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] + @Test + public void testLayout3KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L0); + assertEquals("3 key fix 5 L0 columns", 3, params.mNumColumns); + assertEquals("3 key fix 5 L0 rows", 1, params.mNumRows); + assertEquals("3 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("3 key fix 5 L0 right", 3, params.mRightKeys); + assertEquals("3 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] + @Test + public void testLayout3KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L1); + assertEquals("3 key fix 5 L1 columns", 3, params.mNumColumns); + assertEquals("3 key fix 5 L1 rows", 1, params.mNumRows); + assertEquals("3 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("3 key fix 5 L1 right", 3, params.mRightKeys); + assertEquals("3 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] <2> [3] + @Test + public void testLayout3KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L2); + assertEquals("3 key fix 5 L2 columns", 3, params.mNumColumns); + assertEquals("3 key fix 5 L2 rows", 1, params.mNumRows); + assertEquals("3 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("3 key fix 5 L2 right", 2, params.mRightKeys); + assertEquals("3 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("3 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("3 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("3 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [1] [2] <3>| + @Test + public void testLayout3KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R0); + assertEquals("3 key fix 5 R0 columns", 3, params.mNumColumns); + assertEquals("3 key fix 5 R0 rows", 1, params.mNumRows); + assertEquals("3 key fix 5 R0 left", 2, params.mLeftKeys); + assertEquals("3 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("3 key fix 5 R0 [1]", -2, params.getColumnPos(0)); + assertEquals("3 key fix 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key fix 5 R0 <3>", 0, params.getColumnPos(2)); + assertEquals("3 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 5 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [1] [2] <3> ___| + @Test + public void testLayout3KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R1); + assertEquals("3 key fix 5 R1 columns", 3, params.mNumColumns); + assertEquals("3 key fix 5 R1 rows", 1, params.mNumRows); + assertEquals("3 key fix 5 R1 left", 2, params.mLeftKeys); + assertEquals("3 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("3 key fix 5 R1 [1]", -2, params.getColumnPos(0)); + assertEquals("3 key fix 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key fix 5 R1 <3>", 0, params.getColumnPos(2)); + assertEquals("3 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 5 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [1] <2> [3] ___| + @Test + public void testLayout3KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R2); + assertEquals("3 key fix 5 R2 columns", 3, params.mNumColumns); + assertEquals("3 key fix 5 R2 rows", 1, params.mNumRows); + assertEquals("3 key fix 5 R2 left", 1, params.mLeftKeys); + assertEquals("3 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("3 key fix 5 R2 [1]", -1, params.getColumnPos(0)); + assertEquals("3 key fix 5 R2 <2>", 0, params.getColumnPos(1)); + assertEquals("3 key fix 5 R2 [3]", 1, params.getColumnPos(2)); + assertEquals("3 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key fix 5 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] + // [1] <2> [3] + @Test + public void testLayout4KeyFix3M0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_M0); + assertEquals("4 key fix 3 M0 columns", 3, params.mNumColumns); + assertEquals("4 key fix 3 M0 rows", 2, params.mNumRows); + assertEquals("4 key fix 3 M0 left", 1, params.mLeftKeys); + assertEquals("4 key fix 3 M0 right", 2, params.mRightKeys); + assertEquals("4 key fix 3 M0 [1]", -1, params.getColumnPos(0)); + assertEquals("4 key fix 3 M0 <2>", 0, params.getColumnPos(1)); + assertEquals("4 key fix 3 M0 [3]", 1, params.getColumnPos(2)); + assertEquals("4 key fix 3 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key fix 3 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] + // |<1> [2] [3] + @Test + public void testLayout4KeyFix3L0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L0); + assertEquals("4 key fix 3 L0 columns", 3, params.mNumColumns); + assertEquals("4 key fix 3 L0 rows", 2, params.mNumRows); + assertEquals("4 key fix 3 L0 left", 0, params.mLeftKeys); + assertEquals("4 key fix 3 L0 right", 3, params.mRightKeys); + assertEquals("4 key fix 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key fix 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key fix 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key fix 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key fix 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] + // |___ <1> [2] [3] + @Test + public void testLayout4KeyFix3L1() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L1); + assertEquals("4 key fix 3 L1 columns", 3, params.mNumColumns); + assertEquals("4 key fix 3 L1 rows", 2, params.mNumRows); + assertEquals("4 key fix 3 L1 left", 0, params.mLeftKeys); + assertEquals("4 key fix 3 L1 right", 3, params.mRightKeys); + assertEquals("4 key fix 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key fix 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key fix 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key fix 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key fix 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [4] + // |___ ___ [1] <2> [3] + @Test + public void testLayout4KeyFix3L2() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L2); + assertEquals("4 key fix 3 L2 columns", 3, params.mNumColumns); + assertEquals("4 key fix 3 L2 rows", 2, params.mNumRows); + assertEquals("4 key fix 3 L2 left", 1, params.mLeftKeys); + assertEquals("4 key fix 3 L2 right", 2, params.mRightKeys); + assertEquals("4 key fix 3 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("4 key fix 3 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("4 key fix 3 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("4 key fix 3 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key fix 3 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4]| + // [1] [2] <3>| + @Test + public void testLayout4KeyFix3R0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R0); + assertEquals("4 key fix 3 R0 columns", 3, params.mNumColumns); + assertEquals("4 key fix 3 R0 rows", 2, params.mNumRows); + assertEquals("4 key fix 3 R0 left", 2, params.mLeftKeys); + assertEquals("4 key fix 3 R0 right", 1, params.mRightKeys); + assertEquals("4 key fix 3 R0 [1]", -2, params.getColumnPos(0)); + assertEquals("4 key fix 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key fix 3 R0 <3>", 0, params.getColumnPos(2)); + assertEquals("4 key fix 3 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key fix 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] ___| + // [1] [2] <3> ___| + @Test + public void testLayout4KeyFix3R1() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R1); + assertEquals("4 key fix 3 R1 columns", 3, params.mNumColumns); + assertEquals("4 key fix 3 R1 rows", 2, params.mNumRows); + assertEquals("4 key fix 3 R1 left", 2, params.mLeftKeys); + assertEquals("4 key fix 3 R1 right", 1, params.mRightKeys); + assertEquals("4 key fix 3 R1 [1]", -2, params.getColumnPos(0)); + assertEquals("4 key fix 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key fix 3 R1 <3>", 0, params.getColumnPos(2)); + assertEquals("4 key fix 3 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key fix 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] ___| + // [1] <2> [3] ___| + @Test + public void testLayout4KeyFix3R2() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R2); + assertEquals("4 key fix 3 R2 columns", 3, params.mNumColumns); + assertEquals("4 key fix 3 R2 rows", 2, params.mNumRows); + assertEquals("4 key fix 3 R2 left", 1, params.mLeftKeys); + assertEquals("4 key fix 3 R2 right", 2, params.mRightKeys); + assertEquals("4 key fix 3 R2 [1]", -1, params.getColumnPos(0)); + assertEquals("4 key fix 3 R2 <2>", 0, params.getColumnPos(1)); + assertEquals("4 key fix 3 R2 [3]", 1, params.getColumnPos(2)); + assertEquals("4 key fix 3 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("4 key fix 3 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [5] + // [1] <2> [3] + @Test + public void testLayout5KeyFix3M0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_M0); + assertEquals("5 key fix 3 M0 columns", 3, params.mNumColumns); + assertEquals("5 key fix 3 M0 rows", 2, params.mNumRows); + assertEquals("5 key fix 3 M0 left", 1, params.mLeftKeys); + assertEquals("5 key fix 3 M0 right", 2, params.mRightKeys); + assertEquals("5 key fix 3 M0 [1]", -1, params.getColumnPos(0)); + assertEquals("5 key fix 3 M0 <2>", 0, params.getColumnPos(1)); + assertEquals("5 key fix 3 M0 [3]", 1, params.getColumnPos(2)); + assertEquals("5 key fix 3 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key fix 3 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key fix 3 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key fix 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] + // |<1> [2] [3] + @Test + public void testLayout5KeyFix3L0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L0); + assertEquals("5 key fix 3 L0 columns", 3, params.mNumColumns); + assertEquals("5 key fix 3 L0 rows", 2, params.mNumRows); + assertEquals("5 key fix 3 L0 left", 0, params.mLeftKeys); + assertEquals("5 key fix 3 L0 right", 3, params.mRightKeys); + assertEquals("5 key fix 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key fix 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key fix 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key fix 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key fix 3 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key fix 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ <1> [2] [3] + @Test + public void testLayout5KeyFix3L1() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L1); + assertEquals("5 key fix 3 L1 columns", 3, params.mNumColumns); + assertEquals("5 key fix 3 L1 rows", 2, params.mNumRows); + assertEquals("5 key fix 3 L1 left", 0, params.mLeftKeys); + assertEquals("5 key fix 3 L1 right", 3, params.mRightKeys); + assertEquals("5 key fix 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key fix 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key fix 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key fix 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key fix 3 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key fix 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ [1] <2> [3] + @Test + public void testLayout5KeyFix3L2() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L2); + assertEquals("5 key fix 3 L2 columns", 3, params.mNumColumns); + assertEquals("5 key fix 3 L2 rows", 2, params.mNumRows); + assertEquals("5 key fix 3 L2 left", 1, params.mLeftKeys); + assertEquals("5 key fix 3 L2 right", 2, params.mRightKeys); + assertEquals("5 key fix 3 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("5 key fix 3 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("5 key fix 3 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("5 key fix 3 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key fix 3 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key fix 3 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key fix 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [5]| + // [1] [2] <3>| + @Test + public void testLayout5KeyFix3R0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R0); + assertEquals("5 key fix 3 R0 columns", 3, params.mNumColumns); + assertEquals("5 key fix 3 R0 rows", 2, params.mNumRows); + assertEquals("5 key fix 3 R0 left", 2, params.mLeftKeys); + assertEquals("5 key fix 3 R0 right", 1, params.mRightKeys); + assertEquals("5 key fix 3 R0 [1]", -2, params.getColumnPos(0)); + assertEquals("5 key fix 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key fix 3 R0 <3>", 0, params.getColumnPos(2)); + assertEquals("5 key fix 3 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("5 key fix 3 R0 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] ___| + // [1] [2] <3> ___| + @Test + public void testLayout5KeyFix3R1() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R1); + assertEquals("5 key fix 3 R1 columns", 3, params.mNumColumns); + assertEquals("5 key fix 3 R1 rows", 2, params.mNumRows); + assertEquals("5 key fix 3 R1 left", 2, params.mLeftKeys); + assertEquals("5 key fix 3 R1 right", 1, params.mRightKeys); + assertEquals("5 key fix 3 R1 [1]", -2, params.getColumnPos(0)); + assertEquals("5 key fix 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key fix 3 R1 <3>", 0, params.getColumnPos(2)); + assertEquals("5 key fix 3 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("5 key fix 3 R1 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] ___| + // [1] <2> [3] ___| + @Test + public void testLayout5KeyFix3R2() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R2); + assertEquals("5 key fix 3 R2 columns", 3, params.mNumColumns); + assertEquals("5 key fix 3 R2 rows", 2, params.mNumRows); + assertEquals("5 key fix 3 R2 left", 1, params.mLeftKeys); + assertEquals("5 key fix 3 R2 right", 2, params.mRightKeys); + assertEquals("5 key fix 3 R2 [1]", -1, params.getColumnPos(0)); + assertEquals("5 key fix 3 R2 <2>", 0, params.getColumnPos(1)); + assertEquals("5 key fix 3 R2 [3]", 1, params.getColumnPos(2)); + assertEquals("5 key fix 3 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key fix 3 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key fix 3 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key fix 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [5] [6] + // [1] <2> [3] + @Test + public void testLayout6KeyFix3M0() { + MoreKeysKeyboardParams params = createParams(6, 3, XPOS_M0); + assertEquals("6 key fix 3 M0 columns", 3, params.mNumColumns); + assertEquals("6 key fix 3 M0 rows", 2, params.mNumRows); + assertEquals("6 key fix 3 M0 left", 1, params.mLeftKeys); + assertEquals("6 key fix 3 M0 right", 2, params.mRightKeys); + assertEquals("6 key fix 3 M0 [1]", -1, params.getColumnPos(0)); + assertEquals("6 key fix 3 M0 <2>", 0, params.getColumnPos(1)); + assertEquals("6 key fix 3 M0 [3]", 1, params.getColumnPos(2)); + assertEquals("6 key fix 3 M0 [4]", -1, params.getColumnPos(3)); + assertEquals("6 key fix 3 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 3 M0 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 3 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] [6] + // |<1> [2] [3] + @Test + public void testLayout6KeyFix3L0() { + MoreKeysKeyboardParams params = createParams(6, 3, XPOS_L0); + assertEquals("6 key fix 3 L0 columns", 3, params.mNumColumns); + assertEquals("6 key fix 3 L0 rows", 2, params.mNumRows); + assertEquals("6 key fix 3 L0 left", 0, params.mLeftKeys); + assertEquals("6 key fix 3 L0 right", 3, params.mRightKeys); + assertEquals("6 key fix 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key fix 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key fix 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key fix 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key fix 3 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key fix 3 L0 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key fix 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] [6] + // |___ <1> [2] [3] + @Test + public void testLayout6KeyFix3L1() { + MoreKeysKeyboardParams params = createParams(6, 3, XPOS_L1); + assertEquals("6 key fix 3 L1 columns", 3, params.mNumColumns); + assertEquals("6 key fix 3 L1 rows", 2, params.mNumRows); + assertEquals("6 key fix 3 L1 left", 0, params.mLeftKeys); + assertEquals("6 key fix 3 L1 right", 3, params.mRightKeys); + assertEquals("6 key fix 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key fix 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key fix 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key fix 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key fix 3 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key fix 3 L1 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key fix 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] [6] + // |___ [1] <2> [3] + @Test + public void testLayout6KeyFix3L2() { + MoreKeysKeyboardParams params = createParams(6, 3, XPOS_L2); + assertEquals("6 key fix 3 L2 columns", 3, params.mNumColumns); + assertEquals("6 key fix 3 L2 rows", 2, params.mNumRows); + assertEquals("6 key fix 3 L2 left", 1, params.mLeftKeys); + assertEquals("6 key fix 3 L2 right", 2, params.mRightKeys); + assertEquals("6 key fix 3 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("6 key fix 3 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("6 key fix 3 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("6 key fix 3 L2 [4]", -1, params.getColumnPos(3)); + assertEquals("6 key fix 3 L2 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 3 L2 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 3 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [5] [6]| + // [1] [2] <3>| + @Test + public void testLayout6KeyFix3R0() { + MoreKeysKeyboardParams params = createParams(6, 3, XPOS_R0); + assertEquals("6 key fix 3 R0 columns", 3, params.mNumColumns); + assertEquals("6 key fix 3 R0 rows", 2, params.mNumRows); + assertEquals("6 key fix 3 R0 left", 2, params.mLeftKeys); + assertEquals("6 key fix 3 R0 right", 1, params.mRightKeys); + assertEquals("6 key fix 3 R0 [1]", -2, params.getColumnPos(0)); + assertEquals("6 key fix 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key fix 3 R0 <3>", 0, params.getColumnPos(2)); + assertEquals("6 key fix 3 R0 [4]", -2, params.getColumnPos(3)); + assertEquals("6 key fix 3 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key fix 3 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] [6] ___| + // [1] [2] <3> ___| + @Test + public void testLayout6KeyFix3R1() { + MoreKeysKeyboardParams params = createParams(6, 3, XPOS_R1); + assertEquals("6 key fix 3 R1 columns", 3, params.mNumColumns); + assertEquals("6 key fix 3 R1 rows", 2, params.mNumRows); + assertEquals("6 key fix 3 R1 left", 2, params.mLeftKeys); + assertEquals("6 key fix 3 R1 right", 1, params.mRightKeys); + assertEquals("6 key fix 3 R1 [1]", -2, params.getColumnPos(0)); + assertEquals("6 key fix 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key fix 3 R1 <3>", 0, params.getColumnPos(2)); + assertEquals("6 key fix 3 R1 [4]", -2, params.getColumnPos(3)); + assertEquals("6 key fix 3 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key fix 3 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] [6] ___| + // [1] <2> [3] ___| + @Test + public void testLayout6KeyFix3R2() { + MoreKeysKeyboardParams params = createParams(6, 3, XPOS_R2); + assertEquals("6 key fix 3 R2 columns", 3, params.mNumColumns); + assertEquals("6 key fix 3 R2 rows", 2, params.mNumRows); + assertEquals("6 key fix 3 R2 left", 1, params.mLeftKeys); + assertEquals("6 key fix 3 R2 right", 2, params.mRightKeys); + assertEquals("6 key fix 3 R2 [1]", -1, params.getColumnPos(0)); + assertEquals("6 key fix 3 R2 <2>", 0, params.getColumnPos(1)); + assertEquals("6 key fix 3 R2 [1]", 1, params.getColumnPos(2)); + assertEquals("6 key fix 3 R2 [4]", -1, params.getColumnPos(3)); + assertEquals("6 key fix 3 R2 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 3 R2 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 3 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // <1> [2] [3] [4] + @Test + public void testLayout4KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_M0); + assertEquals("4 key fix 5 columns", 4, params.mNumColumns); + assertEquals("4 key fix 5 rows", 1, params.mNumRows); + assertEquals("4 key fix 5 left", 1, params.mLeftKeys); + assertEquals("4 key fix 5 right", 3, params.mRightKeys); + assertEquals("4 key fix 5 <1>", -1, params.getColumnPos(0)); + assertEquals("4 key fix 5 [2]", 0, params.getColumnPos(1)); + assertEquals("4 key fix 5 [3]", 1, params.getColumnPos(2)); + assertEquals("4 key fix 5 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key fix 5 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 5 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] + @Test + public void testLayout4KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L0); + assertEquals("4 key fix 5 L0 columns", 4, params.mNumColumns); + assertEquals("4 key fix 5 L0 rows", 1, params.mNumRows); + assertEquals("4 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("4 key fix 5 L0 right", 4, params.mRightKeys); + assertEquals("4 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key fix 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] + @Test + public void testLayout4KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L1); + assertEquals("4 key fix 5 L1 columns", 4, params.mNumColumns); + assertEquals("4 key fix 5 L1 rows", 1, params.mNumRows); + assertEquals("4 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("4 key fix 5 L1 right", 4, params.mRightKeys); + assertEquals("4 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key fix 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] <2> [3] [4] + @Test + public void testLayout4KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L2); + assertEquals("4 key fix 5 L2 columns", 4, params.mNumColumns); + assertEquals("4 key fix 5 L2 rows", 1, params.mNumRows); + assertEquals("4 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("4 key fix 5 L2 right", 3, params.mRightKeys); + assertEquals("4 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("4 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("4 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("4 key fix 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] <4>| + @Test + public void testLayout4KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R0); + assertEquals("4 key fix 5 R0 columns", 4, params.mNumColumns); + assertEquals("4 key fix 5 R0 rows", 1, params.mNumRows); + assertEquals("4 key fix 5 R0 left", 3, params.mLeftKeys); + assertEquals("4 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("4 key fix 5 R0 [1]", -3, params.getColumnPos(0)); + assertEquals("4 key fix 5 R0 [2]", -2, params.getColumnPos(1)); + assertEquals("4 key fix 5 R0 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key fix 5 R0 <4>", 0, params.getColumnPos(3)); + assertEquals("4 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 5 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] <4> ___| + @Test + public void testLayout4KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R1); + assertEquals("4 key fix 5 R1 columns", 4, params.mNumColumns); + assertEquals("4 key fix 5 R1 rows", 1, params.mNumRows); + assertEquals("4 key fix 5 R1 left", 3, params.mLeftKeys); + assertEquals("4 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("4 key fix 5 R1 [1]", -3, params.getColumnPos(0)); + assertEquals("4 key fix 5 R1 [2]", -2, params.getColumnPos(1)); + assertEquals("4 key fix 5 R1 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key fix 5 R1 <4>", 0, params.getColumnPos(3)); + assertEquals("4 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 5 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [1] [2] <3> [4] ___| + @Test + public void testLayout4KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R2); + assertEquals("4 key fix 5 R2 columns", 4, params.mNumColumns); + assertEquals("4 key fix 5 R2 rows", 1, params.mNumRows); + assertEquals("4 key fix 5 R2 left", 2, params.mLeftKeys); + assertEquals("4 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("4 key fix 5 R2 [1]", -2, params.getColumnPos(0)); + assertEquals("4 key fix 5 R2 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key fix 5 R2 <3>", 0, params.getColumnPos(2)); + assertEquals("4 key fix 5 R2 [4]", 1, params.getColumnPos(3)); + assertEquals("4 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key fix 5 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] + // [1] <2> [3] [4] + @Test + public void testLayout5KeyFix4M0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_M0); + assertEquals("5 key fix 4 M0 columns", 4, params.mNumColumns); + assertEquals("5 key fix 4 M0 rows", 2, params.mNumRows); + assertEquals("5 key fix 4 M0 left", 1, params.mLeftKeys); + assertEquals("5 key fix 4 M0 right", 3, params.mRightKeys); + assertEquals("5 key fix 4 M0 [1]", -1, params.getColumnPos(0)); + assertEquals("5 key fix 4 M0 <2>", 0, params.getColumnPos(1)); + assertEquals("5 key fix 4 M0 [3]", 1, params.getColumnPos(2)); + assertEquals("5 key fix 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key fix 4 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] + // |<1> [2] [3] [4] + @Test + public void testLayout5KeyFix4L0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L0); + assertEquals("5 key fix 4 L0 columns", 4, params.mNumColumns); + assertEquals("5 key fix 4 L0 rows", 2, params.mNumRows); + assertEquals("5 key fix 4 L0 left", 0, params.mLeftKeys); + assertEquals("5 key fix 4 L0 right", 4, params.mRightKeys); + assertEquals("5 key fix 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key fix 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key fix 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key fix 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key fix 4 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] + // |___ <1> [2] [3] [4] + @Test + public void testLayout5KeyFix4L1() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L1); + assertEquals("5 key fix 4 L1 columns", 4, params.mNumColumns); + assertEquals("5 key fix 4 L1 rows", 2, params.mNumRows); + assertEquals("5 key fix 4 L1 left", 0, params.mLeftKeys); + assertEquals("5 key fix 4 L1 right", 4, params.mRightKeys); + assertEquals("5 key fix 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key fix 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key fix 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key fix 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key fix 4 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] + // |___ [1] <2> [3] [4] + @Test + public void testLayout5KeyFix4L2() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L2); + assertEquals("5 key fix 4 L2 columns", 4, params.mNumColumns); + assertEquals("5 key fix 4 L2 rows", 2, params.mNumRows); + assertEquals("5 key fix 4 L2 left", 1, params.mLeftKeys); + assertEquals("5 key fix 4 L2 right", 3, params.mRightKeys); + assertEquals("5 key fix 4 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("5 key fix 4 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("5 key fix 4 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("5 key fix 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key fix 4 L2 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5]| + // [1] [2] [3] <4>| + @Test + public void testLayout5KeyFix4R0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R0); + assertEquals("5 key fix 4 R0 columns", 4, params.mNumColumns); + assertEquals("5 key fix 4 R0 rows", 2, params.mNumRows); + assertEquals("5 key fix 4 R0 left", 3, params.mLeftKeys); + assertEquals("5 key fix 4 R0 right", 1, params.mRightKeys); + assertEquals("5 key fix 4 R0 [1]", -3, params.getColumnPos(0)); + assertEquals("5 key fix 4 R0 [2]", -2, params.getColumnPos(1)); + assertEquals("5 key fix 4 R0 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key fix 4 R0 <4>", 0, params.getColumnPos(3)); + assertEquals("5 key fix 4 R0 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] ___| + // [1] [2] [3] <4> ___| + @Test + public void testLayout5KeyFix4R1() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R1); + assertEquals("5 key fix 4 R1 columns", 4, params.mNumColumns); + assertEquals("5 key fix 4 R1 rows", 2, params.mNumRows); + assertEquals("5 key fix 4 R1 left", 3, params.mLeftKeys); + assertEquals("5 key fix 4 R1 right", 1, params.mRightKeys); + assertEquals("5 key fix 4 R1 [1]", -3, params.getColumnPos(0)); + assertEquals("5 key fix 4 R1 [2]", -2, params.getColumnPos(1)); + assertEquals("5 key fix 4 R1 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key fix 4 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key fix 4 R1 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] ___| + // [1] [2] <3> [4] ___| + @Test + public void testLayout5KeyFix4R2() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R2); + assertEquals("5 key fix 4 R2 columns", 4, params.mNumColumns); + assertEquals("5 key fix 4 R2 rows", 2, params.mNumRows); + assertEquals("5 key fix 4 R2 left", 2, params.mLeftKeys); + assertEquals("5 key fix 4 R2 right", 2, params.mRightKeys); + assertEquals("5 key fix 4 R2 [1]", -2, params.getColumnPos(0)); + assertEquals("5 key fix 4 R2 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key fix 4 R2 <3>", 0, params.getColumnPos(2)); + assertEquals("5 key fix 4 R2 [4]", 1, params.getColumnPos(3)); + assertEquals("5 key fix 4 R2 [5]", 0, params.getColumnPos(4)); + assertEquals("5 key fix 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [6] + // [1] <2> [3] [4] + @Test + public void testLayout6KeyFix4M0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_M0); + assertEquals("6 key fix 4 M0 columns", 4, params.mNumColumns); + assertEquals("6 key fix 4 M0 rows", 2, params.mNumRows); + assertEquals("6 key fix 4 M0 left", 1, params.mLeftKeys); + assertEquals("6 key fix 4 M0 right", 3, params.mRightKeys); + assertEquals("6 key fix 4 M0 [1]", -1, params.getColumnPos(0)); + assertEquals("6 key fix 4 M0 <2>", 0, params.getColumnPos(1)); + assertEquals("6 key fix 4 M0 [3]", 1, params.getColumnPos(2)); + assertEquals("6 key fix 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("6 key fix 4 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 4 M0 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 4 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("6 key fix 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] + // |<1> [2] [3] [4] + @Test + public void testLayout6KeyFix4L0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L0); + assertEquals("6 key fix 4 L0 columns", 4, params.mNumColumns); + assertEquals("6 key fix 4 L0 rows", 2, params.mNumRows); + assertEquals("6 key fix 4 L0 left", 0, params.mLeftKeys); + assertEquals("6 key fix 4 L0 right", 4, params.mRightKeys); + assertEquals("6 key fix 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key fix 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key fix 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key fix 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key fix 4 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 4 L0 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] + // |___ <1> [2] [3] [4] + @Test + public void testLayout6KeyFix4L1() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L1); + assertEquals("6 key fix 4 L1 columns", 4, params.mNumColumns); + assertEquals("6 key fix 4 L1 rows", 2, params.mNumRows); + assertEquals("6 key fix 4 L1 left", 0, params.mLeftKeys); + assertEquals("6 key fix 4 L1 right", 4, params.mRightKeys); + assertEquals("6 key fix 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key fix 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key fix 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key fix 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key fix 4 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 4 L1 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] + // |___ [1] <2> [3] [4] + @Test + public void testLayout6KeyFix4L2() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L2); + assertEquals("6 key fix 4 L2 columns", 4, params.mNumColumns); + assertEquals("6 key fix 4 L2 rows", 2, params.mNumRows); + assertEquals("6 key fix 4 L2 left", 1, params.mLeftKeys); + assertEquals("6 key fix 4 L2 right", 3, params.mRightKeys); + assertEquals("6 key fix 4 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("6 key fix 4 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("6 key fix 4 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("6 key fix 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("6 key fix 4 L2 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 4 L2 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 4 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("6 key fix 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [6]| + // [1] [2] [3] <4>| + @Test + public void testLayout6KeyFix4R0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R0); + assertEquals("6 key fix 4 R0 columns", 4, params.mNumColumns); + assertEquals("6 key fix 4 R0 rows", 2, params.mNumRows); + assertEquals("6 key fix 4 R0 left", 3, params.mLeftKeys); + assertEquals("6 key fix 4 R0 right", 1, params.mRightKeys); + assertEquals("6 key fix 4 R0 [1]", -3, params.getColumnPos(0)); + assertEquals("6 key fix 4 R0 [2]", -2, params.getColumnPos(1)); + assertEquals("6 key fix 4 R0 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key fix 4 R0 <4>", 0, params.getColumnPos(3)); + assertEquals("6 key fix 4 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key fix 4 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] ___| + // [1] [2] [3] <4> ___| + @Test + public void testLayout6KeyFix4R1() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R1); + assertEquals("6 key fix 4 R1 columns", 4, params.mNumColumns); + assertEquals("6 key fix 4 R1 rows", 2, params.mNumRows); + assertEquals("6 key fix 4 R1 left", 3, params.mLeftKeys); + assertEquals("6 key fix 4 R1 right", 1, params.mRightKeys); + assertEquals("6 key fix 4 R1 [1]", -3, params.getColumnPos(0)); + assertEquals("6 key fix 4 R1 [2]", -2, params.getColumnPos(1)); + assertEquals("6 key fix 4 R1 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key fix 4 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key fix 4 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key fix 4 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] ___| + // [1] [2] <3> [4] ___| + @Test + public void testLayout6KeyFix4R2() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R2); + assertEquals("6 key fix 4 R2 columns", 4, params.mNumColumns); + assertEquals("6 key fix 4 R2 rows", 2, params.mNumRows); + assertEquals("6 key fix 4 R2 left", 2, params.mLeftKeys); + assertEquals("6 key fix 4 R2 right", 2, params.mRightKeys); + assertEquals("6 key fix 4 R2 [1]", -2, params.getColumnPos(0)); + assertEquals("6 key fix 4 R2 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key fix 4 R2 <3>", 0, params.getColumnPos(2)); + assertEquals("6 key fix 4 R2 [4]", 1, params.getColumnPos(3)); + assertEquals("6 key fix 4 R2 [5]", 0, params.getColumnPos(4)); + assertEquals("6 key fix 4 R2 [6]", 1, params.getColumnPos(5)); + assertEquals("6 key fix 4 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("6 key fix 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] + // [1] <2> [3] [4] + @Test + public void testLayout7KeyFix4M0() { + MoreKeysKeyboardParams params = createParams(7, 4, XPOS_M0); + assertEquals("7 key fix 4 M0 columns", 4, params.mNumColumns); + assertEquals("7 key fix 4 M0 rows", 2, params.mNumRows); + assertEquals("7 key fix 4 M0 left", 1, params.mLeftKeys); + assertEquals("7 key fix 4 M0 right", 3, params.mRightKeys); + assertEquals("7 key fix 4 M0 [1]", -1, params.getColumnPos(0)); + assertEquals("7 key fix 4 M0 <2>", 0, params.getColumnPos(1)); + assertEquals("7 key fix 4 M0 [3]", 1, params.getColumnPos(2)); + assertEquals("7 key fix 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key fix 4 M0 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key fix 4 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 4 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] [7] + // |<1> [2] [3] [4] + @Test + public void testLayout7KeyFix4L0() { + MoreKeysKeyboardParams params = createParams(7, 4, XPOS_L0); + assertEquals("7 key fix 4 L0 columns", 4, params.mNumColumns); + assertEquals("7 key fix 4 L0 rows", 2, params.mNumRows); + assertEquals("7 key fix 4 L0 left", 0, params.mLeftKeys); + assertEquals("7 key fix 4 L0 right", 4, params.mRightKeys); + assertEquals("7 key fix 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key fix 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key fix 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key fix 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key fix 4 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key fix 4 L0 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key fix 4 L0 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key fix 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] + // |___ <1> [2] [3] [4] + @Test + public void testLayout7KeyFix4L1() { + MoreKeysKeyboardParams params = createParams(7, 4, XPOS_L1); + assertEquals("7 key fix 4 L1 columns", 4, params.mNumColumns); + assertEquals("7 key fix 4 L1 rows", 2, params.mNumRows); + assertEquals("7 key fix 4 L1 left", 0, params.mLeftKeys); + assertEquals("7 key fix 4 L1 right", 4, params.mRightKeys); + assertEquals("7 key fix 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key fix 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key fix 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key fix 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key fix 4 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key fix 4 L1 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key fix 4 l1 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key fix 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] + // |___ [1] <2> [3] [4] + @Test + public void testLayout7KeyFix4L2() { + MoreKeysKeyboardParams params = createParams(7, 4, XPOS_L2); + assertEquals("7 key fix 4 L2 columns", 4, params.mNumColumns); + assertEquals("7 key fix 4 L2 rows", 2, params.mNumRows); + assertEquals("7 key fix 4 L2 left", 1, params.mLeftKeys); + assertEquals("7 key fix 4 L2 right", 3, params.mRightKeys); + assertEquals("7 key fix 4 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("7 key fix 4 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("7 key fix 4 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("7 key fix 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key fix 4 L2 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key fix 4 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 4 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7]| + // [1] [2] [3] <4>| + @Test + public void testLayout7KeyFix4R0() { + MoreKeysKeyboardParams params = createParams(7, 4, XPOS_R0); + assertEquals("7 key fix 4 R0 columns", 4, params.mNumColumns); + assertEquals("7 key fix 4 R0 rows", 2, params.mNumRows); + assertEquals("7 key fix 4 R0 left", 3, params.mLeftKeys); + assertEquals("7 key fix 4 R0 right", 1, params.mRightKeys); + assertEquals("7 key fix 4 R0 [1]", -3, params.getColumnPos(0)); + assertEquals("7 key fix 4 R0 [2]", -2, params.getColumnPos(1)); + assertEquals("7 key fix 4 R0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key fix 4 R0 <4>", 0, params.getColumnPos(3)); + assertEquals("7 key fix 4 R0 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key fix 4 R0 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key fix 4 R0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key fix 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] ___| + // [1] [2] [3] <4> ___| + @Test + public void testLayout7KeyFix4R1() { + MoreKeysKeyboardParams params = createParams(7, 4, XPOS_R1); + assertEquals("7 key fix 4 R1 columns", 4, params.mNumColumns); + assertEquals("7 key fix 4 R1 rows", 2, params.mNumRows); + assertEquals("7 key fix 4 R1 left", 3, params.mLeftKeys); + assertEquals("7 key fix 4 R1 right", 1, params.mRightKeys); + assertEquals("7 key fix 4 R1 [1]", -3, params.getColumnPos(0)); + assertEquals("7 key fix 4 R1 [2]", -2, params.getColumnPos(1)); + assertEquals("7 key fix 4 R1 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key fix 4 R1 <4>", 0, params.getColumnPos(3)); + assertEquals("7 key fix 4 R1 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key fix 4 R1 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key fix 4 R1 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key fix 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] ___| + // [1] [2] <3> [4] ___| + @Test + public void testLayout7KeyFix4R2() { + MoreKeysKeyboardParams params = createParams(7, 4, XPOS_R2); + assertEquals("7 key fix 4 R2 columns", 4, params.mNumColumns); + assertEquals("7 key fix 4 R2 rows", 2, params.mNumRows); + assertEquals("7 key fix 4 R2 left", 2, params.mLeftKeys); + assertEquals("7 key fix 4 R2 right", 2, params.mRightKeys); + assertEquals("7 key fix 4 R2 [1]", -2, params.getColumnPos(0)); + assertEquals("7 key fix 4 R2 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key fix 4 R2 <3>", 0, params.getColumnPos(2)); + assertEquals("7 key fix 4 R2 [4]", 1, params.getColumnPos(3)); + assertEquals("7 key fix 4 R2 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key fix 4 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 4 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] [8] + // [1] <2> [3] [4] + @Test + public void testLayout8KeyFix4M0() { + MoreKeysKeyboardParams params = createParams(8, 4, XPOS_M0); + assertEquals("8 key fix 4 M0 columns", 4, params.mNumColumns); + assertEquals("8 key fix 4 M0 rows", 2, params.mNumRows); + assertEquals("8 key fix 4 M0 left", 1, params.mLeftKeys); + assertEquals("8 key fix 4 M0 right", 3, params.mRightKeys); + assertEquals("8 key fix 4 M0 [1]", -1, params.getColumnPos(0)); + assertEquals("8 key fix 4 M0 <2>", 0, params.getColumnPos(1)); + assertEquals("8 key fix 4 M0 [3]", 1, params.getColumnPos(2)); + assertEquals("8 key fix 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key fix 4 M0 [5]", -1, params.getColumnPos(4)); + assertEquals("8 key fix 4 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key fix 4 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key fix 4 M0 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key fix 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] [7] [8] + // |<1> [2] [3] [4] + @Test + public void testLayout8KeyFix4L0() { + MoreKeysKeyboardParams params = createParams(8, 4, XPOS_L0); + assertEquals("8 key fix 4 L0 columns", 4, params.mNumColumns); + assertEquals("8 key fix 4 L0 rows", 2, params.mNumRows); + assertEquals("8 key fix 4 L0 left", 0, params.mLeftKeys); + assertEquals("8 key fix 4 L0 right", 4, params.mRightKeys); + assertEquals("8 key fix 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key fix 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key fix 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key fix 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key fix 4 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key fix 4 L0 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key fix 4 L0 [7]", 2, params.getColumnPos(6)); + assertEquals("8 key fix 4 L0 [8]", 3, params.getColumnPos(7)); + assertEquals("8 key fix 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] [8] + // |___ <1> [2] [3] [4] + @Test + public void testLayout8KeyFix4L1() { + MoreKeysKeyboardParams params = createParams(8, 4, XPOS_L1); + assertEquals("8 key fix 4 L1 columns", 4, params.mNumColumns); + assertEquals("8 key fix 4 L1 rows", 2, params.mNumRows); + assertEquals("8 key fix 4 L1 left", 0, params.mLeftKeys); + assertEquals("8 key fix 4 L1 right", 4, params.mRightKeys); + assertEquals("8 key fix 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key fix 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key fix 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key fix 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key fix 4 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key fix 4 L1 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key fix 4 L1 [7]", 2, params.getColumnPos(6)); + assertEquals("8 key fix 4 L1 [8]", 3, params.getColumnPos(7)); + assertEquals("8 key fix 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] [8] + // |___ [1] <2> [3] [4] + @Test + public void testLayout8KeyFix4L2() { + MoreKeysKeyboardParams params = createParams(8, 4, XPOS_L2); + assertEquals("8 key fix 4 L2 columns", 4, params.mNumColumns); + assertEquals("8 key fix 4 L2 rows", 2, params.mNumRows); + assertEquals("8 key fix 4 L2 left", 1, params.mLeftKeys); + assertEquals("8 key fix 4 L2 right", 3, params.mRightKeys); + assertEquals("8 key fix 4 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("8 key fix 4 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("8 key fix 4 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("8 key fix 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key fix 4 L2 [5]", -1, params.getColumnPos(4)); + assertEquals("8 key fix 4 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key fix 4 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key fix 4 L2 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key fix 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] [8]| + // [1] [2] [3] <4>| + @Test + public void testLayout8KeyFix4R0() { + MoreKeysKeyboardParams params = createParams(8, 4, XPOS_R0); + assertEquals("8 key fix 4 R0 columns", 4, params.mNumColumns); + assertEquals("8 key fix 4 R0 rows", 2, params.mNumRows); + assertEquals("8 key fix 4 R0 left", 3, params.mLeftKeys); + assertEquals("8 key fix 4 R0 right", 1, params.mRightKeys); + assertEquals("8 key fix 4 R0 [1]", -3, params.getColumnPos(0)); + assertEquals("8 key fix 4 R0 [2]", -2, params.getColumnPos(1)); + assertEquals("8 key fix 4 R0 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key fix 4 R0 <4>", 0, params.getColumnPos(3)); + assertEquals("8 key fix 4 R0 [5]", -3, params.getColumnPos(4)); + assertEquals("8 key fix 4 R0 [6]", -2, params.getColumnPos(5)); + assertEquals("8 key fix 4 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key fix 4 R0 [8]", 0, params.getColumnPos(7)); + assertEquals("8 key fix 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] [8] ___| + // [1] [2] [3] <4> ___| + @Test + public void testLayout8KeyFix4R1() { + MoreKeysKeyboardParams params = createParams(8, 4, XPOS_R1); + assertEquals("8 key fix 4 R1 columns", 4, params.mNumColumns); + assertEquals("8 key fix 4 R1 rows", 2, params.mNumRows); + assertEquals("8 key fix 4 R1 left", 3, params.mLeftKeys); + assertEquals("8 key fix 4 R1 right", 1, params.mRightKeys); + assertEquals("8 key fix 4 R1 [1]", -3, params.getColumnPos(0)); + assertEquals("8 key fix 4 R1 [2]", -2, params.getColumnPos(1)); + assertEquals("8 key fix 4 R1 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key fix 4 R1 <4>", 0, params.getColumnPos(3)); + assertEquals("8 key fix 4 R1 [5]", -3, params.getColumnPos(4)); + assertEquals("8 key fix 4 R1 [6]", -2, params.getColumnPos(5)); + assertEquals("8 key fix 4 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key fix 4 R1 [8]", 0, params.getColumnPos(7)); + assertEquals("8 key fix 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] [8] ___| + // [1] [2] <3> [4] ___| + @Test + public void testLayout8KeyFix4R2() { + MoreKeysKeyboardParams params = createParams(8, 4, XPOS_R2); + assertEquals("8 key fix 4 R2 columns", 4, params.mNumColumns); + assertEquals("8 key fix 4 R2 rows", 2, params.mNumRows); + assertEquals("8 key fix 4 R2 left", 2, params.mLeftKeys); + assertEquals("8 key fix 4 R2 right", 2, params.mRightKeys); + assertEquals("8 key fix 4 R2 [1]", -2, params.getColumnPos(0)); + assertEquals("8 key fix 4 R2 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key fix 4 R2 <3>", 0, params.getColumnPos(2)); + assertEquals("8 key fix 4 R2 [4]", 1, params.getColumnPos(3)); + assertEquals("8 key fix 4 R2 [5]", -2, params.getColumnPos(4)); + assertEquals("8 key fix 4 R2 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key fix 4 R2 [7]", 0, params.getColumnPos(6)); + assertEquals("8 key fix 4 R2 [8]", 1, params.getColumnPos(7)); + assertEquals("8 key fix 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [1] [2] <3> [4] [5] + @Test + public void testLayout5KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_M0); + assertEquals("5 key fix 5 columns", 5, params.mNumColumns); + assertEquals("5 key fix 5 rows", 1, params.mNumRows); + assertEquals("5 key fix 5 left", 2, params.mLeftKeys); + assertEquals("5 key fix 5 right", 3, params.mRightKeys); + assertEquals("5 key fix 5 [1]", -2, params.getColumnPos(0)); + assertEquals("5 key fix 5 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key fix 5 <3>", 0, params.getColumnPos(2)); + assertEquals("5 key fix 5 [4]", 1, params.getColumnPos(3)); + assertEquals("5 key fix 5 [5]", 2, params.getColumnPos(4)); + assertEquals("5 key fix 5 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 5 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] [5] + @Test + public void testLayout5KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L0); + assertEquals("5 key fix 5 L0 columns", 5, params.mNumColumns); + assertEquals("5 key fix 5 L0 rows", 1, params.mNumRows); + assertEquals("5 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("5 key fix 5 L0 right", 5, params.mRightKeys); + assertEquals("5 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key fix 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key fix 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout5KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L1); + assertEquals("5 key fix 5 L1 columns", 5, params.mNumColumns); + assertEquals("5 key fix 5 L1 rows", 1, params.mNumRows); + assertEquals("5 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("5 key fix 5 L1 right", 5, params.mRightKeys); + assertEquals("5 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key fix 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key fix 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] <2> [3] [4] [5] + @Test + public void testLayout5KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L2); + assertEquals("5 key fix 5 L2 columns", 5, params.mNumColumns); + assertEquals("5 key fix 5 L2 rows", 1, params.mNumRows); + assertEquals("5 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("5 key fix 5 L2 right", 4, params.mRightKeys); + assertEquals("5 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("5 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("5 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("5 key fix 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key fix 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("5 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] [4] <5>| + @Test + public void testLayout5KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R0); + assertEquals("5 key fix 5 R0 columns", 5, params.mNumColumns); + assertEquals("5 key fix 5 R0 rows", 1, params.mNumRows); + assertEquals("5 key fix 5 R0 left", 4, params.mLeftKeys); + assertEquals("5 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("5 key fix 5 R0 [1]", -4, params.getColumnPos(0)); + assertEquals("5 key fix 5 R0 [2]", -3, params.getColumnPos(1)); + assertEquals("5 key fix 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key fix 5 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("5 key fix 5 R0 <5>", 0, params.getColumnPos(4)); + assertEquals("5 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] [4] <5> ___| + @Test + public void testLayout5KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R1); + assertEquals("5 key fix 5 R1 columns", 5, params.mNumColumns); + assertEquals("5 key fix 5 R1 rows", 1, params.mNumRows); + assertEquals("5 key fix 5 R1 left", 4, params.mLeftKeys); + assertEquals("5 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("5 key fix 5 R1 [1]", -4, params.getColumnPos(0)); + assertEquals("5 key fix 5 R1 [2]", -3, params.getColumnPos(1)); + assertEquals("5 key fix 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key fix 5 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("5 key fix 5 R1 <5>", 0, params.getColumnPos(4)); + assertEquals("5 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] <4> [5] ___| + @Test + public void testLayout5KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R2); + assertEquals("5 key fix 5 R2 columns", 5, params.mNumColumns); + assertEquals("5 key fix 5 R2 rows", 1, params.mNumRows); + assertEquals("5 key fix 5 R2 left", 3, params.mLeftKeys); + assertEquals("5 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("5 key fix 5 R2 [1]", -3, params.getColumnPos(0)); + assertEquals("5 key fix 5 R2 [2]", -2, params.getColumnPos(1)); + assertEquals("5 key fix 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key fix 5 R2 <4>", 0, params.getColumnPos(3)); + assertEquals("5 key fix 5 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key fix 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] + // [1] [2] <3> [4] [5] + @Test + public void testLayout6KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_M0); + assertEquals("6 key fix 5 columns", 5, params.mNumColumns); + assertEquals("6 key fix 5 rows", 2, params.mNumRows); + assertEquals("6 key fix 5 left", 2, params.mLeftKeys); + assertEquals("6 key fix 5 right", 3, params.mRightKeys); + assertEquals("6 key fix 5 [1]", -2, params.getColumnPos(0)); + assertEquals("6 key fix 5 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key fix 5 <3>", 0, params.getColumnPos(2)); + assertEquals("6 key fix 5 [4]", 1, params.getColumnPos(3)); + assertEquals("6 key fix 5 [5]", 2, params.getColumnPos(4)); + assertEquals("6 key fix 5 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 5 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 5 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout6KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L0); + assertEquals("6 key fix 5 L0 columns", 5, params.mNumColumns); + assertEquals("6 key fix 5 L0 rows", 2, params.mNumRows); + assertEquals("6 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("6 key fix 5 L0 right", 5, params.mRightKeys); + assertEquals("6 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key fix 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key fix 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("6 key fix 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout6KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L1); + assertEquals("6 key fix 5 L1 columns", 5, params.mNumColumns); + assertEquals("6 key fix 5 L1 rows", 2, params.mNumRows); + assertEquals("6 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("6 key fix 5 L1 right", 5, params.mRightKeys); + assertEquals("6 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key fix 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("6 key fix 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("6 key fix 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] + // |___ [1] <2> [3] [4] [5] + @Test + public void testLayout6KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L2); + assertEquals("6 key fix 5 L2 columns", 5, params.mNumColumns); + assertEquals("6 key fix 5 L2 rows", 2, params.mNumRows); + assertEquals("6 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("6 key fix 5 L2 right", 4, params.mRightKeys); + assertEquals("6 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("6 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("6 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("6 key fix 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("6 key fix 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("6 key fix 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6]| + // [1] [2] [3] [4] <5>| + @Test + public void testLayout6KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R0); + assertEquals("6 key fix 5 R0 columns", 5, params.mNumColumns); + assertEquals("6 key fix 5 R0 rows", 2, params.mNumRows); + assertEquals("6 key fix 5 R0 left", 4, params.mLeftKeys); + assertEquals("6 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("6 key fix 5 R0 [1]", -4, params.getColumnPos(0)); + assertEquals("6 key fix 5 R0 [2]", -3, params.getColumnPos(1)); + assertEquals("6 key fix 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key fix 5 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("6 key fix 5 R0 <5>", 0, params.getColumnPos(4)); + assertEquals("6 key fix 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] ___| + // [1] [2] [3] [4] <5> ___| + @Test + public void testLayout6KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R1); + assertEquals("6 key fix 5 R1 columns", 5, params.mNumColumns); + assertEquals("6 key fix 5 R1 rows", 2, params.mNumRows); + assertEquals("6 key fix 5 R1 left", 4, params.mLeftKeys); + assertEquals("6 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("6 key fix 5 R1 [1]", -4, params.getColumnPos(0)); + assertEquals("6 key fix 5 R1 [2]", -3, params.getColumnPos(1)); + assertEquals("6 key fix 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key fix 5 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("6 key fix 5 R1 <5>", 0, params.getColumnPos(4)); + assertEquals("6 key fix 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] ___| + // [1] [2] [3] <4> [5] ___| + @Test + public void testLayout6KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R2); + assertEquals("6 key fix 5 R2 columns", 5, params.mNumColumns); + assertEquals("6 key fix 5 R2 rows", 2, params.mNumRows); + assertEquals("6 key fix 5 R2 left", 3, params.mLeftKeys); + assertEquals("6 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("6 key fix 5 R2 [1]", -3, params.getColumnPos(0)); + assertEquals("6 key fix 5 R2 [2]", -2, params.getColumnPos(1)); + assertEquals("6 key fix 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key fix 5 R2 <4>", 0, params.getColumnPos(3)); + assertEquals("6 key fix 5 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key fix 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("6 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key fix 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] [7] + // [1] [2] <3> [4] [5] + @Test + public void testLayout7KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_M0); + assertEquals("7 key fix 5 columns", 5, params.mNumColumns); + assertEquals("7 key fix 5 rows", 2, params.mNumRows); + assertEquals("7 key fix 5 left", 2, params.mLeftKeys); + assertEquals("7 key fix 5 right", 3, params.mRightKeys); + assertEquals("7 key fix 5 [1]", -2, params.getColumnPos(0)); + assertEquals("7 key fix 5 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key fix 5 <3>", 0, params.getColumnPos(2)); + assertEquals("7 key fix 5 [4]", 1, params.getColumnPos(3)); + assertEquals("7 key fix 5 [5]", 2, params.getColumnPos(4)); + assertEquals("7 key fix 5 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 5 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 5 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key fix 5 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout7KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L0); + assertEquals("7 key fix 5 L0 columns", 5, params.mNumColumns); + assertEquals("7 key fix 5 L0 rows", 2, params.mNumRows); + assertEquals("7 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("7 key fix 5 L0 right", 5, params.mRightKeys); + assertEquals("7 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key fix 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key fix 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key fix 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout7KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L1); + assertEquals("7 key fix 5 L1 columns", 5, params.mNumColumns); + assertEquals("7 key fix 5 L1 rows", 2, params.mNumRows); + assertEquals("7 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("7 key fix 5 L1 right", 5, params.mRightKeys); + assertEquals("7 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key fix 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key fix 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key fix 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] + // |___ [1] <2> [3] [4] [5] + @Test + public void testLayout7KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L2); + assertEquals("7 key fix 5 L2 columns", 5, params.mNumColumns); + assertEquals("7 key fix 5 L2 rows", 2, params.mNumRows); + assertEquals("7 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("7 key fix 5 L2 right", 4, params.mRightKeys); + assertEquals("7 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("7 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("7 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("7 key fix 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key fix 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("7 key fix 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 5 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [7]| + // [1] [2] [3] [4] <5>| + @Test + public void testLayout7KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R0); + assertEquals("7 key fix 5 R0 columns", 5, params.mNumColumns); + assertEquals("7 key fix 5 R0 rows", 2, params.mNumRows); + assertEquals("7 key fix 5 R0 left", 4, params.mLeftKeys); + assertEquals("7 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("7 key fix 5 R0 [1]", -4, params.getColumnPos(0)); + assertEquals("7 key fix 5 R0 [2]", -3, params.getColumnPos(1)); + assertEquals("7 key fix 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key fix 5 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("7 key fix 5 R0 <5>", 0, params.getColumnPos(4)); + assertEquals("7 key fix 5 R0 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key fix 5 R0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] ___| + // [1] [2] [3] [4] <5> ___| + @Test + public void testLayout7KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R1); + assertEquals("7 key fix 5 R1 columns", 5, params.mNumColumns); + assertEquals("7 key fix 5 R1 rows", 2, params.mNumRows); + assertEquals("7 key fix 5 R1 left", 4, params.mLeftKeys); + assertEquals("7 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("7 key fix 5 R1 [1]", -4, params.getColumnPos(0)); + assertEquals("7 key fix 5 R1 [2]", -3, params.getColumnPos(1)); + assertEquals("7 key fix 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key fix 5 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("7 key fix 5 R1 <5>", 0, params.getColumnPos(4)); + assertEquals("7 key fix 5 R1 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key fix 5 R1 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] ___| + // [1] [2] [3] <4> [5] ___| + @Test + public void testLayout7KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R2); + assertEquals("7 key fix 5 R2 columns",5, params.mNumColumns); + assertEquals("7 key fix 5 R2 rows", 2, params.mNumRows); + assertEquals("7 key fix 5 R2 left", 3, params.mLeftKeys); + assertEquals("7 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("7 key fix 5 R2 [1]", -3, params.getColumnPos(0)); + assertEquals("7 key fix 5 R2 [2]", -2, params.getColumnPos(1)); + assertEquals("7 key fix 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key fix 5 R2 <4>", 0, params.getColumnPos(3)); + assertEquals("7 key fix 5 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key fix 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("7 key fix 5 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 5 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key fix 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] + // [1] [2] <3> [4] [5] + @Test + public void testLayout8KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_M0); + assertEquals("8 key fix 5 M0 columns", 5, params.mNumColumns); + assertEquals("8 key fix 5 M0 rows", 2, params.mNumRows); + assertEquals("8 key fix 5 M0 left", 2, params.mLeftKeys); + assertEquals("8 key fix 5 M0 right", 3, params.mRightKeys); + assertEquals("8 key fix 5 M0 [1]", -2, params.getColumnPos(0)); + assertEquals("8 key fix 5 M0 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key fix 5 M0 <3>", 0, params.getColumnPos(2)); + assertEquals("8 key fix 5 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("8 key fix 5 M0 [5]", 2, params.getColumnPos(4)); + assertEquals("8 key fix 5 M0 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key fix 5 M0 [7]", 0, params.getColumnPos(6)); + assertEquals("8 key fix 5 M0 [8]", 1, params.getColumnPos(7)); + assertEquals("8 key fix 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout8KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L0); + assertEquals("8 key fix 5 L0 columns", 5, params.mNumColumns); + assertEquals("8 key fix 5 L0 rows", 2, params.mNumRows); + assertEquals("8 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("8 key fix 5 L0 right", 5, params.mRightKeys); + assertEquals("8 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key fix 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key fix 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("8 key fix 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key fix 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key fix 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout8KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L1); + assertEquals("8 key fix 5 L1 columns", 5, params.mNumColumns); + assertEquals("8 key fix 5 L1 rows", 2, params.mNumRows); + assertEquals("8 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("8 key fix 5 L1 right", 5, params.mRightKeys); + assertEquals("8 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key fix 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key fix 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("8 key fix 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("8 key fix 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("8 key fix 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] + // |___ [1] <2> [3] [4] [5] + @Test + public void testLayout8KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L2); + assertEquals("8 key fix 5 L2 columns", 5, params.mNumColumns); + assertEquals("8 key fix 5 L2 rows", 2, params.mNumRows); + assertEquals("8 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("8 key fix 5 L2 right", 4, params.mRightKeys); + assertEquals("8 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("8 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("8 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("8 key fix 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key fix 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("8 key fix 5 L2 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key fix 5 L2 [7]", 0, params.getColumnPos(6)); + assertEquals("8 key fix 5 L2 [8]", 1, params.getColumnPos(7)); + assertEquals("8 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8]| + // [1] [2] [3] [4] <5>| + @Test + public void testLayout8KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R0); + assertEquals("8 key fix 5 R0 columns", 5, params.mNumColumns); + assertEquals("8 key fix 5 R0 rows", 2, params.mNumRows); + assertEquals("8 key fix 5 R0 left", 4, params.mLeftKeys); + assertEquals("8 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("8 key fix 5 R0 [1]", -4, params.getColumnPos(0)); + assertEquals("8 key fix 5 R0 [2]", -3, params.getColumnPos(1)); + assertEquals("8 key fix 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key fix 5 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("8 key fix 5 R0 <5>", 0, params.getColumnPos(4)); + assertEquals("8 key fix 5 R0 [6]", -2, params.getColumnPos(5)); + assertEquals("8 key fix 5 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key fix 5 R0 [8]", 0, params.getColumnPos(7)); + assertEquals("8 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] ___| + // [1] [2] [3] [4] <5> ___| + @Test + public void testLayout8KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R1); + assertEquals("8 key fix 5 R1 columns", 5, params.mNumColumns); + assertEquals("8 key fix 5 R1 rows", 2, params.mNumRows); + assertEquals("8 key fix 5 R1 left", 4, params.mLeftKeys); + assertEquals("8 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("8 key fix 5 R1 [1]", -4, params.getColumnPos(0)); + assertEquals("8 key fix 5 R1 [2]", -3, params.getColumnPos(1)); + assertEquals("8 key fix 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key fix 5 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("8 key fix 5 R1 <5>", 0, params.getColumnPos(4)); + assertEquals("8 key fix 5 R1 [6]", -2, params.getColumnPos(5)); + assertEquals("8 key fix 5 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key fix 5 R1 [8]", 0, params.getColumnPos(7)); + assertEquals("8 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] ___| + // [1] [2] [3] <4> [5] ___| + @Test + public void testLayout8KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R2); + assertEquals("8 key fix 5 R2 columns", 5, params.mNumColumns); + assertEquals("8 key fix 5 R2 rows", 2, params.mNumRows); + assertEquals("8 key fix 5 R2 left", 3, params.mLeftKeys); + assertEquals("8 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("8 key fix 5 R2 [1]", -3, params.getColumnPos(0)); + assertEquals("8 key fix 5 R2 [2]", -2, params.getColumnPos(1)); + assertEquals("8 key fix 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key fix 5 R2 <4>", 0, params.getColumnPos(3)); + assertEquals("8 key fix 5 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("8 key fix 5 R2 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key fix 5 R2 [7]", 0, params.getColumnPos(6)); + assertEquals("8 key fix 5 R2 [8]", 1, params.getColumnPos(7)); + assertEquals("8 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key fix 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9] + // [1] [2] <3> [4] [5] + @Test + public void testLayout9KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_M0); + assertEquals("9 key fix 5 M0 columns", 5, params.mNumColumns); + assertEquals("9 key fix 5 M0 rows", 2, params.mNumRows); + assertEquals("9 key fix 5 M0 left", 2, params.mLeftKeys); + assertEquals("9 key fix 5 M0 right", 3, params.mRightKeys); + assertEquals("9 key fix 5 M0 [1]", -2, params.getColumnPos(0)); + assertEquals("9 key fix 5 M0 [2]", -1, params.getColumnPos(1)); + assertEquals("9 key fix 5 M0 <3>", 0, params.getColumnPos(2)); + assertEquals("9 key fix 5 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("9 key fix 5 M0 [5]", 2, params.getColumnPos(4)); + assertEquals("9 key fix 5 M0 [6]", -1, params.getColumnPos(5)); + assertEquals("9 key fix 5 M0 [7]", 0, params.getColumnPos(6)); + assertEquals("9 key fix 5 M0 [8]", 1, params.getColumnPos(7)); + assertEquals("9 key fix 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("9 key fix 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key fix 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout9KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L0); + assertEquals("9 key fix 5 L0 columns", 5, params.mNumColumns); + assertEquals("9 key fix 5 L0 rows", 2, params.mNumRows); + assertEquals("9 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("9 key fix 5 L0 right", 5, params.mRightKeys); + assertEquals("9 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key fix 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key fix 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key fix 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key fix 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key fix 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key fix 5 L0 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout9KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L1); + assertEquals("9 key fix 5 L1 columns", 5, params.mNumColumns); + assertEquals("9 key fix 5 L1 rows", 2, params.mNumRows); + assertEquals("9 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("9 key fix 5 L1 right", 5, params.mRightKeys); + assertEquals("9 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key fix 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key fix 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key fix 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key fix 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key fix 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key fix 5 L1 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key fix 5 L1 adjust",0, params.mTopRowAdjustment); + assertEquals("9 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] + // |___ [1] <2> [3] [4] [5] + @Test + public void testLayout9KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L2); + assertEquals("9 key fix 5 L2 columns", 5, params.mNumColumns); + assertEquals("9 key fix 5 L2 rows", 2, params.mNumRows); + assertEquals("9 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("9 key fix 5 L2 right", 4, params.mRightKeys); + assertEquals("9 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("9 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("9 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("9 key fix 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("9 key fix 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("9 key fix 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key fix 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key fix 5 L2 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key fix 5 L2 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key fix 5 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9]| + // [1] [2] [3] [4] <5>| + @Test + public void testLayout9KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R0); + assertEquals("9 key fix 5 R0 columns", 5, params.mNumColumns); + assertEquals("9 key fix 5 R0 rows", 2, params.mNumRows); + assertEquals("9 key fix 5 R0 left", 4, params.mLeftKeys); + assertEquals("9 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("9 key fix 5 R0 [1]", -4, params.getColumnPos(0)); + assertEquals("9 key fix 5 R0 [2]", -3, params.getColumnPos(1)); + assertEquals("9 key fix 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key fix 5 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("9 key fix 5 R0 <5>", 0, params.getColumnPos(4)); + assertEquals("9 key fix 5 R0 [6]", -3, params.getColumnPos(5)); + assertEquals("9 key fix 5 R0 [7]", -2, params.getColumnPos(6)); + assertEquals("9 key fix 5 R0 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key fix 5 R0 [9]", 0, params.getColumnPos(8)); + assertEquals("9 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key fix 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9] ___| + // [1] [2] [3] [4] <5> ___| + @Test + public void testLayout9KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R1); + assertEquals("9 key fix 5 R1 columns", 5, params.mNumColumns); + assertEquals("9 key fix 5 R1 rows", 2, params.mNumRows); + assertEquals("9 key fix 5 R1 left", 4, params.mLeftKeys); + assertEquals("9 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("9 key fix 5 R1 [1]", -4, params.getColumnPos(0)); + assertEquals("9 key fix 5 R1 [2]", -3, params.getColumnPos(1)); + assertEquals("9 key fix 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key fix 5 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("9 key fix 5 R1 <5>", 0, params.getColumnPos(4)); + assertEquals("9 key fix 5 R1 [6]", -3, params.getColumnPos(5)); + assertEquals("9 key fix 5 R1 [7]", -2, params.getColumnPos(6)); + assertEquals("9 key fix 5 R1 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key fix 5 R1 [9]", 0, params.getColumnPos(8)); + assertEquals("9 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key fix 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9] ___| + // [1] [2] [3] <4> [5] ___| + @Test + public void testLayout9KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R2); + assertEquals("9 key fix 5 R2 columns", 5, params.mNumColumns); + assertEquals("9 key fix 5 R2 rows", 2, params.mNumRows); + assertEquals("9 key fix 5 R2 left", 3, params.mLeftKeys); + assertEquals("9 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("9 key fix 5 R2 [1]", -3, params.getColumnPos(0)); + assertEquals("9 key fix 5 R2 [2]", -2, params.getColumnPos(1)); + assertEquals("9 key fix 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key fix 5 R2 <4>", 0, params.getColumnPos(3)); + assertEquals("9 key fix 5 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("9 key fix 5 R2 [6]", -2, params.getColumnPos(5)); + assertEquals("9 key fix 5 R2 [7]", -1, params.getColumnPos(6)); + assertEquals("9 key fix 5 R2 [8]", 0, params.getColumnPos(7)); + assertEquals("9 key fix 5 R2 [9]", 1, params.getColumnPos(8)); + assertEquals("9 key fix 5 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key fix 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9] [A] + // [1] [2] <3> [4] [5] + @Test + public void testLayout10KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_M0); + assertEquals("10 key fix 5 M0 columns", 5, params.mNumColumns); + assertEquals("10 key fix 5 M0 rows", 2, params.mNumRows); + assertEquals("10 key fix 5 M0 left", 2, params.mLeftKeys); + assertEquals("10 key fix 5 M0 right", 3, params.mRightKeys); + assertEquals("10 key fix 5 M0 [1]", -2, params.getColumnPos(0)); + assertEquals("10 key fix 5 M0 [2]", -1, params.getColumnPos(1)); + assertEquals("10 key fix 5 M0 <3>", 0, params.getColumnPos(2)); + assertEquals("10 key fix 5 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("10 key fix 5 M0 [5]", 2, params.getColumnPos(4)); + assertEquals("10 key fix 5 M0 [6]", -2, params.getColumnPos(5)); + assertEquals("10 key fix 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("10 key fix 5 M0 [8]", 0, params.getColumnPos(7)); + assertEquals("10 key fix 5 M0 [9]", 1, params.getColumnPos(8)); + assertEquals("10 key fix 5 M0 [A]", 2, params.getColumnPos(9)); + assertEquals("10 key fix 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key fix 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] [A] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout10KeyFix5L0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L0); + assertEquals("10 key fix 5 L0 columns", 5, params.mNumColumns); + assertEquals("10 key fix 5 L0 rows", 2, params.mNumRows); + assertEquals("10 key fix 5 L0 left", 0, params.mLeftKeys); + assertEquals("10 key fix 5 L0 right", 5, params.mRightKeys); + assertEquals("10 key fix 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key fix 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key fix 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key fix 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key fix 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key fix 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key fix 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key fix 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key fix 5 L0 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key fix 5 L0 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key fix 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key fix 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] [A] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout10KeyFix5L1() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L1); + assertEquals("10 key fix 5 L1 columns", 5, params.mNumColumns); + assertEquals("10 key fix 5 L1 rows", 2, params.mNumRows); + assertEquals("10 key fix 5 L1 left", 0, params.mLeftKeys); + assertEquals("10 key fix 5 L1 right", 5, params.mRightKeys); + assertEquals("10 key fix 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key fix 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key fix 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key fix 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key fix 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key fix 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key fix 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key fix 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key fix 5 L1 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key fix 5 L1 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key fix 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key fix 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] [A] + // |___ [1] <2> [3] [4] [5] + @Test + public void testLayout10KeyFix5L2() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L2); + assertEquals("10 key fix 5 L2 columns", 5, params.mNumColumns); + assertEquals("10 key fix 5 L2 rows", 2, params.mNumRows); + assertEquals("10 key fix 5 L2 left", 1, params.mLeftKeys); + assertEquals("10 key fix 5 L2 right", 4, params.mRightKeys); + assertEquals("10 key fix 5 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("10 key fix 5 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("10 key fix 5 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("10 key fix 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("10 key fix 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("10 key fix 5 L2 [6]", -1, params.getColumnPos(5)); + assertEquals("10 key fix 5 L2 [7]", 0, params.getColumnPos(6)); + assertEquals("10 key fix 5 L2 [8]", 1, params.getColumnPos(7)); + assertEquals("10 key fix 5 L2 [9]", 2, params.getColumnPos(8)); + assertEquals("10 key fix 5 L2 [A]", 3, params.getColumnPos(9)); + assertEquals("10 key fix 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key fix 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9] [A]| + // [1] [2] [3] [4] <5>| + @Test + public void testLayout10KeyFix5R0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R0); + assertEquals("10 key fix 5 R0 columns", 5, params.mNumColumns); + assertEquals("10 key fix 5 R0 rows", 2, params.mNumRows); + assertEquals("10 key fix 5 R0 left", 4, params.mLeftKeys); + assertEquals("10 key fix 5 R0 right", 1, params.mRightKeys); + assertEquals("10 key fix 5 R0 [1]", -4, params.getColumnPos(0)); + assertEquals("10 key fix 5 R0 [2]", -3, params.getColumnPos(1)); + assertEquals("10 key fix 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key fix 5 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("10 key fix 5 R0 <5>", 0, params.getColumnPos(4)); + assertEquals("10 key fix 5 R0 [6]", -4, params.getColumnPos(5)); + assertEquals("10 key fix 5 R0 [7]", -3, params.getColumnPos(6)); + assertEquals("10 key fix 5 R0 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key fix 5 R0 [9]", -1, params.getColumnPos(8)); + assertEquals("10 key fix 5 R0 [A]", 0, params.getColumnPos(9)); + assertEquals("10 key fix 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key fix 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9] [A] ___| + // [1] [2] [3] [4] <5> ___| + @Test + public void testLayout10KeyFix5R1() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R1); + assertEquals("10 key fix 5 R1 columns", 5, params.mNumColumns); + assertEquals("10 key fix 5 R1 rows", 2, params.mNumRows); + assertEquals("10 key fix 5 R1 left", 4, params.mLeftKeys); + assertEquals("10 key fix 5 R1 right", 1, params.mRightKeys); + assertEquals("10 key fix 5 R1 [1]", -4, params.getColumnPos(0)); + assertEquals("10 key fix 5 R1 [2]", -3, params.getColumnPos(1)); + assertEquals("10 key fix 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key fix 5 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("10 key fix 5 R1 <5>", 0, params.getColumnPos(4)); + assertEquals("10 key fix 5 R1 [6]", -4, params.getColumnPos(5)); + assertEquals("10 key fix 5 R1 [7]", -3, params.getColumnPos(6)); + assertEquals("10 key fix 5 R1 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key fix 5 R1 [9]", -1, params.getColumnPos(8)); + assertEquals("10 key fix 5 R1 [A]", 0, params.getColumnPos(9)); + assertEquals("10 key fix 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key fix 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [6] [7] [8] [9] [A] ___| + // [1] [2] [3] <4> [5] ___| + @Test + public void testLayout10KeyFix5R2() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R2); + assertEquals("10 key fix 5 R2 columns", 5, params.mNumColumns); + assertEquals("10 key fix 5 R2 rows", 2, params.mNumRows); + assertEquals("10 key fix 5 R2 left", 3, params.mLeftKeys); + assertEquals("10 key fix 5 R2 right", 2, params.mRightKeys); + assertEquals("10 key fix 5 R2 [1]", -3, params.getColumnPos(0)); + assertEquals("10 key fix 5 R2 [2]", -2, params.getColumnPos(1)); + assertEquals("10 key fix 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key fix 5 R2 <4>", 0, params.getColumnPos(3)); + assertEquals("10 key fix 5 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("10 key fix 5 R2 [6]", -3, params.getColumnPos(5)); + assertEquals("10 key fix 5 R2 [7]", -2, params.getColumnPos(6)); + assertEquals("10 key fix 5 R2 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key fix 5 R2 [9]", 0, params.getColumnPos(8)); + assertEquals("10 key fix 5 R2 [A]", 1, params.getColumnPos(9)); + assertEquals("10 key fix 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key fix 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [B] + // [6] [7] [8] [9] [A] + // [1] [2] <3> [4] [5] + @Test + public void testLayout11KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(11, 5, XPOS_M0); + assertEquals("11 key fix 5 M0 columns", 5, params.mNumColumns); + assertEquals("11 key fix 5 M0 rows", 3, params.mNumRows); + assertEquals("11 key fix 5 M0 left", 2, params.mLeftKeys); + assertEquals("11 key fix 5 M0 right", 3, params.mRightKeys); + assertEquals("11 key fix 5 M0 [1]", -2, params.getColumnPos(0)); + assertEquals("11 key fix 5 M0 [2]", -1, params.getColumnPos(1)); + assertEquals("11 key fix 5 M0 <3>", 0, params.getColumnPos(2)); + assertEquals("11 key fix 5 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("11 key fix 5 M0 [5]", 2, params.getColumnPos(4)); + assertEquals("11 key fix 5 M0 [6]", -2, params.getColumnPos(5)); + assertEquals("11 key fix 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("11 key fix 5 M0 [8]", 0, params.getColumnPos(7)); + assertEquals("11 key fix 5 M0 [9]", 1, params.getColumnPos(8)); + assertEquals("11 key fix 5 M0 [A]", 2, params.getColumnPos(9)); + assertEquals("11 key fix 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("11 key fix 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("11 key fix 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [B] [C] + // [6] [7] [8] [9] [A] + // [1] [2] <3> [4] [5] + @Test + public void testLayout12KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(12, 5, XPOS_M0); + assertEquals("12 key fix 5 M0 columns", 5, params.mNumColumns); + assertEquals("12 key fix 5 M0 rows", 3, params.mNumRows); + assertEquals("12 key fix 5 M0 left", 2, params.mLeftKeys); + assertEquals("12 key fix 5 M0 right", 3, params.mRightKeys); + assertEquals("12 key fix 5 M0 [1]", -2, params.getColumnPos(0)); + assertEquals("12 key fix 5 M0 [2]", -1, params.getColumnPos(1)); + assertEquals("12 key fix 5 M0 <3>", 0, params.getColumnPos(2)); + assertEquals("12 key fix 5 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("12 key fix 5 M0 [5]", 2, params.getColumnPos(4)); + assertEquals("12 key fix 5 M0 [6]", -2, params.getColumnPos(5)); + assertEquals("12 key fix 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("12 key fix 5 M0 [8]", 0, params.getColumnPos(7)); + assertEquals("12 key fix 5 M0 [9]", 1, params.getColumnPos(8)); + assertEquals("12 key fix 5 M0 [A]", 2, params.getColumnPos(9)); + assertEquals("12 key fix 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("12 key fix 5 M0 [C]", 1, params.getColumnPos(11)); + assertEquals("12 key fix 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("12 key fix 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [B] [C] [D] + // [6] [7] [8] [9] [A] + // [1] [2] <3> [4] [5] + @Test + public void testLayout13KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(13, 5, XPOS_M0); + assertEquals("13 key fix 5 M0 columns", 5, params.mNumColumns); + assertEquals("13 key fix 5 M0 rows", 3, params.mNumRows); + assertEquals("13 key fix 5 M0 left", 2, params.mLeftKeys); + assertEquals("13 key fix 5 M0 right", 3, params.mRightKeys); + assertEquals("13 key fix 5 M0 [1]", -2, params.getColumnPos(0)); + assertEquals("13 key fix 5 M0 [2]", -1, params.getColumnPos(1)); + assertEquals("13 key fix 5 M0 <3>", 0, params.getColumnPos(2)); + assertEquals("13 key fix 5 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("13 key fix 5 M0 [5]", 2, params.getColumnPos(4)); + assertEquals("13 key fix 5 M0 [6]", -2, params.getColumnPos(5)); + assertEquals("13 key fix 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("13 key fix 5 M0 [8]", 0, params.getColumnPos(7)); + assertEquals("13 key fix 5 M0 [9]", 1, params.getColumnPos(8)); + assertEquals("13 key fix 5 M0 [A]", 2, params.getColumnPos(9)); + assertEquals("13 key fix 5 M0 [B]", -1, params.getColumnPos(10)); + assertEquals("13 key fix 5 M0 [C]", 0, params.getColumnPos(11)); + assertEquals("13 key fix 5 M0 [D]", 1, params.getColumnPos(12)); + assertEquals("13 key fix 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("13 key fix 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [B] [C] [D] [E] + // [6] [7] [8] [9] [A] + // [1] [2] <3> [4] [5] + @Test + public void testLayout14KeyFix5M0() { + MoreKeysKeyboardParams params = createParams(14, 5, XPOS_M0); + assertEquals("14 key fix 5 M0 columns", 5, params.mNumColumns); + assertEquals("14 key fix 5 M0 rows", 3, params.mNumRows); + assertEquals("14 key fix 5 M0 left", 2, params.mLeftKeys); + assertEquals("14 key fix 5 M0 right", 3, params.mRightKeys); + assertEquals("14 key fix 5 M0 [1]", -2, params.getColumnPos(0)); + assertEquals("14 key fix 5 M0 [2]", -1, params.getColumnPos(1)); + assertEquals("14 key fix 5 M0 <3>", 0, params.getColumnPos(2)); + assertEquals("14 key fix 5 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("14 key fix 5 M0 [5]", 2, params.getColumnPos(4)); + assertEquals("14 key fix 5 M0 [6]", -2, params.getColumnPos(5)); + assertEquals("14 key fix 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("14 key fix 5 M0 [8]", 0, params.getColumnPos(7)); + assertEquals("14 key fix 5 M0 [9]", 1, params.getColumnPos(8)); + assertEquals("14 key fix 5 M0 [A]", 2, params.getColumnPos(9)); + assertEquals("14 key fix 5 M0 [B]", -1, params.getColumnPos(10)); + assertEquals("14 key fix 5 M0 [C]", 0, params.getColumnPos(11)); + assertEquals("14 key fix 5 M0 [D]", 1, params.getColumnPos(12)); + assertEquals("14 key fix 5 M0 [E]", 2, params.getColumnPos(13)); + assertEquals("14 key fix 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("14 key fix 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] [5] [6] [7] + @Test + public void testLayout7KeyFix7L0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L0); + assertEquals("7 key fix 7 L0 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 L0 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 L0 left", 0, params.mLeftKeys); + assertEquals("7 key fix 7 L0 right", 7, params.mRightKeys); + assertEquals("7 key fix 7 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key fix 7 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key fix 7 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key fix 7 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key fix 7 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key fix 7 L0 [6]", 5, params.getColumnPos(5)); + assertEquals("7 key fix 7 L0 [7]", 6, params.getColumnPos(6)); + assertEquals("7 key fix 7 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] [5] [6] [7] + @Test + public void testLayout7KeyFix7L1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L1); + assertEquals("7 key fix 7 L1 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 L1 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 L1 left", 0, params.mLeftKeys); + assertEquals("7 key fix 7 L1 right", 7, params.mRightKeys); + assertEquals("7 key fix 7 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key fix 7 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key fix 7 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key fix 7 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key fix 7 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key fix 7 L1 [6]", 5, params.getColumnPos(5)); + assertEquals("7 key fix 7 L1 [7]", 6, params.getColumnPos(6)); + assertEquals("7 key fix 7 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [1] <2> [3] [4] [5] [6] [7] + @Test + public void testLayout7KeyFix7L2() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L2); + assertEquals("7 key fix 7 L2 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 L2 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 L2 left", 1, params.mLeftKeys); + assertEquals("7 key fix 7 L2 right", 6, params.mRightKeys); + assertEquals("7 key fix 7 L2 [1]", -1, params.getColumnPos(0)); + assertEquals("7 key fix 7 L2 <2>", 0, params.getColumnPos(1)); + assertEquals("7 key fix 7 L2 [3]", 1, params.getColumnPos(2)); + assertEquals("7 key fix 7 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key fix 7 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("7 key fix 7 L2 [6]", 4, params.getColumnPos(5)); + assertEquals("7 key fix 7 L2 [7]", 5, params.getColumnPos(6)); + assertEquals("7 key fix 7 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |___ [1] [2] <3> [4] [5] [6] [7] + @Test + public void testLayout7KeyFix7L3() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L3); + assertEquals("7 key fix 7 L3 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 L3 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 L3 left", 2, params.mLeftKeys); + assertEquals("7 key fix 7 L3 right", 5, params.mRightKeys); + assertEquals("7 key fix 7 L3 [1]", -2, params.getColumnPos(0)); + assertEquals("7 key fix 7 L3 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key fix 7 L3 <3>", 0, params.getColumnPos(2)); + assertEquals("7 key fix 7 L3 [4]", 1, params.getColumnPos(3)); + assertEquals("7 key fix 7 L3 [5]", 2, params.getColumnPos(4)); + assertEquals("7 key fix 7 L3 [6]", 3, params.getColumnPos(5)); + assertEquals("7 key fix 7 L3 [7]", 4, params.getColumnPos(6)); + assertEquals("7 key fix 7 L3 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 L3 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |___ [1] [2] [3] <4> [5] [6] [7] ___ ___| + @Test + public void testLayout7KeyFix7M0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_M0); + assertEquals("7 key fix 7 M0 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 M0 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 M0 left", 3, params.mLeftKeys); + assertEquals("7 key fix 7 M0 right", 4, params.mRightKeys); + assertEquals("7 key fix 7 M0 [1]", -3, params.getColumnPos(0)); + assertEquals("7 key fix 7 M0 [2]", -2, params.getColumnPos(1)); + assertEquals("7 key fix 7 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key fix 7 M0 <4>", 0, params.getColumnPos(3)); + assertEquals("7 key fix 7 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key fix 7 M0 [6]", 2, params.getColumnPos(5)); + assertEquals("7 key fix 7 M0 [7]", 3, params.getColumnPos(6)); + assertEquals("7 key fix 7 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 M0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // |___ ___ [1] [2] [3] <4> [5] [6] [7] ___| + @Test + public void testLayout7KeyFix7M1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_M1); + assertEquals("7 key fix 7 M1 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 M1 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 M1 left", 3, params.mLeftKeys); + assertEquals("7 key fix 7 M1 right", 4, params.mRightKeys); + assertEquals("7 key fix 7 M1 [1]", -3, params.getColumnPos(0)); + assertEquals("7 key fix 7 M1 [2]", -2, params.getColumnPos(1)); + assertEquals("7 key fix 7 M1 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key fix 7 M1 <4>", 0, params.getColumnPos(3)); + assertEquals("7 key fix 7 M1 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key fix 7 M1 [6]", 2, params.getColumnPos(5)); + assertEquals("7 key fix 7 M1 [7]", 3, params.getColumnPos(6)); + assertEquals("7 key fix 7 M1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 M1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] [4] <5> [6] [7] ___| + @Test + public void testLayout7KeyFix7R3() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R3); + assertEquals("7 key fix 7 R3 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 R3 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 R3 left", 4, params.mLeftKeys); + assertEquals("7 key fix 7 R3 right", 3, params.mRightKeys); + assertEquals("7 key fix 7 R3 [1]", -4, params.getColumnPos(0)); + assertEquals("7 key fix 7 R3 [2]", -3, params.getColumnPos(1)); + assertEquals("7 key fix 7 R3 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key fix 7 R3 [4]", -1, params.getColumnPos(3)); + assertEquals("7 key fix 7 R3 <5>", 0, params.getColumnPos(4)); + assertEquals("7 key fix 7 R3 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key fix 7 R3 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key fix 7 R3 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 R3 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] [4] [5] <6> [7] ___| + @Test + public void testLayout7KeyFix7R2() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R2); + assertEquals("7 key fix 7 R2 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 R2 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 R2 left", 5, params.mLeftKeys); + assertEquals("7 key fix 7 R2 right", 2, params.mRightKeys); + assertEquals("7 key fix 7 R2 [1]", -5, params.getColumnPos(0)); + assertEquals("7 key fix 7 R2 [2]", -4, params.getColumnPos(1)); + assertEquals("7 key fix 7 R2 [3]", -3, params.getColumnPos(2)); + assertEquals("7 key fix 7 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("7 key fix 7 R2 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key fix 7 R2 <6>", 0, params.getColumnPos(5)); + assertEquals("7 key fix 7 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("7 key fix 7 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 R2 default", WIDTH * 5, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] [4] [5] [6] <7> ___| + @Test + public void testLayout7KeyFix7R1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R1); + assertEquals("7 key fix 7 R1 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 R1 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 R1 left", 6, params.mLeftKeys); + assertEquals("7 key fix 7 R1 right", 1, params.mRightKeys); + assertEquals("7 key fix 7 R1 [1]", -6, params.getColumnPos(0)); + assertEquals("7 key fix 7 R1 [2]", -5, params.getColumnPos(1)); + assertEquals("7 key fix 7 R1 [3]", -4, params.getColumnPos(2)); + assertEquals("7 key fix 7 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key fix 7 R1 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key fix 7 R1 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key fix 7 R1 <7>", 0, params.getColumnPos(6)); + assertEquals("7 key fix 7 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 R1 default", WIDTH * 6, params.getDefaultKeyCoordX()); + } + + // [1] [2] [3] [4] [5] [6] <7>| + @Test + public void testLayout7KeyFix7R0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R0); + assertEquals("7 key fix 7 R0 columns", 7, params.mNumColumns); + assertEquals("7 key fix 7 R0 rows", 1, params.mNumRows); + assertEquals("7 key fix 7 R0 left", 6, params.mLeftKeys); + assertEquals("7 key fix 7 R0 right", 1, params.mRightKeys); + assertEquals("7 key fix 7 R0 [1]", -6, params.getColumnPos(0)); + assertEquals("7 key fix 7 R0 [2]", -5, params.getColumnPos(1)); + assertEquals("7 key fix 7 R0 [3]", -4, params.getColumnPos(2)); + assertEquals("7 key fix 7 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key fix 7 R0 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key fix 7 R0 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key fix 7 R0 <7>", 0, params.getColumnPos(6)); + assertEquals("7 key fix 7 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key fix 7 R0 default", WIDTH * 6, params.getDefaultKeyCoordX()); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderMaxOrderTests.java b/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderMaxOrderTests.java new file mode 100644 index 000000000..85a49f80c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/MoreKeysKeyboardBuilderMaxOrderTests.java @@ -0,0 +1,2505 @@ +/* + * Copyright (C) 2011 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 org.kelar.inputmethod.keyboard; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.keyboard.MoreKeysKeyboard.MoreKeysKeyboardParams; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@MediumTest +@RunWith(AndroidJUnit4.class) +public class MoreKeysKeyboardBuilderMaxOrderTests { + private static final int WIDTH = 10; + private static final int HEIGHT = 10; + + private static final int KEYBOARD_WIDTH = WIDTH * 10; + private static final int XPOS_L0 = WIDTH * 0 + WIDTH / 2; + private static final int XPOS_L1 = WIDTH * 1 + WIDTH / 2; + private static final int XPOS_L2 = WIDTH * 2 + WIDTH / 2; + private static final int XPOS_L3 = WIDTH * 3 + WIDTH / 2; + private static final int XPOS_M0 = WIDTH * 4 + WIDTH / 2; + private static final int XPOS_M1 = WIDTH * 5 + WIDTH / 2; + private static final int XPOS_R3 = WIDTH * 6 + WIDTH / 2; + private static final int XPOS_R2 = WIDTH * 7 + WIDTH / 2; + private static final int XPOS_R1 = WIDTH * 8 + WIDTH / 2; + private static final int XPOS_R0 = WIDTH * 9 + WIDTH / 2; + + private static MoreKeysKeyboardParams createParams(final int numKeys, final int maxColumns, + final int coordXInParent) { + final MoreKeysKeyboardParams params = new MoreKeysKeyboardParams(); + params.setParameters(numKeys, maxColumns, WIDTH, HEIGHT, coordXInParent, KEYBOARD_WIDTH, + false /* isMoreKeysFixedColumn */, false /* isMoreKeysFixedOrder */, + 0 /* dividerWidth */); + return params; + } + + @Test + public void testLayoutError() { + MoreKeysKeyboardParams params = null; + try { + final int maxColumns = KEYBOARD_WIDTH / WIDTH; + params = createParams(maxColumns + 1, maxColumns + 1, HEIGHT); + fail("Should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Too small keyboard to hold more keys keyboard. + } + assertNull("Too small keyboard to hold more keys keyboard", params); + } + + // More keys keyboard layout test. + // "[n]" represents n-th key position in more keys keyboard. + // "<1>" is the default key. + + // <1> + @Test + public void testLayout1KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_M0); + assertEquals("1 key max 5 M0 columns", 1, params.mNumColumns); + assertEquals("1 key max 5 M0 rows", 1, params.mNumRows); + assertEquals("1 key max 5 M0 left", 0, params.mLeftKeys); + assertEquals("1 key max 5 M0 right", 1, params.mRightKeys); + assertEquals("1 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key max 5 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |<1> + @Test + public void testLayout1KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L0); + assertEquals("1 key max 5 L0 columns", 1, params.mNumColumns); + assertEquals("1 key max 5 L0 rows", 1, params.mNumRows); + assertEquals("1 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("1 key max 5 L0 right", 1, params.mRightKeys); + assertEquals("1 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> + @Test + public void testLayout1KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L1); + assertEquals("1 key max 5 L1 columns", 1, params.mNumColumns); + assertEquals("1 key max 5 L1 rows", 1, params.mNumRows); + assertEquals("1 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("1 key max 5 L1 right", 1, params.mRightKeys); + assertEquals("1 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ <1> + @Test + public void testLayout1KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_L2); + assertEquals("1 key max 5 L2 columns", 1, params.mNumColumns); + assertEquals("1 key max 5 L2 rows", 1, params.mNumRows); + assertEquals("1 key max 5 L2 left", 0, params.mLeftKeys); + assertEquals("1 key max 5 L2 right", 1, params.mRightKeys); + assertEquals("1 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key max 5 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1>| + @Test + public void testLayout1KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R0); + assertEquals("1 key max 5 R0 columns", 1, params.mNumColumns); + assertEquals("1 key max 5 R0 rows", 1, params.mNumRows); + assertEquals("1 key max 5 R0 left", 0, params.mLeftKeys); + assertEquals("1 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("1 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key max 5 R0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> ___| + @Test + public void testLayout1KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R1); + assertEquals("1 key max 5 R1 columns", 1, params.mNumColumns); + assertEquals("1 key max 5 R1 rows", 1, params.mNumRows); + assertEquals("1 key max 5 R1 left", 0, params.mLeftKeys); + assertEquals("1 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("1 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key max 5 R1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> ___ ___| + @Test + public void testLayout1KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(1, 5, XPOS_R2); + assertEquals("1 key max 5 R2 columns", 1, params.mNumColumns); + assertEquals("1 key max 5 R2 rows", 1, params.mNumRows); + assertEquals("1 key max 5 R2 left", 0, params.mLeftKeys); + assertEquals("1 key max 5 R2 right", 1, params.mRightKeys); + assertEquals("1 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("1 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("1 key max 5 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // <1> [2] + @Test + public void testLayout2KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_M0); + assertEquals("2 key max 5 M0 columns", 2, params.mNumColumns); + assertEquals("2 key max 5 M0 rows", 1, params.mNumRows); + assertEquals("2 key max 5 M0 left", 0, params.mLeftKeys); + assertEquals("2 key max 5 M0 right", 2, params.mRightKeys); + assertEquals("2 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key max 5 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |<1> [2] + @Test + public void testLayout2KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L0); + assertEquals("2 key max 5 L0 columns", 2, params.mNumColumns); + assertEquals("2 key max 5 L0 rows", 1, params.mNumRows); + assertEquals("2 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("2 key max 5 L0 right", 2, params.mRightKeys); + assertEquals("2 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] + @Test + public void testLayout2KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L1); + assertEquals("2 key max 5 L1 columns", 2, params.mNumColumns); + assertEquals("2 key max 5 L1 rows", 1, params.mNumRows); + assertEquals("2 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("2 key max 5 L1 right", 2, params.mRightKeys); + assertEquals("2 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ <1> [2] + @Test + public void testLayout2KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_L2); + assertEquals("2 key max 5 L2 columns", 2, params.mNumColumns); + assertEquals("2 key max 5 L2 rows", 1, params.mNumRows); + assertEquals("2 key max 5 L2 left", 0, params.mLeftKeys); + assertEquals("2 key max 5 L2 right", 2, params.mRightKeys); + assertEquals("2 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key max 5 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [2] <1>| + @Test + public void testLayout2KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R0); + assertEquals("2 key max 5 R0 columns", 2, params.mNumColumns); + assertEquals("2 key max 5 R0 rows", 1, params.mNumRows); + assertEquals("2 key max 5 R0 left", 1, params.mLeftKeys); + assertEquals("2 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("2 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("2 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key max 5 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [2] <1> ___| + @Test + public void testLayout2KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R1); + assertEquals("2 key max 5 R1 columns", 2, params.mNumColumns); + assertEquals("2 key max 5 R1 rows", 1, params.mNumRows); + assertEquals("2 key max 5 R1 left", 1, params.mLeftKeys); + assertEquals("2 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("2 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("2 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key max 5 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // <1> [2] ___| + @Test + public void testLayout2KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(2, 5, XPOS_R2); + assertEquals("2 key max 5 R2 columns", 2, params.mNumColumns); + assertEquals("2 key max 5 R2 rows", 1, params.mNumRows); + assertEquals("2 key max 5 R2 left", 0, params.mLeftKeys); + assertEquals("2 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("2 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("2 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("2 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("2 key max 5 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] + @Test + public void testLayout3KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_M0); + assertEquals("3 key max 5 M0 columns", 3, params.mNumColumns); + assertEquals("3 key max 5 M0 rows", 1, params.mNumRows); + assertEquals("3 key max 5 M0 left", 1, params.mLeftKeys); + assertEquals("3 key max 5 M0 right", 2, params.mRightKeys); + assertEquals("3 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] + @Test + public void testLayout3KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L0); + assertEquals("3 key max 5 L0 columns", 3, params.mNumColumns); + assertEquals("3 key max 5 L0 rows", 1, params.mNumRows); + assertEquals("3 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("3 key max 5 L0 right", 3, params.mRightKeys); + assertEquals("3 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] + @Test + public void testLayout3KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L1); + assertEquals("3 key max 5 L1 columns", 3, params.mNumColumns); + assertEquals("3 key max 5 L1 rows", 1, params.mNumRows); + assertEquals("3 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("3 key max 5 L1 right", 3, params.mRightKeys); + assertEquals("3 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("3 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] + @Test + public void testLayout3KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_L2); + assertEquals("3 key max 5 L2 columns", 3, params.mNumColumns); + assertEquals("3 key max 5 L2 rows", 1, params.mNumRows); + assertEquals("3 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("3 key max 5 L2 right", 2, params.mRightKeys); + assertEquals("3 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] [2] <1>| + @Test + public void testLayout3KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R0); + assertEquals("3 key max 5 R0 columns", 3, params.mNumColumns); + assertEquals("3 key max 5 R0 rows", 1, params.mNumRows); + assertEquals("3 key max 5 R0 left", 2, params.mLeftKeys); + assertEquals("3 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("3 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("3 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 5 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] [2] <1> ___| + @Test + public void testLayout3KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R1); + assertEquals("3 key max 5 R1 columns", 3, params.mNumColumns); + assertEquals("3 key max 5 R1 rows", 1, params.mNumRows); + assertEquals("3 key max 5 R1 left", 2, params.mLeftKeys); + assertEquals("3 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("3 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("3 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 5 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] ___| + @Test + public void testLayout3KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(3, 5, XPOS_R2); + assertEquals("3 key max 5 R2 columns", 3, params.mNumColumns); + assertEquals("3 key max 5 R2 rows", 1, params.mNumRows); + assertEquals("3 key max 5 R2 left", 1, params.mLeftKeys); + assertEquals("3 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("3 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("3 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 5 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] + // <1> [2] + @Test + public void testLayout3KeyMax2M0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_M0); + assertEquals("3 key max 2 M0 columns", 2, params.mNumColumns); + assertEquals("3 key max 2 M0 rows", 2, params.mNumRows); + assertEquals("3 key max 2 M0 left", 0, params.mLeftKeys); + assertEquals("3 key max 2 M0 right", 2, params.mRightKeys); + assertEquals("3 key max 2 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 2 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 2 M0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key max 2 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 2 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |[3] + // |<1> [2] + @Test + public void testLayout3KeyMax2L0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L0); + assertEquals("3 key max 2 L0 columns", 2, params.mNumColumns); + assertEquals("3 key max 2 L0 rows", 2, params.mNumRows); + assertEquals("3 key max 2 L0 left", 0, params.mLeftKeys); + assertEquals("3 key max 2 L0 right", 2, params.mRightKeys); + assertEquals("3 key max 2 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 2 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 2 L0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key max 2 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 2 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] + // |___ <1> [2] + @Test + public void testLayout3KeyMax2L1() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L1); + assertEquals("3 key max 2 L1 columns", 2, params.mNumColumns); + assertEquals("3 key max 2 L1 rows", 2, params.mNumRows); + assertEquals("3 key max 2 L1 left", 0, params.mLeftKeys); + assertEquals("3 key max 2 L1 right", 2, params.mRightKeys); + assertEquals("3 key max 2 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 2 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 2 L1 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key max 2 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 2 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // | [3] + // |___ ___ <1> [2] + @Test + public void testLayout3KeyMax2L2() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_L2); + assertEquals("3 key max 2 L2 columns", 2, params.mNumColumns); + assertEquals("3 key max 2 L2 rows", 2, params.mNumRows); + assertEquals("3 key max 2 L2 left", 0, params.mLeftKeys); + assertEquals("3 key max 2 L2 right", 2, params.mRightKeys); + assertEquals("3 key max 2 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 2 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 2 L2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key max 2 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 2 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3]| + // [2] <1>| + @Test + public void testLayout3KeyMax2R0() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R0); + assertEquals("3 key max 2 R0 columns", 2, params.mNumColumns); + assertEquals("3 key max 2 R0 rows", 2, params.mNumRows); + assertEquals("3 key max 2 R0 left", 1, params.mLeftKeys); + assertEquals("3 key max 2 R0 right", 1, params.mRightKeys); + assertEquals("3 key max 2 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 2 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key max 2 R0 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key max 2 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 2 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] | + // [2] <1> ___| + @Test + public void testLayout3KeyMax2R1() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R1); + assertEquals("3 key max 2 R1 columns", 2, params.mNumColumns); + assertEquals("3 key max 2 R1 rows", 2, params.mNumRows); + assertEquals("3 key max 2 R1 left", 1, params.mLeftKeys); + assertEquals("3 key max 2 R1 right", 1, params.mRightKeys); + assertEquals("3 key max 2 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 2 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("3 key max 2 R1 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key max 2 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 2 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] | + // <1> [2] ___| + @Test + public void testLayout3KeyMax2R2() { + MoreKeysKeyboardParams params = createParams(3, 2, XPOS_R2); + assertEquals("3 key max 2 R2 columns", 2, params.mNumColumns); + assertEquals("3 key max 2 R2 rows", 2, params.mNumRows); + assertEquals("3 key max 2 R2 left", 0, params.mLeftKeys); + assertEquals("3 key max 2 R2 right", 2, params.mRightKeys); + assertEquals("3 key max 2 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("3 key max 2 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("3 key max 2 R2 [3]", 0, params.getColumnPos(2)); + assertEquals("3 key max 2 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("3 key max 2 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] [4] + // <1> [2] + @Test + public void testLayout4KeyMax3M0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_M0); + assertEquals("4 key max 3 M0 columns", 2, params.mNumColumns); + assertEquals("4 key max 3 M0 rows", 2, params.mNumRows); + assertEquals("4 key max 3 M0 left", 0, params.mLeftKeys); + assertEquals("4 key max 3 M0 right", 2, params.mRightKeys); + assertEquals("4 key max 3 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 3 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 3 M0 [3]", 0, params.getColumnPos(2)); + assertEquals("4 key max 3 M0 [4]", 1, params.getColumnPos(3)); + assertEquals("4 key max 3 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 3 M0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |[3] [4] + // |<1> [2] + @Test + public void testLayout4KeyMax3L0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L0); + assertEquals("4 key max 3 L0 columns", 2, params.mNumColumns); + assertEquals("4 key max 3 L0 rows", 2, params.mNumRows); + assertEquals("4 key max 3 L0 left", 0, params.mLeftKeys); + assertEquals("4 key max 3 L0 right", 2, params.mRightKeys); + assertEquals("4 key max 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 3 L0 [3]", 0, params.getColumnPos(2)); + assertEquals("4 key max 3 L0 [4]", 1, params.getColumnPos(3)); + assertEquals("4 key max 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] [4] + // |___ <1> [2] + @Test + public void testLayout4KeyMax3L1() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L1); + assertEquals("4 key max 3 L1 columns", 2, params.mNumColumns); + assertEquals("4 key max 3 L1 rows", 2, params.mNumRows); + assertEquals("4 key max 3 L1 left", 0, params.mLeftKeys); + assertEquals("4 key max 3 L1 right", 2, params.mRightKeys); + assertEquals("4 key max 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 3 L1 [3]", 0, params.getColumnPos(2)); + assertEquals("4 key max 3 L1 [4]", 1, params.getColumnPos(3)); + assertEquals("4 key max 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ ___ [3] [4] + // |___ ___ <1> [2] + @Test + public void testLayout4KeyMax3L2() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_L2); + assertEquals("4 key max 3 L2 columns", 2, params.mNumColumns); + assertEquals("4 key max 3 L2 rows", 2, params.mNumRows); + assertEquals("4 key max 3 L2 left", 0, params.mLeftKeys); + assertEquals("4 key max 3 L2 right", 2, params.mRightKeys); + assertEquals("4 key max 3 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 3 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 3 L2 [3]", 0, params.getColumnPos(2)); + assertEquals("4 key max 3 L2 [4]", 1, params.getColumnPos(3)); + assertEquals("4 key max 3 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 3 L2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [4] [3]| + // [2] <1>| + @Test + public void testLayout4KeyMax3R0() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R0); + assertEquals("4 key max 3 R0 columns", 2, params.mNumColumns); + assertEquals("4 key max 3 R0 rows", 2, params.mNumRows); + assertEquals("4 key max 3 R0 left", 1, params.mLeftKeys); + assertEquals("4 key max 3 R0 right", 1, params.mRightKeys); + assertEquals("4 key max 3 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key max 3 R0 [3]", 0, params.getColumnPos(2)); + assertEquals("4 key max 3 R0 [4]", -1, params.getColumnPos(3)); + assertEquals("4 key max 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 3 R0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [3] ___| + // [2] <1> ___| + @Test + public void testLayout4KeyMax3R1() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R1); + assertEquals("4 key max 3 R1 columns", 2, params.mNumColumns); + assertEquals("4 key max 3 R1 rows", 2, params.mNumRows); + assertEquals("4 key max 3 R1 left", 1, params.mLeftKeys); + assertEquals("4 key max 3 R1 right", 1, params.mRightKeys); + assertEquals("4 key max 3 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key max 3 R1 [3]", 0, params.getColumnPos(2)); + assertEquals("4 key max 3 R1 [4]", -1, params.getColumnPos(3)); + assertEquals("4 key max 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 3 R1 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [3] [4] ___| + // <1> [2] ___| + @Test + public void testLayout4KeyMax3R2() { + MoreKeysKeyboardParams params = createParams(4, 3, XPOS_R2); + assertEquals("4 key max 3 R2 columns", 2, params.mNumColumns); + assertEquals("4 key max 3 R2 rows", 2, params.mNumRows); + assertEquals("4 key max 3 R2 left", 0, params.mLeftKeys); + assertEquals("4 key max 3 R2 right", 2, params.mRightKeys); + assertEquals("4 key max 3 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 3 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 3 R2 [3]", 0, params.getColumnPos(2)); + assertEquals("4 key max 3 R2 [4]", 1, params.getColumnPos(3)); + assertEquals("4 key max 3 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 3 R2 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] [4] + @Test + public void testLayout4KeyMax4M0() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_M0); + assertEquals("4 key max 4 M0 columns", 4, params.mNumColumns); + assertEquals("4 key max 4 M0 rows", 1, params.mNumRows); + assertEquals("4 key max 4 M0 left", 1, params.mLeftKeys); + assertEquals("4 key max 4 M0 right", 3, params.mRightKeys); + assertEquals("4 key max 4 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 4 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 4 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key max 4 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key max 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] + @Test + public void testLayout4KeyMax4L0() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_L0); + assertEquals("4 key max 4 L0 columns", 4, params.mNumColumns); + assertEquals("4 key max 4 L0 rows", 1, params.mNumRows); + assertEquals("4 key max 4 L0 left", 0, params.mLeftKeys); + assertEquals("4 key max 4 L0 right", 4, params.mRightKeys); + assertEquals("4 key max 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key max 4 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key max 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] + @Test + public void testLayout4KeyMax4L1() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_L1); + assertEquals("4 key max 4 L1 columns", 4, params.mNumColumns); + assertEquals("4 key max 4 L1 rows", 1, params.mNumRows); + assertEquals("4 key max 4 L1 left", 0, params.mLeftKeys); + assertEquals("4 key max 4 L1 right", 4, params.mRightKeys); + assertEquals("4 key max 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key max 4 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key max 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] + @Test + public void testLayout4KeyMax4L2() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_L2); + assertEquals("4 key max 4 L2 columns", 4, params.mNumColumns); + assertEquals("4 key max 4 L2 rows", 1, params.mNumRows); + assertEquals("4 key max 4 L2 left", 1, params.mLeftKeys); + assertEquals("4 key max 4 L2 right", 3, params.mRightKeys); + assertEquals("4 key max 4 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 4 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 4 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key max 4 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key max 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1>| + @Test + public void testLayout4KeyMax4R0() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_R0); + assertEquals("4 key max 4 R0 columns", 4, params.mNumColumns); + assertEquals("4 key max 4 R0 rows", 1, params.mNumRows); + assertEquals("4 key max 4 R0 left", 3, params.mLeftKeys); + assertEquals("4 key max 4 R0 right", 1, params.mRightKeys); + assertEquals("4 key max 4 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 4 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key max 4 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key max 4 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key max 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 4 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1> ___| + @Test + public void testLayout4KeyMax4R1() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_R1); + assertEquals("4 key max 4 R1 columns", 4, params.mNumColumns); + assertEquals("4 key max 4 R1 rows", 1, params.mNumRows); + assertEquals("4 key max 4 R1 left", 3, params.mLeftKeys); + assertEquals("4 key max 4 R1 right", 1, params.mRightKeys); + assertEquals("4 key max 4 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 4 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key max 4 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key max 4 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key max 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 4 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] <1> [2] ___| + @Test + public void testLayout4KeyMax4R2() { + MoreKeysKeyboardParams params = createParams(4, 4, XPOS_R2); + assertEquals("4 key max 4 R2 columns", 4, params.mNumColumns); + assertEquals("4 key max 4 R2 rows", 1, params.mNumRows); + assertEquals("4 key max 4 R2 left", 2, params.mLeftKeys); + assertEquals("4 key max 4 R2 right", 2, params.mRightKeys); + assertEquals("4 key max 4 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 4 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 4 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key max 4 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("4 key max 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 4 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [3] <1> [2] [4] + @Test + public void testLayout4KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_M0); + assertEquals("4 key max 5 M0 columns", 4, params.mNumColumns); + assertEquals("4 key max 5 M0 rows", 1, params.mNumRows); + assertEquals("4 key max 5 M0 left", 1, params.mLeftKeys); + assertEquals("4 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("4 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] + @Test + public void testLayout4KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L0); + assertEquals("4 key max 5 L0 columns", 4, params.mNumColumns); + assertEquals("4 key max 5 L0 rows", 1, params.mNumRows); + assertEquals("4 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("4 key max 5 L0 right", 4, params.mRightKeys); + assertEquals("4 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key max 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] + @Test + public void testLayout4KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L1); + assertEquals("4 key max 5 L1 columns", 4, params.mNumColumns); + assertEquals("4 key max 5 L1 rows", 1, params.mNumRows); + assertEquals("4 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("4 key max 5 L1 right", 4, params.mRightKeys); + assertEquals("4 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("4 key max 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("4 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] + @Test + public void testLayout4KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_L2); + assertEquals("4 key max 5 L2 columns", 4, params.mNumColumns); + assertEquals("4 key max 5 L2 rows", 1, params.mNumRows); + assertEquals("4 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("4 key max 5 L2 right", 3, params.mRightKeys); + assertEquals("4 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key max 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("4 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1>| + @Test + public void testLayout4KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R0); + assertEquals("4 key max 5 R0 columns", 4, params.mNumColumns); + assertEquals("4 key max 5 R0 rows", 1, params.mNumRows); + assertEquals("4 key max 5 R0 left", 3, params.mLeftKeys); + assertEquals("4 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("4 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key max 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 5 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] [2] <1> ___| + @Test + public void testLayout4KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R1); + assertEquals("4 key max 5 R1 columns", 4, params.mNumColumns); + assertEquals("4 key max 5 R1 rows", 1, params.mNumRows); + assertEquals("4 key max 5 R1 left", 3, params.mLeftKeys); + assertEquals("4 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("4 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("4 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("4 key max 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("4 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 5 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [4] [3] <1> [2] ___| + @Test + public void testLayout4KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(4, 5, XPOS_R2); + assertEquals("4 key max 5 R2 columns", 4, params.mNumColumns); + assertEquals("4 key max 5 R2 rows", 1, params.mNumRows); + assertEquals("4 key max 5 R2 left", 2, params.mLeftKeys); + assertEquals("4 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("4 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("4 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("4 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("4 key max 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("4 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("4 key max 5 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] + // [3] <1> [2] + @Test + public void testLayout5KeyMax3M0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_M0); + assertEquals("5 key max 3 M0 columns", 3, params.mNumColumns); + assertEquals("5 key max 3 M0 rows", 2, params.mNumRows); + assertEquals("5 key max 3 M0 left", 1, params.mLeftKeys); + assertEquals("5 key max 3 M0 right", 2, params.mRightKeys); + assertEquals("5 key max 3 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 3 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 3 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 3 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 3 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 3 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key max 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] + // |<1> [2] [3] + @Test + public void testLayout5KeyMax3L0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L0); + assertEquals("5 key max 3 L0 columns", 3, params.mNumColumns); + assertEquals("5 key max 3 L0 rows", 2, params.mNumRows); + assertEquals("5 key max 3 L0 left", 0, params.mLeftKeys); + assertEquals("5 key max 3 L0 right", 3, params.mRightKeys); + assertEquals("5 key max 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key max 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 3 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ <1> [2] [3] + @Test + public void testLayout5KeyMax3L1() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L1); + assertEquals("5 key max 3 L1 columns", 3, params.mNumColumns); + assertEquals("5 key max 3 L1 rows", 2, params.mNumRows); + assertEquals("5 key max 3 L1 left", 0, params.mLeftKeys); + assertEquals("5 key max 3 L1 right", 3, params.mRightKeys); + assertEquals("5 key max 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key max 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 3 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ [3] <1> [2] + @Test + public void testLayout5KeyMax3L2() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_L2); + assertEquals("5 key max 3 L2 columns", 3, params.mNumColumns); + assertEquals("5 key max 3 L2 rows", 2, params.mNumRows); + assertEquals("5 key max 3 L2 left", 1, params.mLeftKeys); + assertEquals("5 key max 3 L2 right", 2, params.mRightKeys); + assertEquals("5 key max 3 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 3 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 3 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 3 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 3 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 3 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key max 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [4]| + // [3] [2] <1>| + @Test + public void testLayout5KeyMax3R0() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R0); + assertEquals("5 key max 3 R0 columns", 3, params.mNumColumns); + assertEquals("5 key max 3 R0 rows", 2, params.mNumRows); + assertEquals("5 key max 3 R0 left", 2, params.mLeftKeys); + assertEquals("5 key max 3 R0 right", 1, params.mRightKeys); + assertEquals("5 key max 3 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key max 3 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key max 3 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 3 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("5 key max 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout5KeyMax3R1() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R1); + assertEquals("5 key max 3 R1 columns", 3, params.mNumColumns); + assertEquals("5 key max 3 R1 rows", 2, params.mNumRows); + assertEquals("5 key max 3 R1 left", 2, params.mLeftKeys); + assertEquals("5 key max 3 R1 right", 1, params.mRightKeys); + assertEquals("5 key max 3 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key max 3 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key max 3 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 3 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("5 key max 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] ___| + // [3] <1> [2] ___| + @Test + public void testLayout5KeyMax3R2() { + MoreKeysKeyboardParams params = createParams(5, 3, XPOS_R2); + assertEquals("5 key max 3 R2 columns", 3, params.mNumColumns); + assertEquals("5 key max 3 R2 rows", 2, params.mNumRows); + assertEquals("5 key max 3 R2 left", 1, params.mLeftKeys); + assertEquals("5 key max 3 R2 right", 2, params.mRightKeys); + assertEquals("5 key max 3 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 3 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 3 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 3 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 3 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 3 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key max 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [4] [5] + // [3] <1> [2] + @Test + public void testLayout5KeyMax4M0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_M0); + assertEquals("5 key max 4 M0 columns", 3, params.mNumColumns); + assertEquals("5 key max 4 M0 rows", 2, params.mNumRows); + assertEquals("5 key max 4 M0 left", 1, params.mLeftKeys); + assertEquals("5 key max 4 M0 right", 2, params.mRightKeys); + assertEquals("5 key max 4 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 4 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 4 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 4 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 4 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 4 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key max 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] + // |<1> [2] [3] + @Test + public void testLayout5KeyMax4L0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L0); + assertEquals("5 key max 4 L0 columns", 3, params.mNumColumns); + assertEquals("5 key max 4 L0 rows", 2, params.mNumRows); + assertEquals("5 key max 4 L0 left", 0, params.mLeftKeys); + assertEquals("5 key max 4 L0 right", 3, params.mRightKeys); + assertEquals("5 key max 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key max 4 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 4 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ <1> [2] [3] + @Test + public void testLayout5KeyMax4L1() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L1); + assertEquals("5 key max 4 L1 columns", 3, params.mNumColumns); + assertEquals("5 key max 4 L1 rows", 2, params.mNumRows); + assertEquals("5 key max 4 L1 left", 0, params.mLeftKeys); + assertEquals("5 key max 4 L1 right", 3, params.mRightKeys); + assertEquals("5 key max 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key max 4 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 4 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] + // |___ [3] <1> [2] + @Test + public void testLayout5KeyMax4L2() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_L2); + assertEquals("5 key max 4 L2 columns", 3, params.mNumColumns); + assertEquals("5 key max 4 L2 rows", 2, params.mNumRows); + assertEquals("5 key max 4 L2 left", 1, params.mLeftKeys); + assertEquals("5 key max 4 L2 right", 2, params.mRightKeys); + assertEquals("5 key max 4 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 4 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 4 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 4 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 4 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 4 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key max 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [4]| + // [3] [2] <1>| + @Test + public void testLayout5KeyMax4R0() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R0); + assertEquals("5 key max 4 R0 columns", 3, params.mNumColumns); + assertEquals("5 key max 4 R0 rows", 2, params.mNumRows); + assertEquals("5 key max 4 R0 left", 2, params.mLeftKeys); + assertEquals("5 key max 4 R0 right", 1, params.mRightKeys); + assertEquals("5 key max 4 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 4 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key max 4 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key max 4 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 4 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("5 key max 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 4 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [5] [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout5KeyMax4R1() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R1); + assertEquals("5 key max 4 R1 columns", 3, params.mNumColumns); + assertEquals("5 key max 4 R1 rows", 2, params.mNumRows); + assertEquals("5 key max 4 R1 left", 2, params.mLeftKeys); + assertEquals("5 key max 4 R1 right", 1, params.mRightKeys); + assertEquals("5 key max 4 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 4 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key max 4 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key max 4 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 4 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("5 key max 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 4 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [4] [5] ___| + // [3] <1> [2] ___| + @Test + public void testLayout5KeyMax4R2() { + MoreKeysKeyboardParams params = createParams(5, 4, XPOS_R2); + assertEquals("5 key max 4 R2 columns", 3, params.mNumColumns); + assertEquals("5 key max 4 R2 rows", 2, params.mNumRows); + assertEquals("5 key max 4 R2 left", 1, params.mLeftKeys); + assertEquals("5 key max 4 R2 right", 2, params.mRightKeys); + assertEquals("5 key max 4 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 4 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 4 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 4 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("5 key max 4 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("5 key max 4 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("5 key max 4 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [3] <1> [2] [4] + @Test + public void testLayout5KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_M0); + assertEquals("5 key max 5 M0 columns", 5, params.mNumColumns); + assertEquals("5 key max 5 M0 rows", 1, params.mNumRows); + assertEquals("5 key max 5 M0 left", 2, params.mLeftKeys); + assertEquals("5 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("5 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key max 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("5 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] [5] + @Test + public void testLayout5KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L0); + assertEquals("5 key max 5 L0 columns", 5, params.mNumColumns); + assertEquals("5 key max 5 L0 rows", 1, params.mNumRows); + assertEquals("5 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("5 key max 5 L0 right", 5, params.mRightKeys); + assertEquals("5 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key max 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key max 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout5KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L1); + assertEquals("5 key max 5 L1 columns", 5, params.mNumColumns); + assertEquals("5 key max 5 L1 rows", 1, params.mNumRows); + assertEquals("5 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("5 key max 5 L1 right", 5, params.mRightKeys); + assertEquals("5 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("5 key max 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("5 key max 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("5 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout5KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_L2); + assertEquals("5 key max 5 L2 columns", 5, params.mNumColumns); + assertEquals("5 key max 5 L2 rows", 1, params.mNumRows); + assertEquals("5 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("5 key max 5 L2 right", 4, params.mRightKeys); + assertEquals("5 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("5 key max 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("5 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] [2] <1>| + @Test + public void testLayout5KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R0); + assertEquals("5 key max 5 R0 columns", 5, params.mNumColumns); + assertEquals("5 key max 5 R0 rows", 1, params.mNumRows); + assertEquals("5 key max 5 R0 left", 4, params.mLeftKeys); + assertEquals("5 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("5 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key max 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key max 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("5 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout5KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R1); + assertEquals("5 key max 5 R1 columns", 5, params.mNumColumns); + assertEquals("5 key max 5 R1 rows", 1, params.mNumRows); + assertEquals("5 key max 5 R1 left", 4, params.mLeftKeys); + assertEquals("5 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("5 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("5 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("5 key max 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("5 key max 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("5 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout5KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(5, 5, XPOS_R2); + assertEquals("5 key max 5 R2 columns", 5, params.mNumColumns); + assertEquals("5 key max 5 R2 rows", 1, params.mNumRows); + assertEquals("5 key max 5 R2 left", 3, params.mLeftKeys); + assertEquals("5 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("5 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("5 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("5 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("5 key max 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("5 key max 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("5 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("5 key max 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [6] [4] [5] + // [3] <1> [2] + @Test + public void testLayout6KeyMax4M0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_M0); + assertEquals("6 key max 4 M0 columns", 3, params.mNumColumns); + assertEquals("6 key max 4 M0 rows", 2, params.mNumRows); + assertEquals("6 key max 4 M0 left", 1, params.mLeftKeys); + assertEquals("6 key max 4 M0 right", 2, params.mRightKeys); + assertEquals("6 key max 4 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 4 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 4 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key max 4 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 4 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 4 M0 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key max 4 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 4 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] [6] + // |<1> [2] [3] + @Test + public void testLayout6KeyMax4L0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L0); + assertEquals("6 key max 4 L0 columns", 3, params.mNumColumns); + assertEquals("6 key max 4 L0 rows", 2, params.mNumRows); + assertEquals("6 key max 4 L0 left", 0, params.mLeftKeys); + assertEquals("6 key max 4 L0 right", 3, params.mRightKeys); + assertEquals("6 key max 4 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 4 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 4 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key max 4 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 4 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 4 L0 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key max 4 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 4 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] [6] + // |___ <1> [2] [3] + @Test + public void testLayout6KeyMax4L1() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L1); + assertEquals("6 key max 4 L1 columns", 3, params.mNumColumns); + assertEquals("6 key max 4 L1 rows", 2, params.mNumRows); + assertEquals("6 key max 4 L1 left", 0, params.mLeftKeys); + assertEquals("6 key max 4 L1 right", 3, params.mRightKeys); + assertEquals("6 key max 4 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 4 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 4 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key max 4 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 4 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 4 L1 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key max 4 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 4 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [4] [5] + // |___ [3] <1> [2] + @Test + public void testLayout6KeyMax4L2() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_L2); + assertEquals("6 key max 4 L2 columns", 3, params.mNumColumns); + assertEquals("6 key max 4 L2 rows", 2, params.mNumRows); + assertEquals("6 key max 4 L2 left", 1, params.mLeftKeys); + assertEquals("6 key max 4 L2 right", 2, params.mRightKeys); + assertEquals("6 key max 4 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 4 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 4 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key max 4 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 4 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 4 L2 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key max 4 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 4 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [5] [4]| + // [3] [2] <1>| + @Test + public void testLayout6KeyMax4R0() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R0); + assertEquals("6 key max 4 R0 columns", 3, params.mNumColumns); + assertEquals("6 key max 4 R0 rows", 2, params.mNumRows); + assertEquals("6 key max 4 R0 left", 2, params.mLeftKeys); + assertEquals("6 key max 4 R0 right", 1, params.mRightKeys); + assertEquals("6 key max 4 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 4 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key max 4 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key max 4 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 4 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key max 4 R0 [6]", -2, params.getColumnPos(5)); + assertEquals("6 key max 4 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 4 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [6] [5] [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout6KeyMax4R1() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R1); + assertEquals("6 key max 4 R1 columns", 3, params.mNumColumns); + assertEquals("6 key max 4 R1 rows", 2, params.mNumRows); + assertEquals("6 key max 4 R1 left", 2, params.mLeftKeys); + assertEquals("6 key max 4 R1 right", 1, params.mRightKeys); + assertEquals("6 key max 4 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 4 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key max 4 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key max 4 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 4 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key max 4 R1 [6]", -2, params.getColumnPos(5)); + assertEquals("6 key max 4 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 4 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [6] [4] [5] ___| + // [3] <1> [2] ___| + @Test + public void testLayout6KeyMax4R2() { + MoreKeysKeyboardParams params = createParams(6, 4, XPOS_R2); + assertEquals("6 key max 4 R2 columns", 3, params.mNumColumns); + assertEquals("6 key max 4 R2 rows", 2, params.mNumRows); + assertEquals("6 key max 4 R2 left", 1, params.mLeftKeys); + assertEquals("6 key max 4 R2 right", 2, params.mRightKeys); + assertEquals("6 key max 4 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 4 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 4 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key max 4 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 4 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 4 R2 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key max 4 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 4 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [4] [5] + // [3] <1> [2] + @Test + public void testLayout6KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_M0); + assertEquals("6 key max 5 M0 columns", 3, params.mNumColumns); + assertEquals("6 key max 5 M0 rows", 2, params.mNumRows); + assertEquals("6 key max 5 M0 left", 1, params.mLeftKeys); + assertEquals("6 key max 5 M0 right", 2, params.mRightKeys); + assertEquals("6 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key max 5 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 5 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 5 M0 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[4] [5] [6] + // |<1> [2] [3] + @Test + public void testLayout6KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L0); + assertEquals("6 key max 5 L0 columns", 3, params.mNumColumns); + assertEquals("6 key max 5 L0 rows", 2, params.mNumRows); + assertEquals("6 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("6 key max 5 L0 right", 3, params.mRightKeys); + assertEquals("6 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key max 5 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 5 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 5 L0 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [4] [5] [6] + // |___ <1> [2] [3] + @Test + public void testLayout6KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L1); + assertEquals("6 key max 5 L1 columns", 3, params.mNumColumns); + assertEquals("6 key max 5 L1 rows", 2, params.mNumRows); + assertEquals("6 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("6 key max 5 L1 right", 3, params.mRightKeys); + assertEquals("6 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("6 key max 5 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 5 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 5 L1 [6]", 2, params.getColumnPos(5)); + assertEquals("6 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [4] [5] + // |___ [3] <1> [2] + @Test + public void testLayout6KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_L2); + assertEquals("6 key max 5 L2 columns", 3, params.mNumColumns); + assertEquals("6 key max 5 L2 rows", 2, params.mNumRows); + assertEquals("6 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("6 key max 5 L2 right", 2, params.mRightKeys); + assertEquals("6 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key max 5 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 5 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 5 L2 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [6] [5] [4]| + // [3] [2] <1>| + @Test + public void testLayout6KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R0); + assertEquals("6 key max 5 R0 columns", 3, params.mNumColumns); + assertEquals("6 key max 5 R0 rows", 2, params.mNumRows); + assertEquals("6 key max 5 R0 left", 2, params.mLeftKeys); + assertEquals("6 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("6 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key max 5 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 5 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key max 5 R0 [6]", -2, params.getColumnPos(5)); + assertEquals("6 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 5 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [6] [5] [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout6KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R1); + assertEquals("6 key max 5 R1 columns", 3, params.mNumColumns); + assertEquals("6 key max 5 R1 rows", 2, params.mNumRows); + assertEquals("6 key max 5 R1 left", 2, params.mLeftKeys); + assertEquals("6 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("6 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("6 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("6 key max 5 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 5 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("6 key max 5 R1 [6]", -2, params.getColumnPos(5)); + assertEquals("6 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 5 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [6] [4] [5] ___| + // [3] <1> [2] ___| + @Test + public void testLayout6KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(6, 5, XPOS_R2); + assertEquals("6 key max 5 R2 columns", 3, params.mNumColumns); + assertEquals("6 key max 5 R2 rows", 2, params.mNumRows); + assertEquals("6 key max 5 R2 left", 1, params.mLeftKeys); + assertEquals("6 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("6 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("6 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("6 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("6 key max 5 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("6 key max 5 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("6 key max 5 R2 [6]", -1, params.getColumnPos(5)); + assertEquals("6 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("6 key max 5 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |<1> [2] [3] [4] [5] [6] [7] ___ ___ ___| + @Test + public void testLayout7KeyMax7L0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L0); + assertEquals("7 key max 7 L0 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 L0 rows", 1, params.mNumRows); + assertEquals("7 key max 7 L0 left", 0, params.mLeftKeys); + assertEquals("7 key max 7 L0 right", 7, params.mRightKeys); + assertEquals("7 key max 7 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key max 7 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key max 7 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key max 7 L0 [6]", 5, params.getColumnPos(5)); + assertEquals("7 key max 7 L0 [7]", 6, params.getColumnPos(6)); + assertEquals("7 key max 7 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ <1> [2] [3] [4] [5] [6] [7] ___ ___| + @Test + public void testLayout7KeyMax7L1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L1); + assertEquals("7 key max 7 L1 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 L1 rows", 1, params.mNumRows); + assertEquals("7 key max 7 L1 left", 0, params.mLeftKeys); + assertEquals("7 key max 7 L1 right", 7, params.mRightKeys); + assertEquals("7 key max 7 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key max 7 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key max 7 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("7 key max 7 L1 [6]", 5, params.getColumnPos(5)); + assertEquals("7 key max 7 L1 [7]", 6, params.getColumnPos(6)); + assertEquals("7 key max 7 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [3] <1> [2] [4] [5] [6] [7] ___ ___| + @Test + public void testLayout7KeyMax7L2() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L2); + assertEquals("7 key max 7 L2 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 L2 rows", 1, params.mNumRows); + assertEquals("7 key max 7 L2 left", 1, params.mLeftKeys); + assertEquals("7 key max 7 L2 right", 6, params.mRightKeys); + assertEquals("7 key max 7 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 7 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key max 7 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("7 key max 7 L2 [6]", 4, params.getColumnPos(5)); + assertEquals("7 key max 7 L2 [7]", 5, params.getColumnPos(6)); + assertEquals("7 key max 7 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |___ [5] [3] <1> [2] [4] [6] [7] ___ ___| + @Test + public void testLayout7KeyMax7L3() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_L3); + assertEquals("7 key max 7 L3 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 L3 rows", 1, params.mNumRows); + assertEquals("7 key max 7 L3 left", 2, params.mLeftKeys); + assertEquals("7 key max 7 L3 right", 5, params.mRightKeys); + assertEquals("7 key max 7 L3 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 L3 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 L3 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 7 L3 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key max 7 L3 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key max 7 L3 [6]", 3, params.getColumnPos(5)); + assertEquals("7 key max 7 L3 [7]", 4, params.getColumnPos(6)); + assertEquals("7 key max 7 L3 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 L3 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |___ [7] [5] [3] <1> [2] [4] [6] ___ ___| + @Test + public void testLayout7KeyMax7M0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_M0); + assertEquals("7 key max 7 M0 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 M0 rows", 1, params.mNumRows); + assertEquals("7 key max 7 M0 left", 3, params.mLeftKeys); + assertEquals("7 key max 7 M0 right", 4, params.mRightKeys); + assertEquals("7 key max 7 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 7 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key max 7 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key max 7 M0 [6]", 3, params.getColumnPos(5)); + assertEquals("7 key max 7 M0 [7]", -3, params.getColumnPos(6)); + assertEquals("7 key max 7 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 M0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [5] [3] <1> [2] [4] [6] ___| + @Test + public void testLayout7KeyMax7M1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_M1); + assertEquals("7 key max 7 M1 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 M1 rows", 1, params.mNumRows); + assertEquals("7 key max 7 M1 left", 3, params.mLeftKeys); + assertEquals("7 key max 7 M1 right", 4, params.mRightKeys); + assertEquals("7 key max 7 M1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 M1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 M1 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 7 M1 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key max 7 M1 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key max 7 M1 [6]", 3, params.getColumnPos(5)); + assertEquals("7 key max 7 M1 [7]", -3, params.getColumnPos(6)); + assertEquals("7 key max 7 M1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 M1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [3] <1> [2] [4] ___| + @Test + public void testLayout7KeyMax7R3() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R3); + assertEquals("7 key max 7 R3 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 R3 rows", 1, params.mNumRows); + assertEquals("7 key max 7 R3 left", 4, params.mLeftKeys); + assertEquals("7 key max 7 R3 right", 3, params.mRightKeys); + assertEquals("7 key max 7 R3 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 R3 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 R3 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 7 R3 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key max 7 R3 [5]", -2, params.getColumnPos(4)); + assertEquals("7 key max 7 R3 [6]", -3, params.getColumnPos(5)); + assertEquals("7 key max 7 R3 [7]", -4, params.getColumnPos(6)); + assertEquals("7 key max 7 R3 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 R3 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [4] [3] <1> [2] ___| + @Test + public void testLayout7KeyMax7R2() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R2); + assertEquals("7 key max 7 R2 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 R2 rows", 1, params.mNumRows); + assertEquals("7 key max 7 R2 left", 5, params.mLeftKeys); + assertEquals("7 key max 7 R2 right", 2, params.mRightKeys); + assertEquals("7 key max 7 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 7 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 7 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("7 key max 7 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("7 key max 7 R2 [6]", -4, params.getColumnPos(5)); + assertEquals("7 key max 7 R2 [7]", -5, params.getColumnPos(6)); + assertEquals("7 key max 7 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 R2 default", WIDTH * 5, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [4] [3] [2] <1> ___| + @Test + public void testLayout7KeyMax7R1() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R1); + assertEquals("7 key max 7 R1 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 R1 rows", 1, params.mNumRows); + assertEquals("7 key max 7 R1 left", 6, params.mLeftKeys); + assertEquals("7 key max 7 R1 right", 1, params.mRightKeys); + assertEquals("7 key max 7 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key max 7 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key max 7 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key max 7 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("7 key max 7 R1 [6]", -5, params.getColumnPos(5)); + assertEquals("7 key max 7 R1 [7]", -6, params.getColumnPos(6)); + assertEquals("7 key max 7 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 R1 default", WIDTH * 6, params.getDefaultKeyCoordX()); + } + + // |___ ___ [7] [6] [5] [4] [3] [2] <1>| + @Test + public void testLayout7KeyMax7R0() { + MoreKeysKeyboardParams params = createParams(7, 7, XPOS_R0); + assertEquals("7 key max 7 R0 columns", 7, params.mNumColumns); + assertEquals("7 key max 7 R0 rows", 1, params.mNumRows); + assertEquals("7 key max 7 R0 left", 6, params.mLeftKeys); + assertEquals("7 key max 7 R0 right", 1, params.mRightKeys); + assertEquals("7 key max 7 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 7 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key max 7 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key max 7 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key max 7 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("7 key max 7 R0 [6]", -5, params.getColumnPos(5)); + assertEquals("7 key max 7 R0 [7]", -6, params.getColumnPos(6)); + assertEquals("7 key max 7 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 7 R0 default", WIDTH * 6, params.getDefaultKeyCoordX()); + } + + // [5] [6] [7] + // [3] <1> [2] [4] + @Test + public void testLayout7KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_M0); + assertEquals("7 key max 5 M0 columns", 4, params.mNumColumns); + assertEquals("7 key max 5 M0 rows", 2, params.mNumRows); + assertEquals("7 key max 5 M0 left", 1, params.mLeftKeys); + assertEquals("7 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("7 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key max 5 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key max 5 M0 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key max 5 M0 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key max 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key max 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] [7] + // |<1> [2] [3] [4] + @Test + public void testLayout7KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L0); + assertEquals("7 key max 5 L0 columns", 4, params.mNumColumns); + assertEquals("7 key max 5 L0 rows", 2, params.mNumRows); + assertEquals("7 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("7 key max 5 L0 right", 4, params.mRightKeys); + assertEquals("7 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key max 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key max 5 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key max 5 L0 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key max 5 L0 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] + // |___ <1> [2] [3] [4] + @Test + public void testLayout7KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L1); + assertEquals("7 key max 5 L1 columns", 4, params.mNumColumns); + assertEquals("7 key max 5 L1 rows", 2, params.mNumRows); + assertEquals("7 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("7 key max 5 L1 right", 4, params.mRightKeys); + assertEquals("7 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key max 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("7 key max 5 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key max 5 L1 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key max 5 L1 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] + // |___ [3] <1> [2] [4] + @Test + public void testLayout7KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_L2); + assertEquals("7 key max 5 L2 columns", 4, params.mNumColumns); + assertEquals("7 key max 5 L2 rows", 2, params.mNumRows); + assertEquals("7 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("7 key max 5 L2 right", 3, params.mRightKeys); + assertEquals("7 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("7 key max 5 L2 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key max 5 L2 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key max 5 L2 [7]", 2, params.getColumnPos(6)); + assertEquals("7 key max 5 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [7] [6] [5]| + // [4] [3] [2] <1>| + @Test + public void testLayout7KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R0); + assertEquals("7 key max 5 R0 columns", 4, params.mNumColumns); + assertEquals("7 key max 5 R0 rows", 2, params.mNumRows); + assertEquals("7 key max 5 R0 left", 3, params.mLeftKeys); + assertEquals("7 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("7 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key max 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key max 5 R0 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key max 5 R0 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key max 5 R0 [7]", -2, params.getColumnPos(6)); + assertEquals("7 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 5 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [7] [6] [5] ___| + // [4] [3] [2] <1> ___| + @Test + public void testLayout7KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R1); + assertEquals("7 key max 5 R1 columns", 4, params.mNumColumns); + assertEquals("7 key max 5 R1 rows", 2, params.mNumRows); + assertEquals("7 key max 5 R1 left", 3, params.mLeftKeys); + assertEquals("7 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("7 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key max 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("7 key max 5 R1 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key max 5 R1 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key max 5 R1 [7]", -2, params.getColumnPos(6)); + assertEquals("7 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 5 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [7] [5] [6] ___| + // [4] [3] <1> [2] ___| + @Test + public void testLayout7KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(7, 5, XPOS_R2); + assertEquals("7 key max 5 R2 columns", 4, params.mNumColumns); + assertEquals("7 key max 5 R2 rows", 2, params.mNumRows); + assertEquals("7 key max 5 R2 left", 2, params.mLeftKeys); + assertEquals("7 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("7 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("7 key max 5 R2 [5]", 0, params.getColumnPos(4)); + assertEquals("7 key max 5 R2 [6]", 1, params.getColumnPos(5)); + assertEquals("7 key max 5 R2 [7]", -1, params.getColumnPos(6)); + assertEquals("7 key max 5 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("7 key max 5 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [7] + // [6] [4] [5] + // [3] <1> [2] + @Test + public void testLayout7KeyMax3M0() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_M0); + assertEquals("7 key max 3 M0 columns", 3, params.mNumColumns); + assertEquals("7 key max 3 M0 rows", 3, params.mNumRows); + assertEquals("7 key max 3 M0 left", 1, params.mLeftKeys); + assertEquals("7 key max 3 M0 right", 2, params.mRightKeys); + assertEquals("7 key max 3 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 3 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 3 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 3 M0 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key max 3 M0 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key max 3 M0 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key max 3 M0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key max 3 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 3 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[7] + // |[4] [5] [6] + // |<1> [2] [3] + @Test + public void testLayout7KeyMax3L0() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_L0); + assertEquals("7 key max 3 L0 columns", 3, params.mNumColumns); + assertEquals("7 key max 3 L0 rows", 3, params.mNumRows); + assertEquals("7 key max 3 L0 left", 0, params.mLeftKeys); + assertEquals("7 key max 3 L0 right", 3, params.mRightKeys); + assertEquals("7 key max 3 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 3 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 3 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key max 3 L0 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key max 3 L0 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key max 3 L0 [6]", 2, params.getColumnPos(5)); + assertEquals("7 key max 3 L0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key max 3 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 3 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [7] + // |___ [4] [5] [6] + // |___ <1> [2] [3] + @Test + public void testLayout7KeyMax3L1() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_L1); + assertEquals("7 key max 3 L1 columns", 3, params.mNumColumns); + assertEquals("7 key max 3 L1 rows", 3, params.mNumRows); + assertEquals("7 key max 3 L1 left", 0, params.mLeftKeys); + assertEquals("7 key max 3 L1 right", 3, params.mRightKeys); + assertEquals("7 key max 3 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 3 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 3 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("7 key max 3 L1 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key max 3 L1 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key max 3 L1 [6]", 2, params.getColumnPos(5)); + assertEquals("7 key max 3 L1 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key max 3 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 3 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [7] + // |___ [6] [4] [5] + // |___ [3] <1> [2] + @Test + public void testLayout7KeyMax3L2() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_L2); + assertEquals("7 key max 3 L2 columns", 3, params.mNumColumns); + assertEquals("7 key max 3 L2 rows", 3, params.mNumRows); + assertEquals("7 key max 3 L2 left", 1, params.mLeftKeys); + assertEquals("7 key max 3 L2 right", 2, params.mRightKeys); + assertEquals("7 key max 3 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 3 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 3 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 3 L2 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key max 3 L2 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key max 3 L2 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key max 3 L2 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key max 3 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 3 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [7]| + // [6] [5] [4]| + // [3] [2] <1>| + @Test + public void testLayout7KeyMax3R0() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_R0); + assertEquals("7 key max 3 R0 columns", 3, params.mNumColumns); + assertEquals("7 key max 3 R0 rows", 3, params.mNumRows); + assertEquals("7 key max 3 R0 left", 2, params.mLeftKeys); + assertEquals("7 key max 3 R0 right", 1, params.mRightKeys); + assertEquals("7 key max 3 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 3 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key max 3 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key max 3 R0 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key max 3 R0 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key max 3 R0 [6]", -2, params.getColumnPos(5)); + assertEquals("7 key max 3 R0 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key max 3 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 3 R0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [7] ___| + // [6] [5] [4] ___| + // [3] [2] <1> ___| + @Test + public void testLayout7KeyMax3R1() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_R1); + assertEquals("7 key max 3 R1 columns", 3, params.mNumColumns); + assertEquals("7 key max 3 R1 rows", 3, params.mNumRows); + assertEquals("7 key max 3 R1 left", 2, params.mLeftKeys); + assertEquals("7 key max 3 R1 right", 1, params.mRightKeys); + assertEquals("7 key max 3 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 3 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("7 key max 3 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("7 key max 3 R1 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key max 3 R1 [5]", -1, params.getColumnPos(4)); + assertEquals("7 key max 3 R1 [6]", -2, params.getColumnPos(5)); + assertEquals("7 key max 3 R1 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key max 3 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 3 R1 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [7] ___| + // [6] [4] [5] ___| + // [3] <1> [2] ___| + @Test + public void testLayout7KeyMax3R2() { + MoreKeysKeyboardParams params = createParams(7, 3, XPOS_R2); + assertEquals("7 key max 3 R2 columns", 3, params.mNumColumns); + assertEquals("7 key max 3 R2 rows", 3, params.mNumRows); + assertEquals("7 key max 3 R2 left", 1, params.mLeftKeys); + assertEquals("7 key max 3 R2 right", 2, params.mRightKeys); + assertEquals("7 key max 3 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("7 key max 3 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("7 key max 3 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("7 key max 3 R2 [4]", 0, params.getColumnPos(3)); + assertEquals("7 key max 3 R2 [5]", 1, params.getColumnPos(4)); + assertEquals("7 key max 3 R2 [6]", -1, params.getColumnPos(5)); + assertEquals("7 key max 3 R2 [7]", 0, params.getColumnPos(6)); + assertEquals("7 key max 3 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("7 key max 3 R2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [7] [5] [6] [8] + // [3] <1> [2] [4] + @Test + public void testLayout8KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_M0); + assertEquals("8 key max 5 M0 columns", 4, params.mNumColumns); + assertEquals("8 key max 5 M0 rows", 2, params.mNumRows); + assertEquals("8 key max 5 M0 left", 1, params.mLeftKeys); + assertEquals("8 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("8 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key max 5 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key max 5 M0 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key max 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key max 5 M0 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key max 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // |[5] [6] [7] [8] + // |<1> [2] [3] [4] + @Test + public void testLayout8KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L0); + assertEquals("8 key max 5 L0 columns", 4, params.mNumColumns); + assertEquals("8 key max 5 L0 rows", 2, params.mNumRows); + assertEquals("8 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("8 key max 5 L0 right", 4, params.mRightKeys); + assertEquals("8 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key max 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key max 5 L0 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key max 5 L0 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key max 5 L0 [7]", 2, params.getColumnPos(6)); + assertEquals("8 key max 5 L0 [8]", 3, params.getColumnPos(7)); + assertEquals("8 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [5] [6] [7] [8] + // |___ <1> [2] [3] [4] + @Test + public void testLayout8KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L1); + assertEquals("8 key max 5 L1 columns", 4, params.mNumColumns); + assertEquals("8 key max 5 L1 rows", 2, params.mNumRows); + assertEquals("8 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("8 key max 5 L1 right", 4, params.mRightKeys); + assertEquals("8 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("8 key max 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("8 key max 5 L1 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key max 5 L1 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key max 5 L1 [7]", 2, params.getColumnPos(6)); + assertEquals("8 key max 5 L1 [8]", 3, params.getColumnPos(7)); + assertEquals("8 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [7] [5] [6] [8] + // |___ [3] <1> [2] [4] + @Test + public void testLayout8KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_L2); + assertEquals("8 key max 5 L2 columns", 4, params.mNumColumns); + assertEquals("8 key max 5 L2 rows", 2, params.mNumRows); + assertEquals("8 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("8 key max 5 L2 right", 3, params.mRightKeys); + assertEquals("8 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key max 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("8 key max 5 L2 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key max 5 L2 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key max 5 L2 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key max 5 L2 [8]", 2, params.getColumnPos(7)); + assertEquals("8 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [8] [7] [6] [5]| + // [4] [3] [2] <1>| + @Test + public void testLayout8KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R0); + assertEquals("8 key max 5 R0 columns", 4, params.mNumColumns); + assertEquals("8 key max 5 R0 rows", 2, params.mNumRows); + assertEquals("8 key max 5 R0 left", 3, params.mLeftKeys); + assertEquals("8 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("8 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key max 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("8 key max 5 R0 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key max 5 R0 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key max 5 R0 [7]", -2, params.getColumnPos(6)); + assertEquals("8 key max 5 R0 [8]", -3, params.getColumnPos(7)); + assertEquals("8 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key max 5 R0 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [8] [7] [6] [5] ___| + // [4] [3] [2] <1> ___| + @Test + public void testLayout8KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R1); + assertEquals("8 key max 5 R1 columns", 4, params.mNumColumns); + assertEquals("8 key max 5 R1 rows", 2, params.mNumRows); + assertEquals("8 key max 5 R1 left", 3, params.mLeftKeys); + assertEquals("8 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("8 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("8 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("8 key max 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("8 key max 5 R1 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key max 5 R1 [6]", -1, params.getColumnPos(5)); + assertEquals("8 key max 5 R1 [7]", -2, params.getColumnPos(6)); + assertEquals("8 key max 5 R1 [8]", -3, params.getColumnPos(7)); + assertEquals("8 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key max 5 R1 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [8] [7] [5] [6] ___| + // [4] [3] <1> [2] ___| + @Test + public void testLayout8KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(8, 5, XPOS_R2); + assertEquals("8 key max 5 R2 columns", 4, params.mNumColumns); + assertEquals("8 key max 5 R2 rows", 2, params.mNumRows); + assertEquals("8 key max 5 R2 left", 2, params.mLeftKeys); + assertEquals("8 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("8 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("8 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("8 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("8 key max 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("8 key max 5 R2 [5]", 0, params.getColumnPos(4)); + assertEquals("8 key max 5 R2 [6]", 1, params.getColumnPos(5)); + assertEquals("8 key max 5 R2 [7]", -1, params.getColumnPos(6)); + assertEquals("8 key max 5 R2 [8]", -2, params.getColumnPos(7)); + assertEquals("8 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("8 key max 5 R2 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout9KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_M0); + assertEquals("9 key max 5 M0 columns", 5, params.mNumColumns); + assertEquals("9 key max 5 M0 rows", 2, params.mNumRows); + assertEquals("9 key max 5 M0 left", 2, params.mLeftKeys); + assertEquals("9 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("9 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("9 key max 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("9 key max 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key max 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key max 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key max 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("9 key max 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key max 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout9KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L0); + assertEquals("9 key max 5 L0 columns", 5, params.mNumColumns); + assertEquals("9 key max 5 L0 rows", 2, params.mNumRows); + assertEquals("9 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("9 key max 5 L0 right", 5, params.mRightKeys); + assertEquals("9 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key max 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key max 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key max 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key max 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key max 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key max 5 L0 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout9KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L1); + assertEquals("9 key max 5 L1 columns", 5, params.mNumColumns); + assertEquals("9 key max 5 L1 rows", 2, params.mNumRows); + assertEquals("9 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("9 key max 5 L1 right", 5, params.mRightKeys); + assertEquals("9 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("9 key max 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("9 key max 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("9 key max 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key max 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key max 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key max 5 L1 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key max 5 L1 adjust",0, params.mTopRowAdjustment); + assertEquals("9 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout9KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_L2); + assertEquals("9 key max 5 L2 columns", 5, params.mNumColumns); + assertEquals("9 key max 5 L2 rows", 2, params.mNumRows); + assertEquals("9 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("9 key max 5 L2 right", 4, params.mRightKeys); + assertEquals("9 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key max 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("9 key max 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("9 key max 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key max 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key max 5 L2 [8]", 2, params.getColumnPos(7)); + assertEquals("9 key max 5 L2 [9]", 3, params.getColumnPos(8)); + assertEquals("9 key max 5 L2 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [9] [8] [7] [6]| + // [5] [4] [3] [2] <1>| + @Test + public void testLayout9KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R0); + assertEquals("9 key max 5 R0 columns", 5, params.mNumColumns); + assertEquals("9 key max 5 R0 rows", 2, params.mNumRows); + assertEquals("9 key max 5 R0 left", 4, params.mLeftKeys); + assertEquals("9 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("9 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("9 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key max 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("9 key max 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("9 key max 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key max 5 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("9 key max 5 R0 [8]", -2, params.getColumnPos(7)); + assertEquals("9 key max 5 R0 [9]", -3, params.getColumnPos(8)); + assertEquals("9 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key max 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [9] [8] [7] [6] ___| + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout9KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R1); + assertEquals("9 key max 5 R1 columns", 5, params.mNumColumns); + assertEquals("9 key max 5 R1 rows", 2, params.mNumRows); + assertEquals("9 key max 5 R1 left", 4, params.mLeftKeys); + assertEquals("9 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("9 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("9 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("9 key max 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("9 key max 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("9 key max 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key max 5 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("9 key max 5 R1 [8]", -2, params.getColumnPos(7)); + assertEquals("9 key max 5 R1 [9]", -3, params.getColumnPos(8)); + assertEquals("9 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("9 key max 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [9] [8] [6] [7] ___| + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout9KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(9, 5, XPOS_R2); + assertEquals("9 key max 5 R2 columns", 5, params.mNumColumns); + assertEquals("9 key max 5 R2 rows", 2, params.mNumRows); + assertEquals("9 key max 5 R2 left", 3, params.mLeftKeys); + assertEquals("9 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("9 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("9 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("9 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("9 key max 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("9 key max 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("9 key max 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("9 key max 5 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("9 key max 5 R2 [8]", -1, params.getColumnPos(7)); + assertEquals("9 key max 5 R2 [9]", -2, params.getColumnPos(8)); + assertEquals("9 key max 5 R2 adjust", -1, params.mTopRowAdjustment); + assertEquals("9 key max 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout10KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_M0); + assertEquals("10 key max 5 M0 columns", 5, params.mNumColumns); + assertEquals("10 key max 5 M0 rows", 2, params.mNumRows); + assertEquals("10 key max 5 M0 left", 2, params.mLeftKeys); + assertEquals("10 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("10 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("10 key max 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("10 key max 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key max 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key max 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key max 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("10 key max 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("10 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key max 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // |[6] [7] [8] [9] [A] + // |<1> [2] [3] [4] [5] + @Test + public void testLayout10KeyMax5L0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L0); + assertEquals("10 key max 5 L0 columns", 5, params.mNumColumns); + assertEquals("10 key max 5 L0 rows", 2, params.mNumRows); + assertEquals("10 key max 5 L0 left", 0, params.mLeftKeys); + assertEquals("10 key max 5 L0 right", 5, params.mRightKeys); + assertEquals("10 key max 5 L0 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key max 5 L0 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key max 5 L0 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key max 5 L0 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key max 5 L0 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key max 5 L0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key max 5 L0 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key max 5 L0 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key max 5 L0 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key max 5 L0 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key max 5 L0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key max 5 L0 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [6] [7] [8] [9] [A] + // |___ <1> [2] [3] [4] [5] + @Test + public void testLayout10KeyMax5L1() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L1); + assertEquals("10 key max 5 L1 columns", 5, params.mNumColumns); + assertEquals("10 key max 5 L1 rows", 2, params.mNumRows); + assertEquals("10 key max 5 L1 left", 0, params.mLeftKeys); + assertEquals("10 key max 5 L1 right", 5, params.mRightKeys); + assertEquals("10 key max 5 L1 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key max 5 L1 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key max 5 L1 [3]", 2, params.getColumnPos(2)); + assertEquals("10 key max 5 L1 [4]", 3, params.getColumnPos(3)); + assertEquals("10 key max 5 L1 [5]", 4, params.getColumnPos(4)); + assertEquals("10 key max 5 L1 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key max 5 L1 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key max 5 L1 [8]", 2, params.getColumnPos(7)); + assertEquals("10 key max 5 L1 [9]", 3, params.getColumnPos(8)); + assertEquals("10 key max 5 L1 [A]", 4, params.getColumnPos(9)); + assertEquals("10 key max 5 L1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key max 5 L1 default", WIDTH * 0, params.getDefaultKeyCoordX()); + } + + // |___ [8] [6] [7] [9] [A] + // |___ [3] <1> [2] [4] [5] + @Test + public void testLayout10KeyMax5L2() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_L2); + assertEquals("10 key max 5 L2 columns", 5, params.mNumColumns); + assertEquals("10 key max 5 L2 rows", 2, params.mNumRows); + assertEquals("10 key max 5 L2 left", 1, params.mLeftKeys); + assertEquals("10 key max 5 L2 right", 4, params.mRightKeys); + assertEquals("10 key max 5 L2 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key max 5 L2 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key max 5 L2 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key max 5 L2 [4]", 2, params.getColumnPos(3)); + assertEquals("10 key max 5 L2 [5]", 3, params.getColumnPos(4)); + assertEquals("10 key max 5 L2 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key max 5 L2 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key max 5 L2 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key max 5 L2 [9]", 2, params.getColumnPos(8)); + assertEquals("10 key max 5 L2 [A]", 3, params.getColumnPos(9)); + assertEquals("10 key max 5 L2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key max 5 L2 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [7] [6]| + // [5] [4] [3] [2] <1>| + @Test + public void testLayout10KeyMax5R0() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R0); + assertEquals("10 key max 5 R0 columns", 5, params.mNumColumns); + assertEquals("10 key max 5 R0 rows", 2, params.mNumRows); + assertEquals("10 key max 5 R0 left", 4, params.mLeftKeys); + assertEquals("10 key max 5 R0 right", 1, params.mRightKeys); + assertEquals("10 key max 5 R0 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key max 5 R0 [2]", -1, params.getColumnPos(1)); + assertEquals("10 key max 5 R0 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key max 5 R0 [4]", -3, params.getColumnPos(3)); + assertEquals("10 key max 5 R0 [5]", -4, params.getColumnPos(4)); + assertEquals("10 key max 5 R0 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key max 5 R0 [7]", -1, params.getColumnPos(6)); + assertEquals("10 key max 5 R0 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key max 5 R0 [9]", -3, params.getColumnPos(8)); + assertEquals("10 key max 5 R0 [A]", -4, params.getColumnPos(9)); + assertEquals("10 key max 5 R0 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key max 5 R0 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [7] [6] ___| + // [5] [4] [3] [2] <1> ___| + @Test + public void testLayout10KeyMax5R1() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R1); + assertEquals("10 key max 5 R1 columns", 5, params.mNumColumns); + assertEquals("10 key max 5 R1 rows", 2, params.mNumRows); + assertEquals("10 key max 5 R1 left", 4, params.mLeftKeys); + assertEquals("10 key max 5 R1 right", 1, params.mRightKeys); + assertEquals("10 key max 5 R1 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key max 5 R1 [2]", -1, params.getColumnPos(1)); + assertEquals("10 key max 5 R1 [3]", -2, params.getColumnPos(2)); + assertEquals("10 key max 5 R1 [4]", -3, params.getColumnPos(3)); + assertEquals("10 key max 5 R1 [5]", -4, params.getColumnPos(4)); + assertEquals("10 key max 5 R1 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key max 5 R1 [7]", -1, params.getColumnPos(6)); + assertEquals("10 key max 5 R1 [8]", -2, params.getColumnPos(7)); + assertEquals("10 key max 5 R1 [9]", -3, params.getColumnPos(8)); + assertEquals("10 key max 5 R1 [A]", -4, params.getColumnPos(9)); + assertEquals("10 key max 5 R1 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key max 5 R1 default", WIDTH * 4, params.getDefaultKeyCoordX()); + } + + // [A] [9] [8] [6] [7] ___| + // [5] [4] [3] <1> [2] ___| + @Test + public void testLayout10KeyMax5R2() { + MoreKeysKeyboardParams params = createParams(10, 5, XPOS_R2); + assertEquals("10 key max 5 R2 columns", 5, params.mNumColumns); + assertEquals("10 key max 5 R2 rows", 2, params.mNumRows); + assertEquals("10 key max 5 R2 left", 3, params.mLeftKeys); + assertEquals("10 key max 5 R2 right", 2, params.mRightKeys); + assertEquals("10 key max 5 R2 <1>", 0, params.getColumnPos(0)); + assertEquals("10 key max 5 R2 [2]", 1, params.getColumnPos(1)); + assertEquals("10 key max 5 R2 [3]", -1, params.getColumnPos(2)); + assertEquals("10 key max 5 R2 [4]", -2, params.getColumnPos(3)); + assertEquals("10 key max 5 R2 [5]", -3, params.getColumnPos(4)); + assertEquals("10 key max 5 R2 [6]", 0, params.getColumnPos(5)); + assertEquals("10 key max 5 R2 [7]", 1, params.getColumnPos(6)); + assertEquals("10 key max 5 R2 [8]", -1, params.getColumnPos(7)); + assertEquals("10 key max 5 R2 [9]", -2, params.getColumnPos(8)); + assertEquals("10 key max 5 R2 [A]", -3, params.getColumnPos(9)); + assertEquals("10 key max 5 R2 adjust", 0, params.mTopRowAdjustment); + assertEquals("10 key max 5 R2 default", WIDTH * 3, params.getDefaultKeyCoordX()); + } + + // [9] [A] [B] + // [7] [5] [6] [8] + // [3] <1> [2] [4] + @Test + public void testLayout11KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(11, 5, XPOS_M0); + assertEquals("11 key max 5 M0 columns", 4, params.mNumColumns); + assertEquals("11 key max 5 M0 rows", 3, params.mNumRows); + assertEquals("11 key max 5 M0 left", 1, params.mLeftKeys); + assertEquals("11 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("11 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("11 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("11 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("11 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("11 key max 5 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("11 key max 5 M0 [6]", 1, params.getColumnPos(5)); + assertEquals("11 key max 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("11 key max 5 M0 [8]", 2, params.getColumnPos(7)); + assertEquals("11 key max 5 M0 [9]", 0, params.getColumnPos(8)); + assertEquals("11 key max 5 M0 [A]", 1, params.getColumnPos(9)); + assertEquals("11 key max 5 M0 [B]", 2, params.getColumnPos(10)); + assertEquals("11 key max 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("11 key max 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [B] [9] [A] [C] + // [7] [5] [6] [8] + // [3] <1> [2] [4] + @Test + public void testLayout12KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(12, 5, XPOS_M0); + assertEquals("12 key max 5 M0 columns", 4, params.mNumColumns); + assertEquals("12 key max 5 M0 rows", 3, params.mNumRows); + assertEquals("12 key max 5 M0 left", 1, params.mLeftKeys); + assertEquals("12 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("12 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("12 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("12 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("12 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("12 key max 5 M0 [5]", 0, params.getColumnPos(4)); + assertEquals("12 key max 5 M0 [6]", 1, params.getColumnPos(5)); + assertEquals("12 key max 5 M0 [7]", -1, params.getColumnPos(6)); + assertEquals("12 key max 5 M0 [8]", 2, params.getColumnPos(7)); + assertEquals("12 key max 5 M0 [9]", 0, params.getColumnPos(8)); + assertEquals("12 key max 5 M0 [A]", 1, params.getColumnPos(9)); + assertEquals("12 key max 5 M0 [B]", -1, params.getColumnPos(10)); + assertEquals("12 key max 5 M0 [C]", 2, params.getColumnPos(11)); + assertEquals("12 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("12 key max 5 M0 default", WIDTH * 1, params.getDefaultKeyCoordX()); + } + + // [D] [B] [C] + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout13KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(13, 5, XPOS_M0); + assertEquals("13 key max 5 M0 columns", 5, params.mNumColumns); + assertEquals("13 key max 5 M0 rows", 3, params.mNumRows); + assertEquals("13 key max 5 M0 left", 2, params.mLeftKeys); + assertEquals("13 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("13 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("13 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("13 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("13 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("13 key max 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("13 key max 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("13 key max 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("13 key max 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("13 key max 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("13 key max 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("13 key max 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("13 key max 5 M0 [C]", 1, params.getColumnPos(11)); + assertEquals("13 key max 5 M0 [D]", -1, params.getColumnPos(12)); + assertEquals("13 key max 5 M0 adjust", 0, params.mTopRowAdjustment); + assertEquals("13 key max 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } + + // [D] [B] [C] [E] + // [A] [8] [6] [7] [9] + // [5] [3] <1> [2] [4] + @Test + public void testLayout14KeyMax5M0() { + MoreKeysKeyboardParams params = createParams(14, 5, XPOS_M0); + assertEquals("13 key max 5 M0 columns", 5, params.mNumColumns); + assertEquals("13 key max 5 M0 rows", 3, params.mNumRows); + assertEquals("13 key max 5 M0 left", 2, params.mLeftKeys); + assertEquals("13 key max 5 M0 right", 3, params.mRightKeys); + assertEquals("13 key max 5 M0 <1>", 0, params.getColumnPos(0)); + assertEquals("13 key max 5 M0 [2]", 1, params.getColumnPos(1)); + assertEquals("13 key max 5 M0 [3]", -1, params.getColumnPos(2)); + assertEquals("13 key max 5 M0 [4]", 2, params.getColumnPos(3)); + assertEquals("13 key max 5 M0 [5]", -2, params.getColumnPos(4)); + assertEquals("13 key max 5 M0 [6]", 0, params.getColumnPos(5)); + assertEquals("13 key max 5 M0 [7]", 1, params.getColumnPos(6)); + assertEquals("13 key max 5 M0 [8]", -1, params.getColumnPos(7)); + assertEquals("13 key max 5 M0 [9]", 2, params.getColumnPos(8)); + assertEquals("13 key max 5 M0 [A]", -2, params.getColumnPos(9)); + assertEquals("13 key max 5 M0 [B]", 0, params.getColumnPos(10)); + assertEquals("13 key max 5 M0 [C]", 1, params.getColumnPos(11)); + assertEquals("13 key max 5 M0 [D]", -1, params.getColumnPos(12)); + assertEquals("13 key max 5 M0 [E]", 2, params.getColumnPos(13)); + assertEquals("13 key max 5 M0 adjust", -1, params.mTopRowAdjustment); + assertEquals("13 key max 5 M0 default", WIDTH * 2, params.getDefaultKeyCoordX()); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/ActionTestsBase.java b/tests/src/org/kelar/inputmethod/keyboard/action/ActionTestsBase.java new file mode 100644 index 000000000..77ec4cee3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/ActionTestsBase.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.content.Context; +import android.content.res.Resources; +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import org.kelar.inputmethod.keyboard.Key; +import org.kelar.inputmethod.keyboard.Keyboard; +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.KeyboardLayoutSetTestsBase; +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyVisual; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.common.LocaleUtils; +import org.kelar.inputmethod.latin.utils.RunInLocale; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Locale; + +abstract class ActionTestsBase extends KeyboardLayoutSetTestsBase { + static class ExpectedActionKey { + static ExpectedActionKey newIconKey(final String iconName) { + final int iconId = KeyboardIconsSet.getIconId(iconName); + return new ExpectedActionKey(ExpectedKeyVisual.newInstance(iconId)); + } + + static ExpectedActionKey newLabelKey(final String label) { + return new ExpectedActionKey(ExpectedKeyVisual.newInstance(label)); + } + + static ExpectedActionKey newLabelKey(final int labelResId, + final Locale labelLocale, final Context context) { + final RunInLocale<String> getString = new RunInLocale<String>() { + @Override + protected String job(final Resources res) { + return res.getString(labelResId); + } + }; + return newLabelKey(getString.runInLocale(context.getResources(), labelLocale)); + } + + private final ExpectedKeyVisual mVisual; + + private ExpectedActionKey(final ExpectedKeyVisual visual) { + mVisual = visual; + } + + public int getIconId() { return mVisual.getIconId(); } + + public String getLabel() { return mVisual.getLabel(); } + } + + protected static Locale getLabelLocale(final InputMethodSubtype subtype) { + final String localeString = subtype.getLocale(); + if (localeString.equals(SubtypeLocaleUtils.NO_LANGUAGE)) { + return null; + } + return LocaleUtils.constructLocaleFromString(localeString); + } + + private static void assertActionKey(final String tag, final KeyboardLayoutSet layoutSet, + final int elementId, final ExpectedActionKey expectedKey) { + final Keyboard keyboard = layoutSet.getKeyboard(elementId); + final Key actualKey = keyboard.getKey(Constants.CODE_ENTER); + assertNotNull(tag + " enter key on " + keyboard.mId, actualKey); + assertEquals(tag + " label " + expectedKey, expectedKey.getLabel(), actualKey.getLabel()); + assertEquals(tag + " icon " + expectedKey, expectedKey.getIconId(), actualKey.getIconId()); + } + + protected void doTestActionKey(final String tag, final InputMethodSubtype subtype, + final int actionId, final ExpectedActionKey expectedKey) { + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = actionId; + doTestActionKey(tag, subtype, editorInfo, expectedKey); + } + + protected void doTestActionKey(final String tag, final InputMethodSubtype subtype, + final EditorInfo editorInfo, final ExpectedActionKey expectedKey) { + // Test text layouts. + editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; + final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, expectedKey); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, expectedKey); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, expectedKey); + // Test phone number layouts. + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, expectedKey); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, expectedKey); + // Test normal number layout. + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, expectedKey); + // Test number password layout. + editorInfo.inputType = + InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; + final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); + assertActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, expectedKey); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionCustomTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionCustomTests.java new file mode 100644 index 000000000..e8257cc9f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionCustomTests.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionCustomTests extends KlpActionTestsBase { + public void testActionCustom() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; + editorInfo.actionLabel = "customLabel"; + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel"); + doTestActionKey(tag, subtype, editorInfo, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionDoneTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionDoneTests.java new file mode 100644 index 000000000..557590041 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionDoneTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionDoneTests extends KlpActionTestsBase { + public void testActionDone() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_done_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionGoTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionGoTests.java new file mode 100644 index 000000000..f77a4d38f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionGoTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionGoTests extends KlpActionTestsBase { + public void testActionGo() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_go_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionLabelTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionLabelTests.java new file mode 100644 index 000000000..8297764c2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionLabelTests.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.content.res.Resources; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.MediumTest; + +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.keyboard.internal.KeyboardTextsSet; +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.RichInputMethodManager; +import org.kelar.inputmethod.latin.utils.RunInLocale; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Locale; + +@MediumTest +public class KlpActionLabelTests extends KlpActionTestsBase { + void doTestActionKeys(final InputMethodSubtype subtype, final String tag, + final ExpectedActionKey unspecifiedKey, final ExpectedActionKey noneKey, + final ExpectedActionKey goKey, final ExpectedActionKey searchKey, + final ExpectedActionKey sendKey, final ExpectedActionKey nextKey, + final ExpectedActionKey doneKey, final ExpectedActionKey previousKey) { + doTestActionKey( + tag + " unspecified", subtype, EditorInfo.IME_ACTION_UNSPECIFIED, unspecifiedKey); + doTestActionKey(tag + " none", subtype, EditorInfo.IME_ACTION_NONE, noneKey); + doTestActionKey(tag + " go", subtype, EditorInfo.IME_ACTION_GO, goKey); + doTestActionKey(tag + " search", subtype, EditorInfo.IME_ACTION_SEARCH, searchKey); + doTestActionKey(tag + " send", subtype, EditorInfo.IME_ACTION_SEND, sendKey); + doTestActionKey(tag + " next", subtype, EditorInfo.IME_ACTION_NEXT, nextKey); + doTestActionKey(tag + " done", subtype, EditorInfo.IME_ACTION_DONE, doneKey); + doTestActionKey(tag + " previous", subtype, EditorInfo.IME_ACTION_PREVIOUS, previousKey); + } + + // Working variable to simulate system locale changing. + private Locale mSystemLocale = Locale.getDefault(); + + private void doTestActionKeysInLocaleWithStringResources(final InputMethodSubtype subtype, + final Locale labelLocale, final Locale systemLocale) { + // Simulate system locale changing, see {@link SystemBroadcastReceiver}. + if (!systemLocale.equals(mSystemLocale)) { + KeyboardLayoutSet.onSystemLocaleChanged(); + mSystemLocale = systemLocale; + } + final ExpectedActionKey enterKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + final ExpectedActionKey goKey = ExpectedActionKey.newLabelKey( + R.string.label_go_key, labelLocale, getContext()); + final ExpectedActionKey searchKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + final ExpectedActionKey sendKey = ExpectedActionKey.newLabelKey( + R.string.label_send_key, labelLocale, getContext()); + final ExpectedActionKey nextKey = ExpectedActionKey.newLabelKey( + R.string.label_next_key, labelLocale, getContext()); + final ExpectedActionKey doneKey = ExpectedActionKey.newLabelKey( + R.string.label_done_key, labelLocale, getContext()); + final ExpectedActionKey previousKey = ExpectedActionKey.newLabelKey( + R.string.label_previous_key, labelLocale, getContext()); + final String tag = "label=" + labelLocale + " system=" + systemLocale + + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final RunInLocale<Void> job = new RunInLocale<Void>() { + @Override + public Void job(final Resources res) { + doTestActionKeys(subtype, tag, enterKey, enterKey, goKey, searchKey, sendKey, + nextKey, doneKey, previousKey); + return null; + } + }; + job.runInLocale(getContext().getResources(), systemLocale); + } + + public void testActionLabelInOtherLocale() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY); + // An action label should be displayed in subtype's locale regardless of the system locale. + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.US); + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.FRENCH); + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.ITALIAN); + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.JAPANESE); + } + + public void testNoLanguageSubtypeActionLabel() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY); + // An action label of no language keyboard should be displayed in the system locale. + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.US, Locale.US); + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.FRENCH, Locale.FRENCH); + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.ITALIAN, Locale.ITALIAN); + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.JAPANESE, Locale.JAPANESE); + } + + private void doTestActionKeysInLocaleWithKeyboardTextsSet(final InputMethodSubtype subtype, + final Locale labelLocale, final Locale systemLocale) { + // Simulate system locale changing, see {@link SystemBroadcastReceiver}. + if (!systemLocale.equals(mSystemLocale)) { + KeyboardLayoutSet.onSystemLocaleChanged(); + mSystemLocale = systemLocale; + } + final KeyboardTextsSet textsSet = new KeyboardTextsSet(); + textsSet.setLocale(labelLocale, getContext()); + final ExpectedActionKey enterKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + final ExpectedActionKey goKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_go_key")); + final ExpectedActionKey searchKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + final ExpectedActionKey sendKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_send_key")); + final ExpectedActionKey nextKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_next_key")); + final ExpectedActionKey doneKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_done_key")); + final ExpectedActionKey previousKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_previous_key")); + final String tag = "label=" + subtype.getLocale() + " system=" + systemLocale + + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final RunInLocale<Void> job = new RunInLocale<Void>() { + @Override + public Void job(final Resources res) { + doTestActionKeys(subtype, tag, enterKey, enterKey, goKey, searchKey, sendKey, + nextKey, doneKey, previousKey); + return null; + } + }; + job.runInLocale(getContext().getResources(), systemLocale); + } + + public void testHinglishActionLabel() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final Locale hi_ZZ = new Locale("hi", "ZZ"); + final InputMethodSubtype hiLatn = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + hi_ZZ.toString(), SubtypeLocaleUtils.QWERTY); + // This is a preliminary subtype and may not exist. + if (hiLatn == null) { + return; + } + // An action label should be displayed in subtype's locale regardless of the system locale. + doTestActionKeysInLocaleWithKeyboardTextsSet(hiLatn, hi_ZZ, new Locale("hi")); + doTestActionKeysInLocaleWithKeyboardTextsSet(hiLatn, hi_ZZ, Locale.US); + doTestActionKeysInLocaleWithKeyboardTextsSet(hiLatn, hi_ZZ, Locale.FRENCH); + doTestActionKeysInLocaleWithKeyboardTextsSet(hiLatn, hi_ZZ, Locale.ITALIAN); + doTestActionKeysInLocaleWithKeyboardTextsSet(hiLatn, hi_ZZ, Locale.JAPANESE); + } + + public void testSerbianLatinActionLabel() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final Locale sr_ZZ = new Locale("sr", "ZZ"); + final InputMethodSubtype srLatn = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + sr_ZZ.toString(), "serbian_qwertz"); + // This is a preliminary subtype and may not exist. + if (srLatn == null) { + return; + } + // An action label should be displayed in subtype's locale regardless of the system locale. + doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, new Locale("sr")); + doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.US); + doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.FRENCH); + doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.ITALIAN); + doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.JAPANESE); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionNextTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionNextTests.java new file mode 100644 index 000000000..47170f062 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionNextTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionNextTests extends KlpActionTestsBase { + public void testActionNext() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_next_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NEXT, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionNoneTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionNoneTests.java new file mode 100644 index 000000000..09178bea9 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionNoneTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionNoneTests extends KlpActionTestsBase { + public void testActionNone() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NONE, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionPreviousTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionPreviousTests.java new file mode 100644 index 000000000..d779b2838 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionPreviousTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionPreviousTests extends KlpActionTestsBase { + public void testActionPrevious() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_previous_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionSearchTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionSearchTests.java new file mode 100644 index 000000000..2a2b6ab44 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionSearchTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionSearchTests extends KlpActionTestsBase { + public void testActionSearch() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEARCH, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionSendTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionSendTests.java new file mode 100644 index 000000000..5a0c7de48 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionSendTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionSendTests extends KlpActionTestsBase { + public void testActionSend() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_send_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEND, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionTestsBase.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionTestsBase.java new file mode 100644 index 000000000..61156ebce --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionTestsBase.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.InputMethodSubtype; + +import org.kelar.inputmethod.keyboard.KeyboardTheme; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.ArrayList; +import java.util.Locale; + +abstract class KlpActionTestsBase extends ActionTestsBase { + // Filter a subtype whose name should be displayed using {@link Locale#ROOT}, such like + // Hinglish (hi_ZZ) and Serbian-Latn (sr_ZZ). + static final SubtypeFilter SUBTYPE_FILTER_NAME_IN_BASE_LOCALE = new SubtypeFilter() { + @Override + public boolean accept(final InputMethodSubtype subtype) { + return Locale.ROOT.equals( + SubtypeLocaleUtils.getDisplayLocaleOfSubtypeLocale(subtype.getLocale())); + } + }; + + protected ArrayList<InputMethodSubtype> mSubtypesWhoseNameIsDisplayedInItsLocale; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mSubtypesWhoseNameIsDisplayedInItsLocale = getSubtypesFilteredBy(new SubtypeFilter() { + @Override + public boolean accept(final InputMethodSubtype subtype) { + return !SUBTYPE_FILTER_NAME_IN_BASE_LOCALE.accept(subtype); + } + }); + } + + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionUnspecifiedTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionUnspecifiedTests.java new file mode 100644 index 000000000..11039bb29 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/KlpActionUnspecifiedTests.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionUnspecifiedTests extends KlpActionTestsBase { + public void testActionUnspecified() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "unspecifiled " + + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionCustomTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionCustomTests.java new file mode 100644 index 000000000..fd958b2c0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionCustomTests.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionCustomTests extends LxxActionTestsBase { + public void testActionCustom() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; + editorInfo.actionLabel = "customLabel"; + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel"); + doTestActionKey(tag, subtype, editorInfo, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionDoneTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionDoneTests.java new file mode 100644 index 000000000..d09a514a4 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionDoneTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionDoneTests extends LxxActionTestsBase { + public void testActionDone() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_DONE_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionGoTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionGoTests.java new file mode 100644 index 000000000..c000f2154 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionGoTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionGoTests extends LxxActionTestsBase { + public void testActionGo() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_GO_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionNextTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionNextTests.java new file mode 100644 index 000000000..576fcde84 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionNextTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionNextTests extends LxxActionTestsBase { + public void testActionNext() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_NEXT_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NEXT, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionNoneTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionNoneTests.java new file mode 100644 index 000000000..07b7d01e3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionNoneTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionNoneTests extends LxxActionTestsBase { + public void testActionNone() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NONE, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionPreviousTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionPreviousTests.java new file mode 100644 index 000000000..eb9ecd10a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionPreviousTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionPreviousTests extends LxxActionTestsBase { + public void testActionPrevious() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_PREVIOUS_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionSearchTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionSearchTests.java new file mode 100644 index 000000000..86b915ff8 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionSearchTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionSearchTests extends LxxActionTestsBase { + public void testActionSearch() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEARCH, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionSendTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionSendTests.java new file mode 100644 index 000000000..8c57243ea --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionSendTests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionSendTests extends LxxActionTestsBase { + public void testActionSend() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEND_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEND, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionTestsBase.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionTestsBase.java new file mode 100644 index 000000000..4e9fbcb4a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionTestsBase.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import org.kelar.inputmethod.keyboard.KeyboardTheme; + +abstract class LxxActionTestsBase extends ActionTestsBase { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_LXX_LIGHT; + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionUnspecifiedTests.java b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionUnspecifiedTests.java new file mode 100644 index 000000000..264e8951d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/action/LxxActionUnspecifiedTests.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.action; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionUnspecifiedTests extends LxxActionTestsBase { + public void testActionUnspecified() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "unspecifiled " + + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, expectedKey); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/HermiteInterpolatorTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/HermiteInterpolatorTests.java new file mode 100644 index 000000000..f23fb8d3f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/HermiteInterpolatorTests.java @@ -0,0 +1,202 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import static org.junit.Assert.assertEquals; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class HermiteInterpolatorTests { + private final HermiteInterpolator mInterpolator = new HermiteInterpolator(); + + private static final float EPSILON = 0.0000005f; + + // t=0 p0=(0,1) + // t=1 p1=(1,0) + // t=2 p2=(3,2) + // t=3 p3=(2,3) + // y + // | + // 3 + o p3 + // | + // 2 + o p2 + // | + // 1 o p0 + // | p1 + // 0 +---o---+---+-- x + // 0 1 2 3 + private final int[] mXCoords = { 0, 1, 3, 2 }; + private final int[] mYCoords = { 1, 0, 2, 3 }; + private static final int p0 = 0; + private static final int p1 = 1; + private static final int p2 = 2; + private static final int p3 = 3; + + @Test + public void testP0P1() { + // [(p0 p1) p2 p3] + mInterpolator.reset(mXCoords, mYCoords, p0, p3 + 1); + mInterpolator.setInterval(p0 - 1, p0, p1, p1 + 1); + assertEquals("p0x", mXCoords[p0], mInterpolator.mP1X); + assertEquals("p0y", mYCoords[p0], mInterpolator.mP1Y); + assertEquals("p1x", mXCoords[p1], mInterpolator.mP2X); + assertEquals("p1y", mYCoords[p1], mInterpolator.mP2Y); + // XY-slope at p0=3.0 (-0.75/-0.25) + assertEquals("slope x p0", -0.25f, mInterpolator.mSlope1X, EPSILON); + assertEquals("slope y p0", -0.75f, mInterpolator.mSlope1Y, EPSILON); + // XY-slope at p1=1/3.0 (0.50/1.50) + assertEquals("slope x p1", 1.50f, mInterpolator.mSlope2X, EPSILON); + assertEquals("slope y p1", 0.50f, mInterpolator.mSlope2Y, EPSILON); + // t=0.0 (p0) + mInterpolator.interpolate(0.0f); + assertEquals("t=0.0 x", 0.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.0 y", 1.0f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.2 + mInterpolator.interpolate(0.2f); + assertEquals("t=0.2 x", 0.02400f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.2 y", 0.78400f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.5 + mInterpolator.interpolate(0.5f); + assertEquals("t=0.5 x", 0.28125f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.5 y", 0.34375f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.8 + mInterpolator.interpolate(0.8f); + assertEquals("t=0.8 x", 0.69600f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.8 y", 0.01600f, mInterpolator.mInterpolatedY, EPSILON); + // t=1.0 (p1) + mInterpolator.interpolate(1.0f); + assertEquals("t=1.0 x", 1.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=1.0 y", 0.0f, mInterpolator.mInterpolatedY, EPSILON); + } + + @Test + public void testP1P2() { + // [p0 (p1 p2) p3] + mInterpolator.reset(mXCoords, mYCoords, p0, p3 + 1); + mInterpolator.setInterval(p1 - 1, p1, p2, p2 + 1); + assertEquals("p1x", mXCoords[p1], mInterpolator.mP1X); + assertEquals("p1y", mYCoords[p1], mInterpolator.mP1Y); + assertEquals("p2x", mXCoords[p2], mInterpolator.mP2X); + assertEquals("p2y", mYCoords[p2], mInterpolator.mP2Y); + // XY-slope at p1=1/3.0 (0.50/1.50) + assertEquals("slope x p1", 1.50f, mInterpolator.mSlope1X, EPSILON); + assertEquals("slope y p1", 0.50f, mInterpolator.mSlope1Y, EPSILON); + // XY-slope at p2=3.0 (1.50/0.50) + assertEquals("slope x p2", 0.50f, mInterpolator.mSlope2X, EPSILON); + assertEquals("slope y p2", 1.50f, mInterpolator.mSlope2Y, EPSILON); + // t=0.0 (p1) + mInterpolator.interpolate(0.0f); + assertEquals("t=0.0 x", 1.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.0 y", 0.0f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.2 + mInterpolator.interpolate(0.2f); + assertEquals("t=0.2 x", 1.384f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.2 y", 0.224f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.5 + mInterpolator.interpolate(0.5f); + assertEquals("t=0.5 x", 2.125f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.5 y", 0.875f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.8 + mInterpolator.interpolate(0.8f); + assertEquals("t=0.8 x", 2.776f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.8 y", 1.616f, mInterpolator.mInterpolatedY, EPSILON); + // t=1.0 (p2) + mInterpolator.interpolate(1.0f); + assertEquals("t=1.0 x", 3.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=1.0 y", 2.0f, mInterpolator.mInterpolatedY, EPSILON); + } + + @Test + public void testP2P3() { + // [p0 p1 (p2 p3)] + mInterpolator.reset(mXCoords, mYCoords, p0, p3 + 1); + mInterpolator.setInterval(p2 - 1, p2, p3, p3 + 1); + assertEquals("p2x", mXCoords[p2], mInterpolator.mP1X); + assertEquals("p2y", mYCoords[p2], mInterpolator.mP1Y); + assertEquals("p3x", mXCoords[p3], mInterpolator.mP2X); + assertEquals("p3y", mYCoords[p3], mInterpolator.mP2Y); + // XY-slope at p2=3.0 (1.50/0.50) + assertEquals("slope x p2", 0.50f, mInterpolator.mSlope1X, EPSILON); + assertEquals("slope y p2", 1.50f, mInterpolator.mSlope1Y, EPSILON); + // XY-slope at p3=1/3.0 (-0.25/-0.75) + assertEquals("slope x p3", -0.75f, mInterpolator.mSlope2X, EPSILON); + assertEquals("slope y p3", -0.25f, mInterpolator.mSlope2Y, EPSILON); + // t=0.0 (p2) + mInterpolator.interpolate(0.0f); + assertEquals("t=0.0 x", 3.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.0 y", 2.0f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.2 + mInterpolator.interpolate(0.2f); + assertEquals("t=0.2 x", 2.98400f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.2 y", 2.30400f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.5 + mInterpolator.interpolate(0.5f); + assertEquals("t=0.5 x", 2.65625f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.5 y", 2.71875f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.8 + mInterpolator.interpolate(0.8f); + assertEquals("t=0.8 x", 2.21600f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.8 y", 2.97600f, mInterpolator.mInterpolatedY, EPSILON); + // t=1.0 (p3) + mInterpolator.interpolate(1.0f); + assertEquals("t=1.0 x", 2.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=1.0 y", 3.0f, mInterpolator.mInterpolatedY, EPSILON); + } + + @Test + public void testJustP1P2() { + // [(p1 p2)] + mInterpolator.reset(mXCoords, mYCoords, p1, p2 + 1); + mInterpolator.setInterval(p1 - 1, p1, p2, p2 + 1); + assertEquals("p1x", mXCoords[p1], mInterpolator.mP1X); + assertEquals("p1y", mYCoords[p1], mInterpolator.mP1Y); + assertEquals("p2x", mXCoords[p2], mInterpolator.mP2X); + assertEquals("p2y", mYCoords[p2], mInterpolator.mP2Y); + // XY-slope at p1=1.0 (2.0/2.0) + assertEquals("slope x p1", 2.00f, mInterpolator.mSlope1X, EPSILON); + assertEquals("slope y p1", 2.00f, mInterpolator.mSlope1Y, EPSILON); + // XY-slope at p2=1.0 (2.0/2.0) + assertEquals("slope x p2", 2.00f, mInterpolator.mSlope2X, EPSILON); + assertEquals("slope y p2", 2.00f, mInterpolator.mSlope2Y, EPSILON); + // t=0.0 (p1) + mInterpolator.interpolate(0.0f); + assertEquals("t=0.0 x", 1.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.0 y", 0.0f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.2 + mInterpolator.interpolate(0.2f); + assertEquals("t=0.2 x", 1.4f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.2 y", 0.4f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.5 + mInterpolator.interpolate(0.5f); + assertEquals("t=0.5 x", 2.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.5 y", 1.0f, mInterpolator.mInterpolatedY, EPSILON); + // t=0.8 + mInterpolator.interpolate(0.8f); + assertEquals("t=0.8 x", 2.6f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=0.8 y", 1.6f, mInterpolator.mInterpolatedY, EPSILON); + // t=1.0 (p2) + mInterpolator.interpolate(1.0f); + assertEquals("t=1.0 x", 3.0f, mInterpolator.mInterpolatedX, EPSILON); + assertEquals("t=1.0 y", 2.0f, mInterpolator.mInterpolatedY, EPSILON); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/KeySpecParserTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/KeySpecParserTests.java new file mode 100644 index 000000000..1d3ceaf63 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/KeySpecParserTests.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.internal; + +import static org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UNDEFINED; +import static org.kelar.inputmethod.latin.common.Constants.CODE_UNSPECIFIED; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.latin.common.Constants; + +@SmallTest +public final class KeySpecParserTests extends KeySpecParserTestsBase { + @Override + protected void assertParser(final String message, final String keySpec, + final String expectedLabel, final String expectedOutputText, final int expectedIcon, + final int expectedCode) { + final String keySpecResolved = mTextsSet.resolveTextReference(keySpec); + final String actualLabel = KeySpecParser.getLabel(keySpecResolved); + final String actualOutputText = KeySpecParser.getOutputText(keySpecResolved); + final int actualIcon = KeySpecParser.getIconId(keySpecResolved); + final int actualCode = KeySpecParser.getCode(keySpecResolved); + assertEquals(message + " [label]", expectedLabel, actualLabel); + assertEquals(message + " [ouptputText]", expectedOutputText, actualOutputText); + assertEquals(message + " [icon]", + KeyboardIconsSet.getIconName(expectedIcon), + KeyboardIconsSet.getIconName(actualIcon)); + assertEquals(message + " [code]", + Constants.printableCode(expectedCode), + Constants.printableCode(actualCode)); + } + + // TODO: Remove this method. + // These should throw {@link KeySpecParserError} when Key.keyLabel attribute become mandatory. + public void testEmptySpec() { + assertParser("Null spec", null, + null, null, ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParser("Empty spec", "", + null, null, ICON_UNDEFINED, CODE_UNSPECIFIED); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/KeySpecParserTestsBase.java b/tests/src/org/kelar/inputmethod/keyboard/internal/KeySpecParserTestsBase.java new file mode 100644 index 000000000..8bf344c92 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/KeySpecParserTestsBase.java @@ -0,0 +1,340 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.internal; + +import static org.kelar.inputmethod.keyboard.internal.KeyboardCodesSet.PREFIX_CODE; +import static org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UNDEFINED; +import static org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet.PREFIX_ICON; +import static org.kelar.inputmethod.latin.common.Constants.CODE_OUTPUT_TEXT; +import static org.kelar.inputmethod.latin.common.Constants.CODE_UNSPECIFIED; + +import android.test.AndroidTestCase; + +import java.util.Locale; + +abstract class KeySpecParserTestsBase extends AndroidTestCase { + private final static Locale TEST_LOCALE = Locale.ENGLISH; + protected final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); + + private static final String CODE_SETTINGS_NAME = "key_settings"; + private static final String CODE_SETTINGS = PREFIX_CODE + CODE_SETTINGS_NAME; + private static final String ICON_SETTINGS_NAME = "settings_key"; + private static final String ICON_SETTINGS = PREFIX_ICON + ICON_SETTINGS_NAME; + private static final String CODE_SETTINGS_UPPERCASE = CODE_SETTINGS.toUpperCase(Locale.ROOT); + private static final String ICON_SETTINGS_UPPERCASE = ICON_SETTINGS.toUpperCase(Locale.ROOT); + private static final String CODE_NON_EXISTING = PREFIX_CODE + "non_existing"; + private static final String ICON_NON_EXISTING = PREFIX_ICON + "non_existing"; + + private int mCodeSettings; + private int mCodeActionNext; + private int mSettingsIconId; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mTextsSet.setLocale(TEST_LOCALE, getContext()); + mCodeSettings = KeyboardCodesSet.getCode(CODE_SETTINGS_NAME); + mCodeActionNext = KeyboardCodesSet.getCode("key_action_next"); + mSettingsIconId = KeyboardIconsSet.getIconId(ICON_SETTINGS_NAME); + } + + abstract protected void assertParser(final String message, final String keySpec, + final String expectedLabel, final String expectedOutputText, final int expectedIcon, + final int expectedCode); + + protected void assertParserError(final String message, final String keySpec, + final String expectedLabel, final String expectedOutputText, final int expectedIconId, + final int expectedCode) { + try { + assertParser(message, keySpec, expectedLabel, expectedOutputText, expectedIconId, + expectedCode); + fail(message); + } catch (Exception pcpe) { + // success. + } + } + + // \U001d11e: MUSICAL SYMBOL G CLEF + private static final String SURROGATE_PAIR1 = "\ud834\udd1e"; + private static final int SURROGATE_CODE1 = SURROGATE_PAIR1.codePointAt(0); + // \U001d122: MUSICAL SYMBOL F CLEF + private static final String SURROGATE_PAIR2 = "\ud834\udd22"; + private static final int SURROGATE_CODE2 = SURROGATE_PAIR2.codePointAt(0); + // \U002f8a6: CJK COMPATIBILITY IDEOGRAPH-2F8A6; variant character of \u6148. + private static final String SURROGATE_PAIR3 = "\ud87e\udca6"; + private static final String SURROGATE_PAIRS4 = SURROGATE_PAIR1 + SURROGATE_PAIR2; + private static final String SURROGATE_PAIRS5 = SURROGATE_PAIRS4 + SURROGATE_PAIR3; + + public void testSingleLetter() { + assertParser("Single letter", "a", + "a", null, ICON_UNDEFINED, 'a'); + assertParser("Single surrogate", SURROGATE_PAIR1, + SURROGATE_PAIR1, null, ICON_UNDEFINED, SURROGATE_CODE1); + assertParser("Sole vertical bar", "|", + "|", null, ICON_UNDEFINED, '|'); + assertParser("Single escaped vertical bar", "\\|", + "|", null, ICON_UNDEFINED, '|'); + assertParser("Single escaped escape", "\\\\", + "\\", null, ICON_UNDEFINED, '\\'); + assertParser("Single comma", ",", + ",", null, ICON_UNDEFINED, ','); + assertParser("Single escaped comma", "\\,", + ",", null, ICON_UNDEFINED, ','); + assertParser("Single escaped letter", "\\a", + "a", null, ICON_UNDEFINED, 'a'); + assertParser("Single escaped surrogate", "\\" + SURROGATE_PAIR2, + SURROGATE_PAIR2, null, ICON_UNDEFINED, SURROGATE_CODE2); + assertParser("Single bang", "!", + "!", null, ICON_UNDEFINED, '!'); + assertParser("Single escaped bang", "\\!", + "!", null, ICON_UNDEFINED, '!'); + assertParser("Single output text letter", "a|a", + "a", null, ICON_UNDEFINED, 'a'); + assertParser("Single surrogate pair outputText", "G Clef|" + SURROGATE_PAIR1, + "G Clef", null, ICON_UNDEFINED, SURROGATE_CODE1); + assertParser("Single letter with outputText", "a|abc", + "a", "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with surrogate outputText", "a|" + SURROGATE_PAIRS4, + "a", SURROGATE_PAIRS4, ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single surrogate with outputText", SURROGATE_PAIR3 + "|abc", + SURROGATE_PAIR3, "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with escaped outputText", "a|a\\|c", + "a", "a|c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with escaped surrogate outputText", + "a|" + SURROGATE_PAIR1 + "\\|" + SURROGATE_PAIR2, + "a", SURROGATE_PAIR1 + "|" + SURROGATE_PAIR2, ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with comma outputText", "a|a,b", + "a", "a,b", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with escaped comma outputText", "a|a\\,b", + "a", "a,b", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with outputText starts with bang", "a|!bc", + "a", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with surrogate outputText starts with bang", + "a|!" + SURROGATE_PAIRS5, + "a", "!" + SURROGATE_PAIRS5, ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with outputText contains bang", "a|a!c", + "a", "a!c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single letter with escaped bang outputText", "a|\\!bc", + "a", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Single escaped escape with single outputText", "\\\\|\\\\", + "\\", null, ICON_UNDEFINED, '\\'); + assertParser("Single escaped bar with single outputText", "\\||\\|", + "|", null, ICON_UNDEFINED, '|'); + assertParser("Single letter with code", "a|" + CODE_SETTINGS, + "a", null, ICON_UNDEFINED, mCodeSettings); + } + + public void testLabel() { + assertParser("Simple label", "abc", + "abc", "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Simple surrogate label", SURROGATE_PAIRS4, + SURROGATE_PAIRS4, SURROGATE_PAIRS4, ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped bar", "a\\|c", + "a|c", "a|c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Surrogate label with escaped bar", SURROGATE_PAIR1 + "\\|" + SURROGATE_PAIR2, + SURROGATE_PAIR1 + "|" + SURROGATE_PAIR2, SURROGATE_PAIR1 + "|" + SURROGATE_PAIR2, + ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped escape", "a\\\\c", + "a\\c", "a\\c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with comma", "a,c", + "a,c", "a,c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped comma", "a\\,c", + "a,c", "a,c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label starts with bang", "!bc", + "!bc", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Surrogate label starts with bang", "!" + SURROGATE_PAIRS4, + "!" + SURROGATE_PAIRS4, "!" + SURROGATE_PAIRS4, ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label contains bang", "a!c", + "a!c", "a!c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped bang", "\\!bc", + "!bc", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped letter", "\\abc", + "abc", "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with outputText", "abc|def", + "abc", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with comma and outputText", "a,c|def", + "a,c", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped comma label with outputText", "a\\,c|def", + "a,c", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped label with outputText", "a\\|c|def", + "a|c", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped bar outputText", "abc|d\\|f", + "abc", "d|f", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped escape label with outputText", "a\\\\|def", + "a\\", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label starts with bang and outputText", "!bc|def", + "!bc", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label contains bang label and outputText", "a!c|def", + "a!c", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped bang label with outputText", "\\!bc|def", + "!bc", "def", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with comma outputText", "abc|a,b", + "abc", "a,b", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped comma outputText", "abc|a\\,b", + "abc", "a,b", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with outputText starts with bang", "abc|!bc", + "abc", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with outputText contains bang", "abc|a!c", + "abc", "a!c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped bang outputText", "abc|\\!bc", + "abc", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with escaped bar outputText", "abc|d\\|f", + "abc", "d|f", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", + "a|c", "d|f", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with code", "abc|" + CODE_SETTINGS, + "abc", null, ICON_UNDEFINED, mCodeSettings); + assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS, + "a|c", null, ICON_UNDEFINED, mCodeSettings); + } + + public void testCodes() { + assertParser("Hexadecimal code", "a|0x1000", + "a", null, ICON_UNDEFINED, 0x1000); + assertParserError("Illegal hexadecimal code", "a|0x100X", + "a", null, ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParser("Escaped hexadecimal code 1", "a|\\0x1000", + "a", "0x1000", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped hexadecimal code 2", "a|0\\x1000", + "a", "0x1000", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped hexadecimal code 2", "a|0\\x1000", + "a", "0x1000", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParserError("Illegally escaped hexadecimal code", "a|0x1\\000", + "a", null, ICON_UNDEFINED, CODE_UNSPECIFIED); + // This is a workaround to have a key that has a supplementary code point. We can't put a + // string in resource as a XML entity of a supplementary code point or a surrogate pair. + // TODO: Should pass this test. +// assertParser("Hexadecimal supplementary code", String.format("a|0x%06x", SURROGATE_CODE2), +// SURROGATE_PAIR2, null, ICON_UNDEFINED, SURROGATE_CODE2); + assertParser("Zero is treated as output text", "a|0", + "a", null, ICON_UNDEFINED, '0'); + assertParser("Digit is treated as output text", "a|3", + "a", null, ICON_UNDEFINED, '3'); + assertParser("Decimal number is treated as an output text", "a|2014", + "a", "2014", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + } + + public void testIcons() { + assertParser("Icon with single letter", ICON_SETTINGS + "|a", + null, null, mSettingsIconId, 'a'); + assertParser("Icon with outputText", ICON_SETTINGS + "|abc", + null, "abc", mSettingsIconId, CODE_OUTPUT_TEXT); + assertParser("Icon with outputText starts with bang", ICON_SETTINGS + "|!bc", + null, "!bc", mSettingsIconId, CODE_OUTPUT_TEXT); + assertParser("Icon with outputText contains bang", ICON_SETTINGS + "|a!c", + null, "a!c", mSettingsIconId, CODE_OUTPUT_TEXT); + assertParser("Icon with escaped bang outputText", ICON_SETTINGS + "|\\!bc", + null, "!bc", mSettingsIconId, CODE_OUTPUT_TEXT); + assertParser("Label starts with bang and code", "!bc|" + CODE_SETTINGS, + "!bc", null, ICON_UNDEFINED, mCodeSettings); + assertParser("Label contains bang and code", "a!c|" + CODE_SETTINGS, + "a!c", null, ICON_UNDEFINED, mCodeSettings); + assertParser("Escaped bang label with code", "\\!bc|" + CODE_SETTINGS, + "!bc", null, ICON_UNDEFINED, mCodeSettings); + assertParser("Icon with code", ICON_SETTINGS + "|" + CODE_SETTINGS, + null, null, mSettingsIconId, mCodeSettings); + } + + public void testResourceReference() { + assertParser("Settings as more key", "!text/keyspec_settings", + null, null, mSettingsIconId, mCodeSettings); + + assertParser("Action next as more key", "!text/label_next_key|!code/key_action_next", + "Next", null, ICON_UNDEFINED, mCodeActionNext); + + assertParser("Popular domain", + "!text/keyspec_popular_domain|!text/keyspec_popular_domain ", + ".com", ".com ", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + } + + public void testFormatError() { + assertParserError("Empty label with outputText", "|a", + null, "a", ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParserError("Empty label with code", "|" + CODE_SETTINGS, + null, null, ICON_UNDEFINED, mCodeSettings); + assertParserError("Empty outputText with label", "a|", + "a", null, ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParserError("Empty outputText with icon", ICON_SETTINGS + "|", + null, null, mSettingsIconId, CODE_UNSPECIFIED); + assertParserError("Icon without code", ICON_SETTINGS, + null, null, mSettingsIconId, CODE_UNSPECIFIED); + assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc", + null, "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, + "abc", null, ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParserError("Third bar at end", "a|b|", + "a", null, ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParserError("Multiple bar", "a|b|c", + "a", null, ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParserError("Multiple bar with label and code", "a|" + CODE_SETTINGS + "|c", + "a", null, ICON_UNDEFINED, mCodeSettings); + assertParserError("Multiple bar with icon and outputText", ICON_SETTINGS + "|b|c", + null, null, mSettingsIconId, CODE_UNSPECIFIED); + assertParserError("Multiple bar with icon and code", + ICON_SETTINGS + "|" + CODE_SETTINGS + "|c", + null, null, mSettingsIconId, mCodeSettings); + } + + public void testUselessUpperCaseSpecifier() { + assertParser("Single letter with CODE", "a|" + CODE_SETTINGS_UPPERCASE, + "a", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label with CODE", "abc|" + CODE_SETTINGS_UPPERCASE, + "abc", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped label with CODE", "a\\|c|" + CODE_SETTINGS_UPPERCASE, + "a|c", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("ICON with outputText", ICON_SETTINGS_UPPERCASE + "|abc", + "!ICON/SETTINGS_KEY", "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("ICON with outputText starts with bang", ICON_SETTINGS_UPPERCASE + "|!bc", + "!ICON/SETTINGS_KEY", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("ICON with outputText contains bang", ICON_SETTINGS_UPPERCASE + "|a!c", + "!ICON/SETTINGS_KEY", "a!c", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("ICON with escaped bang outputText", ICON_SETTINGS_UPPERCASE + "|\\!bc", + "!ICON/SETTINGS_KEY", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label starts with bang and CODE", "!bc|" + CODE_SETTINGS_UPPERCASE, + "!bc", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Label contains bang and CODE", "a!c|" + CODE_SETTINGS_UPPERCASE, + "a!c", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("Escaped bang label with CODE", "\\!bc|" + CODE_SETTINGS_UPPERCASE, + "!bc", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("ICON with CODE", ICON_SETTINGS_UPPERCASE + "|" + CODE_SETTINGS_UPPERCASE, + "!ICON/SETTINGS_KEY", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParser("SETTINGS AS MORE KEY", "!TEXT/SETTINGS_AS_MORE_KEY", + "!TEXT/SETTINGS_AS_MORE_KEY", "!TEXT/SETTINGS_AS_MORE_KEY", ICON_UNDEFINED, + CODE_OUTPUT_TEXT); + assertParser("ACTION NEXT AS MORE KEY", "!TEXT/LABEL_NEXT_KEY|!CODE/KEY_ACTION_NEXT", + "!TEXT/LABEL_NEXT_KEY", "!CODE/KEY_ACTION_NEXT", ICON_UNDEFINED, + CODE_OUTPUT_TEXT); + assertParser("POPULAR DOMAIN", + "!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN|!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN ", + "!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN", "!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN ", + ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParserError("Empty label with CODE", "|" + CODE_SETTINGS_UPPERCASE, + null, null, ICON_UNDEFINED, mCodeSettings); + assertParserError("Empty outputText with ICON", ICON_SETTINGS_UPPERCASE + "|", + null, null, mSettingsIconId, CODE_UNSPECIFIED); + assertParser("ICON without code", ICON_SETTINGS_UPPERCASE, + "!ICON/SETTINGS_KEY", "!ICON/SETTINGS_KEY", ICON_UNDEFINED, CODE_OUTPUT_TEXT); + assertParserError("Multiple bar with label and CODE", "a|" + CODE_SETTINGS_UPPERCASE + "|c", + "a", null, ICON_UNDEFINED, mCodeSettings); + assertParserError("Multiple bar with ICON and outputText", ICON_SETTINGS_UPPERCASE + "|b|c", + null, null, mSettingsIconId, CODE_UNSPECIFIED); + assertParserError("Multiple bar with ICON and CODE", + ICON_SETTINGS_UPPERCASE + "|" + CODE_SETTINGS_UPPERCASE + "|c", + null, null, mSettingsIconId, mCodeSettings); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java new file mode 100644 index 000000000..202718bbb --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java @@ -0,0 +1,476 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import androidx.test.filters.SmallTest; + +@SmallTest +public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase { + // Chording input in alphabet. + public void testChordingAlphabet() { + // Press shift key and hold, enter into choring shift state. + pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press/release letter key. + chordingPressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Release shift key, switch back to alphabet. + releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); + + // Press "?123" key and hold, enter into choring symbols state. + pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED); + // Press/release symbol letter key. + chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Release "ABC" key, switch back to alphabet. + releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED); + } + + // Chording input in shifted. + public void testChordingShifted() { + // Press shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + + // Press shift key and hold, enter into choring shift state. + pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press/release letter key. + chordingPressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Release shift key, switch back to alphabet shifted. + releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + + // Press "?123" key and hold, enter into choring symbols state. + pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED); + // Press/release symbol letter key. + chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Release "123?" key, switch back to alphabet unshifted. + releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED); + } + + // Chording input in shift locked. + public void testChordingShiftLocked() { + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + + // Press shift key and hold, enter into choring shift state. + pressKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED); + // Press/release letter key. + chordingPressAndReleaseKey('Z', ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED); + // Release shift key, switch back to alphabet shift locked. + releaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCKED); + + // Press "?123" key and hold, enter into choring symbols state. + pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED); + // Press/release symbol letter key. + chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Release "123?" key, switch back to alphabet shift locked. + releaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED); + } + + // Chording input in symbols. + public void testChordingSymbols() { + // Press/release "?123" key, enter symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + + // Press "=\<" key and hold, enter into choring symbols shifted state. + pressKey(CODE_SHIFT, SYMBOLS_SHIFTED); + // Press/release symbol letter key. + chordingPressAndReleaseKey('1', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Release "=\<" key, switch back to symbols. + releaseKey(CODE_SHIFT, SYMBOLS_UNSHIFTED); + + // Press "ABC" key and hold, enter into choring alphabet state. + pressKey(CODE_SYMBOL, ALPHABET_UNSHIFTED); + // Press/release letter key. + chordingPressAndReleaseKey('a', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Release "ABC" key, switch back to symbols. + releaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED); + + // Alphabet shifted -> symbols -> "ABC" key + letter -> symbols + // -> alphabet. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press "ABC" key, enter into chording alphabet state. + pressKey(CODE_SYMBOL, ALPHABET_UNSHIFTED); + // Enter/release letter key. + chordingPressAndReleaseKey('a', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Release "ABC" key, switch back to symbols. + releaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> symbols -> "ABC" key + letter -> symbols -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press "ABC" key, enter into chording alphabet shift locked. + pressKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED); + // Enter/release letter key. + chordingPressAndReleaseKey('A', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Release "ABC" key, switch back to symbols. + releaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols -> "=\<" key + letter -> symbols -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press "=\<" key, enter into symbols shifted chording state. + pressKey(CODE_SHIFT, SYMBOLS_SHIFTED); + // Enter/release symbols shift letter key. + chordingPressAndReleaseKey('~', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Release "=\<" key, switch back to symbols. + releaseKey(CODE_SHIFT, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + } + + // Chording input in symbol shifted. + public void testChordingSymbolsShifted() { + // Press/release "?123" key, enter symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + + // Press "?123" key and hold, enter into chording symbols state. + pressKey(CODE_SHIFT, SYMBOLS_UNSHIFTED); + // Press/release symbol letter key. + chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Release "=\<" key, switch back to symbols shifted state. + releaseKey(CODE_SHIFT, SYMBOLS_SHIFTED); + + // Press "ABC" key and hold, enter into choring alphabet state. + pressKey(CODE_SYMBOL, ALPHABET_UNSHIFTED); + // Press/release letter key. + chordingPressAndReleaseKey('a', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Release "ABC" key, switch back to symbols. + releaseKey(CODE_SYMBOL, SYMBOLS_SHIFTED); + + // Alphabet shifted -> symbols shifted -> "ABC" key + letter -> symbols shifted -> + // alphabet. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press "ABC" key, enter into chording alphabet state. + pressKey(CODE_SYMBOL, ALPHABET_UNSHIFTED); + // Enter/release letter key. + chordingPressAndReleaseKey('a', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Release "ABC" key, switch back to symbols shifted. + releaseKey(CODE_SYMBOL, SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> symbols shifted -> "ABC" key + letter -> symbols shifted + // -> alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press "ABC" key, enter into chording alphabet shift locked. + pressKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED); + // Enter/release letter key. + chordingPressAndReleaseKey('A', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Release "ABC" key, switch back to symbols shifted. + releaseKey(CODE_SYMBOL, SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols shifted -> "=\<" key + letter -> symbols shifted + // -> alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press "=\<" key, enter into symbols chording state. + pressKey(CODE_SHIFT, SYMBOLS_UNSHIFTED); + // Enter/release symbols letter key. + chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Release "=\<" key, switch back to symbols shifted. + releaseKey(CODE_SHIFT, SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + } + + // Chording input in automatic upper case. + public void testChordingAutomaticUpperCase() { + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + + // Update shift state with auto caps enabled. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + // Press shift key and hold, enter into chording shift state. + pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press/release letter key. + chordingPressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Release shift key, switch back to alphabet. + releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); + + // Update shift state with auto caps enabled. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + // Press "123?" key and hold, enter into chording symbols state. + pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED); + // Press/release symbol letter key. + chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Release "123?" key, switch back to alphabet. + releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED); + } + + // Chording letter key with shift key. + public void testChordingLetterAndShiftKey() { + // Press letter key and hold. + pressKey('z', ALPHABET_UNSHIFTED); + // Press shift key, {@link PointerTracker} will fire a phantom release letter key. + chordingReleaseKey('z', ALPHABET_UNSHIFTED); + chordingPressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press another letter key and hold. + chordingPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Release shift key + releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); + } + + // Multi touch input in manual shifted. + public void testMultiTouchManualShifted() { + // Press/release shift key, enter into alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + + // Press 'X' key and hold + pressKey('X', ALPHABET_MANUAL_SHIFTED); + // Press 'z' key and hold, switch back to alphabet unshifted. + chordingPressKey('z', ALPHABET_UNSHIFTED); + // Release 'X' key + releaseKey('X', ALPHABET_UNSHIFTED); + // Release 'z' key + releaseKey('z', ALPHABET_UNSHIFTED); + } + + // Multi touch input in automatic upper case. + public void testMultiTouchAutomaticUpperCase() { + // Set auto word caps mode on. + setAutoCapsMode(CAP_MODE_WORDS); + // Update shift state with auto caps enabled. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press 'X' key and hold + pressKey('X', ALPHABET_AUTOMATIC_SHIFTED); + // Press 'z' key and hold, switch back to alphabet unshifted. + chordingPressKey('z', ALPHABET_UNSHIFTED); + // Release 'X' key + releaseKey('X', ALPHABET_UNSHIFTED); + // Release 'z' key + releaseKey('z', ALPHABET_UNSHIFTED); + } + + // Multi touch input in capitalize character mode. + public void testMultiTouchCapModeCharacter() { + // Set auto character caps mode on. + setAutoCapsMode(CAP_MODE_CHARACTERS); + // Update shift state with auto caps enabled. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press 'X' key and hold + pressKey('X', ALPHABET_AUTOMATIC_SHIFTED); + // Press 'Z' key and hold, stay in automatic shifted mode. + chordingPressKey('Z', ALPHABET_AUTOMATIC_SHIFTED); + // Release 'X' key + releaseKey('X', ALPHABET_AUTOMATIC_SHIFTED); + // Release 'Z' key + releaseKey('Z', ALPHABET_AUTOMATIC_SHIFTED); + } + + // Multi touch shift chording input in manual shifted. + public void testMultiTouchShiftChordingManualShifted() { + // Press/release shift key, enter into alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + + // Press shift key and hold, stays in alphabet shifted. + pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press 'X' key and hold + chordingPressKey('X', ALPHABET_MANUAL_SHIFTED); + // Press 'Z' key and hold, stays in alphabet shifted. + chordingPressKey('Z', ALPHABET_MANUAL_SHIFTED); + // Release 'X' key + releaseKey('X', ALPHABET_MANUAL_SHIFTED); + // Release 'Z' key + releaseKey('Z', ALPHABET_MANUAL_SHIFTED); + // Release shift key, switch back to alphabet shifted. + releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + } + + // Multi touch shift chording input in automatic upper case. + public void testMultiTouchShiftChordingAutomaticUpperCase() { + // Set auto word caps mode on. + setAutoCapsMode(CAP_MODE_WORDS); + // Update shift state with auto caps enabled. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press shift key and hold, switch to alphabet shifted. + pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press 'X' key and hold + chordingPressKey('X', ALPHABET_MANUAL_SHIFTED); + // Press 'Z' key and hold, stays in alphabet shifted. + chordingPressKey('Z', ALPHABET_MANUAL_SHIFTED); + // Release 'X' key + releaseKey('X', ALPHABET_MANUAL_SHIFTED); + // Release 'Z' key + releaseKey('Z', ALPHABET_MANUAL_SHIFTED); + // Release shift key, updated to alphabet unshifted. + releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); + + // Update shift state with auto caps enabled. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press shift key and hold, switch to alphabet shifted. + pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press 'X' key and hold + chordingPressKey('X', ALPHABET_MANUAL_SHIFTED); + // Release 'X' key + releaseKey('X', ALPHABET_MANUAL_SHIFTED); + // Press key and hold, stays in alphabet shifted. + chordingPressKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_MANUAL_SHIFTED); + // Release 'Z' key + releaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_MANUAL_SHIFTED); + // Release shift key, updated to alphabet automatic shifted. + releaseKey(CODE_SHIFT, ALPHABET_AUTOMATIC_SHIFTED); + } + + // Multi touch shift chording input in capitalize character mode. + public void testMultiTouchShiftChordingCapModeCharacter() { + // Set auto character caps mode on. + setAutoCapsMode(CAP_MODE_CHARACTERS); + // Update shift state with auto caps enabled. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press shift key and hold, switch to alphabet shifted. + pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + // Press 'X' key and hold + chordingPressKey('X', ALPHABET_MANUAL_SHIFTED); + // Press 'Z' key and hold, stay in automatic shifted mode. + chordingPressKey('Z', ALPHABET_MANUAL_SHIFTED); + // Release 'X' key + releaseKey('X', ALPHABET_MANUAL_SHIFTED); + // Release 'Z' key + releaseKey('Z', ALPHABET_MANUAL_SHIFTED); + // Release shift key, updated to alphabet automatic shifted. + releaseKey(CODE_SHIFT, ALPHABET_AUTOMATIC_SHIFTED); + } + + public void testLongPressShiftAndChording() { + // Long press shift key, enter maybe shift locked. + longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release letter key, remain in manual shifted. + chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Release shift key, back to alphabet (not shift locked). + releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); + + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Long press shift key, enter maybe alphabet. + longPressShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED); + // Press/release letter key, remain in manual shifted. + chordingPressAndReleaseKey('A', ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED); + // Release shift key, back to shift locked (not alphabet). + releaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCKED); + // Long press shift key, enter alphabet + longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED, + ALPHABET_UNSHIFTED); + + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Long press shift key, enter maybe alphabet. + longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release letter key, remain in manual shifted. + chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Release shift key, back to alphabet shifted (not alphabet). + releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); + + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Load keyboard, should be in automatic shifted. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + // Long press shift key, enter maybe shift locked. + longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release letter key, remain in manual shifted. + chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Release shift key, back to alphabet (not shift locked). + releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); + } + + public void testDoubleTapShiftAndChording() { + // TODO: The following tests fail due to bug. Temporarily commented. +// // First shift key tap. +// pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); +// // Second shift key tap, maybe shift locked. +// secondPressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); +// // Press/release letter key, remain in manual shifted. +// chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); +// // Release shift key, back to alphabet shifted (not shift locked). +// releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); +// +// // Long press shift key, enter alphabet shift locked. +// longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, +// ALPHABET_SHIFT_LOCKED); +// // First shift key tap. +// pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); +// // Second shift key tap, maybe shift unlocked. +// secondPressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); +// // Press/release letter key, remain in manual shifted. +// chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); +// // Release shift key, back to alphabet (not shift locked). +// releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); +// +// // Set capitalize the first character of all words mode. +// setAutoCapsMode(CAP_MODE_WORDS); +// // Load keyboard, should be in automatic shifted. +// loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); +// // First shift key tap. +// pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); +// // Second shift key tap, maybe shift locked. +// secondPressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED); +// // Press/release letter key, remain in manual shifted. +// chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); +// // Release shift key, back to alphabet (not shift locked). +// releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java new file mode 100644 index 000000000..f1621ebb0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java @@ -0,0 +1,971 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import androidx.test.filters.SmallTest; + +@SmallTest +public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase { + // Shift key in alphabet. + public void testShiftAlphabet() { + // Press/release shift key, enter into alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + + // Press/release shift key, back to alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + + // Press/release shift key, enter into alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release letter key, switch back to alphabet. + pressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + } + + // Shift key in symbols. + public void testShiftSymbols() { + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + + // Press/release "?123" key, back to symbols. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release symbol letter key, remain in symbols shifted. + pressAndReleaseKey('1', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + } + + // Switching between alphabet and symbols. + public void testAlphabetAndSymbols() { + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, back to alphabet. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, back to alphabet. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Press/release "?123" key, back to symbols (not symbols shifted). + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + } + + // Switching between alphabet shifted and symbols. + public void testAlphabetShiftedAndSymbols() { + // Press/release shift key, enter into alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, back to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Press/release shift key, enter into alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\< key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, back to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + } + + // Switching between alphabet shift locked and symbols. + public void testAlphabetShiftLockedAndSymbols() { + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, back to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, back to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, back to symbols (not symbols shifted). + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + } + + // Automatic switch back to alphabet by space key. + public void testSwitchBackBySpace() { + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter symbol letter. + pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter space, switch back to alphabet. + pressAndReleaseKey(CODE_SPACE, SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter symbol shift letter. + pressAndReleaseKey('~', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter space, switch back to alphabet. + pressAndReleaseKey(CODE_SPACE, SYMBOLS_SHIFTED, ALPHABET_UNSHIFTED); + // Press/release "?123" key, enter into symbols (not symbols shifted). + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + } + + // Automatic switch back to alphabet shift locked test by space key. + public void testSwitchBackBySpaceShiftLocked() { + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter symbol letter. + pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter space, switch back to alphabet shift locked. + pressAndReleaseKey(CODE_SPACE, SYMBOLS_UNSHIFTED, ALPHABET_SHIFT_LOCKED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter symbol shift letter. + pressAndReleaseKey('~', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter space, switch back to alphabet shift locked. + pressAndReleaseKey(CODE_SPACE, SYMBOLS_SHIFTED, ALPHABET_SHIFT_LOCKED); + } + + // Automatic upper case test + public void testAutomaticUpperCase() { + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Load keyboard, should be in automatic shifted. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release letter key, switch to alphabet. + pressAndReleaseKey('A', ALPHABET_AUTOMATIC_SHIFTED, ALPHABET_UNSHIFTED); + // Press/release auto caps trigger letter, should be in automatic shifted. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release shift key, back to alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Press/release letter key, remain in alphabet. + pressAndReleaseKey('a', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Press/release auto caps trigger letter, should be in automatic shifted. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release symbol letter key, remain in symbols. + pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release space, switch back to automatic shifted. + pressAndReleaseKey(CODE_SPACE, SYMBOLS_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release symbol shift letter key, remain in symbols shifted. + pressAndReleaseKey('~', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release space, switch back to automatic shifted. + pressAndReleaseKey(CODE_SPACE, SYMBOLS_SHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + } + + // Long press shift key. + public void testLongPressShift() { + // Set auto caps mode off. + setAutoCapsMode(CAP_MODE_OFF); + // Load keyboard, should be in alphabet. + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release shift key, back to alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release letter key, remain in shift locked. + pressAndReleaseKey('A', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Press/release word separator, remain in shift locked. + pressAndReleaseKey(CODE_SPACE, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Press/release shift key, back to alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Long press shift key, back to alphabet. + longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED, + ALPHABET_UNSHIFTED); + + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release shift key, back to alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Load keyboard, should be in automatic shifted. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release shift key, back to alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + } + + // Double tap shift key. + public void testDoubleTapShift() { + // First shift key tap. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Second shift key tap. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // First shift key tap. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + // Second shift key tap. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Press/release shift key, enter alphabet manual shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + + // First shift key tap. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Second shift key tap. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // First shift key tap. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + // Second shift key tap. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Load keyboard, should be in automatic shifted. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + + // First shift key tap. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Second shift key tap. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // First shift key tap. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + // Second shift key tap. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + } + + // Update shift state. + public void testUpdateShiftState() { + // Set auto caps mode off. + setAutoCapsMode(CAP_MODE_OFF); + // Load keyboard, should be in alphabet. + loadKeyboard(ALPHABET_UNSHIFTED); + // Update shift state, remained in alphabet. + updateShiftState(ALPHABET_UNSHIFTED); + + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Update shift state, back to alphabet. + updateShiftState(ALPHABET_UNSHIFTED); + + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Update shift state, remained in alphabet shift locked. + updateShiftState(ALPHABET_SHIFT_LOCKED); + // Long press shift key, back to alphabet. + longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED, + ALPHABET_UNSHIFTED); + + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Update shift state, remained in symbols. + updateShiftState(SYMBOLS_UNSHIFTED); + + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Update shift state, remained in symbols shifted. + updateShiftState(SYMBOLS_SHIFTED); + + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Load keyboard, should be in automatic shifted. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + // Update shift state, remained in automatic shifted. + updateShiftState(ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release shift key, enter alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Update shift state, enter to automatic shifted (not alphabet shifted). + updateShiftState(ALPHABET_AUTOMATIC_SHIFTED); + + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Update shift state, remained in alphabet shift locked (not automatic shifted). + updateShiftState(ALPHABET_SHIFT_LOCKED); + // Long press shift key, back to alphabet. + longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED, + ALPHABET_UNSHIFTED); + + // Load keyboard, should be in automatic shifted. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Update shift state, remained in symbols. + updateShiftState(SYMBOLS_UNSHIFTED); + + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Update shift state, remained in symbols shifted. + updateShiftState(SYMBOLS_SHIFTED); + } + + // Sliding input in alphabet. + public void testSlidingAlphabet() { + // Alphabet -> shift key + letter -> alphabet. + // Press and slide from shift key, enter alphabet shifted. + pressAndSlideFromKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Enter/release letter keys, switch back to alphabet. + pressAndSlideFromKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + stopSlidingOnKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet -> "?123" key + letter -> alphabet. + // Press and slide from "123?" key, enter symbols. + pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release into symbol letter keys, switch back to alphabet. + pressAndSlideFromKey('@', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + stopSlidingOnKey('!', SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shifted -> shift key + letter -> alphabet. + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press and slide from shift key, remain alphabet shifted. + pressAndSlideFromKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Enter/release letter keys, switch back to alphabet (not alphabet shifted). + pressAndSlideFromKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + stopSlidingOnKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shifted -> "?123" key + letter -> alphabet. + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press and slide from "123?" key, enter symbols. + pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release into symbol letter keys, switch back to alphabet (not alphabet shifted). + pressAndSlideFromKey('@', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + stopSlidingOnKey('!', SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> shift key + letter -> alphabet shift locked. + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press and slide from "123?" key, enter symbols. + pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release into symbol letter keys, switch back to alphabet shift locked. + pressAndSlideFromKey('!', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + stopSlidingOnKey('!', SYMBOLS_UNSHIFTED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> "?123" key + letter -> alphabet shift locked. + // Press and slide from shift key, enter alphabet shifted. + pressAndSlideFromKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCKED); + // Enter/release letter keys, switch back to shift locked. + pressAndSlideFromKey('A', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + stopSlidingOnKey('Z', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + } + + // Cancel sliding input in alphabet. + public void testSlidingAlphabetCancel() { + // Alphabet -> shift key + letter -> cancel -> alphabet. + // Press and slide from shift key, enter alphabet shifted. + pressAndSlideFromKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press and slide from shift key, enter alphabet shifted. + pressAndSlideFromKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Enter/release letter key, remains in alphabet shifted. + pressAndSlideFromKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Cancel sliding, switch back to alphabet. + stopSlidingAndCancel(ALPHABET_UNSHIFTED); + + // Alphabet -> "?123" key + letter -> cancel -> alphabet. + // Press and slide from "123?" key, enter symbols. + pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release into symbol letter key, remains in symbols. + pressAndSlideFromKey('!', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Cancel sliding, switch back to alphabet. + stopSlidingAndCancel(ALPHABET_UNSHIFTED); + + // Alphabet shifted -> shift key + letter -> cancel -> alphabet. + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press and slide from shift key, remain alphabet shifted. + pressAndSlideFromKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Enter/release letter key, remains in alphabet shifted. + pressAndSlideFromKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Cancel sliding, switch back to alphabet (not alphabet shifted). + stopSlidingAndCancel(ALPHABET_UNSHIFTED); + + // Alphabet shifted -> "?123" key + letter -> cancel -> alphabet. + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press and slide from "123?" key, enter symbols. + pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release into symbol letter key, remains in symbols. + pressAndSlideFromKey('!', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Cancel sliding, switch back to alphabet (not alphabet shifted). + stopSlidingAndCancel(ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> shift key + letter -> cancel -> alphabet shift locked. + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press and slide from "123?" key, enter symbols. + pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release into symbol letter key, remains in symbols. + pressAndSlideFromKey('!', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Cancel sliding, switch back to alphabet shift locked. + stopSlidingAndCancel( ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> "?123" key + letter -> cancel -> alphabet shift locked. + // Press and slide from shift key, enter alphabet shifted. + pressAndSlideFromKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCKED); + // Enter/release letter key, remains in alphabet shift locked. + pressAndSlideFromKey('Z', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Enter/release letter key, switch back to shift locked. + stopSlidingAndCancel(ALPHABET_SHIFT_LOCKED); + } + + // Sliding input in symbols. + public void testSlidingSymbols() { + // Symbols -> "=\<" key + letter -> symbols. + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from shift key, enter symbols shifted. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter/release symbol shifted letter keys, switch back to symbols. + pressAndSlideFromKey('|', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + stopSlidingOnKey('~', SYMBOLS_SHIFTED, SYMBOLS_UNSHIFTED); + + // Symbols -> "ABC" key + letter -> Symbols. + // Press and slide from "ABC" key, enter alphabet. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter keys, switch back to symbols. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + stopSlidingOnKey('a', ALPHABET_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shifted -> symbols -> "ABC" key + letter -> symbols -> + // alphabet. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from "ABC" key. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter keys, switch back to symbols. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + stopSlidingOnKey('a', ALPHABET_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> symbols -> "ABC" key + letter -> symbols -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from "ABC" key, enter alphabet shift locked. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Enter/release letter keys, switch back to symbols. + pressAndSlideFromKey('Z', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + stopSlidingOnKey('A', ALPHABET_SHIFT_LOCKED, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols -> "=\<" key + letter -> symbols -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from "=\<" key, enter symbols shifted. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter/release symbols shift letter keys, switch back to symbols. + pressAndSlideFromKey('|', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + stopSlidingOnKey('~', SYMBOLS_SHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + } + + // Cancel sliding input in symbols. + public void testSlidingSymbolsCancel() { + // Symbols -> "=\<" key + letter -> cancel -> symbols. + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from shift key, enter symbols shifted. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter/release symbol shifted letter key, remains in symbols shifted. + pressAndSlideFromKey('|', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Cancel sliding, switch back to symbols. + stopSlidingAndCancel(SYMBOLS_UNSHIFTED); + + // Symbols -> "ABC" key + letter -> Symbols. + // Press and slide from "ABC" key, enter alphabet. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter keys, remains in alphabet. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Cancel sliding, switch back to symbols. + stopSlidingAndCancel(SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shifted -> symbols -> "ABC" key + letter -> symbols -> + // alphabet. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from "ABC" key. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter key, remains in alphabet. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Cancel sliding, switch back to symbols. + stopSlidingAndCancel(SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> symbols -> "ABC" key + letter -> symbols -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from "ABC" key, enter alphabet shift locked. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Enter/release letter key, remains in alphabet shifted. + pressAndSlideFromKey('Z', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Cancel sliding, switch back to symbols. + stopSlidingAndCancel(SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols -> "=\<" key + letter -> symbols -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press and slide from "=\<" key, enter symbols shifted. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Enter/release symbols shift letter key, remains in symbols shifted. + pressAndSlideFromKey('|', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Cancel sliding, switch back to symbols. + stopSlidingAndCancel(SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + } + + // Sliding input in symbols shifted. + public void testSlidingSymbolsShifted() { + // Symbols shifted -> "?123" + letter -> symbols shifted. + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from shift key, enter symbols. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release symbol letter keys, switch back to symbols shifted. + pressAndSlideFromKey('2', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + stopSlidingOnKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_SHIFTED); + + // Symbols shifted -> "ABC" key + letter -> symbols shifted. + // Press and slide from "ABC" key, enter alphabet. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter keys, switch back to symbols shifted. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + stopSlidingOnKey('a', ALPHABET_UNSHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shifted -> symbols shifted -> "ABC" + letter -> symbols shifted -> + // alphabet. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from "ABC" key. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter keys, switch back to symbols shifted. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + stopSlidingOnKey('a', ALPHABET_UNSHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> symbols shifted -> "ABC" + letter -> symbols shifted -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from "ABC" key. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Enter/release letter keys, switch back to symbols shifted. + pressAndSlideFromKey('Z', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + stopSlidingOnKey('A', ALPHABET_SHIFT_LOCKED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols shifted -> "?123" + letter -> symbols shifted -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from "?123" key. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release symbol letter keys, switch back to symbols shifted. + pressAndSlideFromKey('2', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + stopSlidingOnKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + } + + // Cancel sliding input in symbols shifted. + public void testSlidingSymbolsShiftedCancel() { + // Symbols shifted -> "?123" + letter -> symbols shifted. + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from shift key, enter symbols. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release symbol letter key, remains in symbols. + pressAndSlideFromKey('2', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Cancel sliding, switch back to symbols shifted. + stopSlidingAndCancel(SYMBOLS_SHIFTED); + + // Symbols shifted -> "ABC" key + letter -> symbols shifted. + // Press and slide from "ABC" key, enter alphabet. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter key, remains in alphabet. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Cancel sliding, switch back to symbols shifted. + stopSlidingAndCancel(SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shifted -> symbols shifted -> "ABC" + letter -> symbols shifted -> + // alphabet. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from "ABC" key. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Enter/release letter key, remains in alphabet. + pressAndSlideFromKey('z', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Cancel sliding, switch back to symbols shifted. + stopSlidingAndCancel(SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet (not alphabet shifted). + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shift locked -> symbols shifted -> "ABC" + letter -> symbols shifted -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from "ABC" key. + pressAndSlideFromKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Enter/release letter key, remains in alphabet shift locked. + pressAndSlideFromKey('Z', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Cancel sliding, switch back to symbols shifted. + stopSlidingAndCancel(SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols shifted -> "?123" + letter -> symbols shifted -> + // alphabet shift locked. + // Load keyboard + loadKeyboard(ALPHABET_UNSHIFTED); + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter into symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter into symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press and slide from "?123" key. + pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Enter/release symbol letter key, remains in symbols. + pressAndSlideFromKey('2', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Cancel sliding, switch back to symbols shifted. + stopSlidingAndCancel(SYMBOLS_SHIFTED); + // Press/release "ABC" key, switch to alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + } + + // Change focus to new text field. + public void testChangeFocus() { + // Press/release shift key. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Change focus to new text field. + loadKeyboard(ALPHABET_UNSHIFTED); + + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Change focus to new text field. + loadKeyboard(ALPHABET_UNSHIFTED); + + // Press/release "?123" key. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Change focus to new text field. + loadKeyboard(ALPHABET_UNSHIFTED); + + // Press/release "?123" key. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Change focus to new text field. + loadKeyboard(ALPHABET_UNSHIFTED); + } + + // Change focus to auto caps text field. + public void testChangeFocusAutoCaps() { + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Change focus to new text field. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release shift key, enter alphabet. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Change focus to new text field. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Change focus to new text field. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release "?123" key. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Change focus to new text field. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + + // Press/release "?123" key. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Change focus to new text field. + loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); + } + + // Change orientation. + public void testChangeOrientation() { + // Alphabet -> rotate -> alphabet. + updateShiftState(ALPHABET_UNSHIFTED); + // Rotate device, remain in alphabet. + rotateDevice(ALPHABET_UNSHIFTED); + + // Alphabet automatic shifted -> rotate -> automatic shifted. + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Press/release auto caps trigger letter to enter alphabet automatic shifted. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + // Rotate device, remain in alphabet. + rotateDevice(ALPHABET_AUTOMATIC_SHIFTED); + setAutoCapsMode(CAP_MODE_OFF); + // Press/release auto caps trigger letter to reset shift state. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_AUTOMATIC_SHIFTED, ALPHABET_UNSHIFTED); + + // Alphabet shifted -> rotate -> alphabet shifted. + // Press/release shift key, enter alphabet shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rotate device, remain in alphabet shifted. + rotateDevice(ALPHABET_MANUAL_SHIFTED); + + // Alphabet shift locked -> rotate -> alphabet shift locked. + // Long press shift key, enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Rotate device, remain in alphabet shift locked. + rotateDevice(ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols -> rotate -> symbols -> + // Alphabet shift locked. + // Press/release "?123" key, enter symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Rotate device, remain in symbols, + rotateDevice(SYMBOLS_UNSHIFTED); + // Press/release "ABC" key, alphabet shift locked state should be maintained. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols shifted -> rotate -> symbols shifted -> + // Alphabet shift locked. + // Press/release "?123" key, enter symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Rotate device, remain in symbols shifted. + rotateDevice(SYMBOLS_SHIFTED); + // Press/release "ABC" key, alphabet shift locked state should be maintained. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + + // Alphabet shift locked -> symbols shifted -> alphabet shift locked -> rotate -> + // Alphabet shift locked -> symbols. + // Press/release "?123" key, enter symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, enter alphabet shift locked. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED); + // Rotate device, remain in alphabet shift locked. + rotateDevice(ALPHABET_SHIFT_LOCKED); + // Press/release "?123" key, enter symbols (not symbols shifted). + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + + // Alphabet -> symbols shifted -> alphabet -> rotate -> + // Alphabet -> symbols. + loadKeyboard(ALPHABET_UNSHIFTED); + // Press/release "?123" key, enter symbols. + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + // Press/release "=\<" key, enter symbols shifted. + pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED); + // Press/release "ABC" key, enter alphabet. + pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Rotate device, remain in alphabet shift locked. + rotateDevice(ALPHABET_UNSHIFTED); + // Press/release "?123" key, enter symbols (not symbols shifted). + pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED); + } + + // Rapidly type shift key. + public void testRapidShiftTyping() { + // Press/release shift key + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + + // Press/release shift key to enter alphabet manual shifted. + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Press/release shift key + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('j', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + + // Long press shift key to enter alphabet shift locked. + longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED, + ALPHABET_SHIFT_LOCKED); + // Press/release shift key + pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('j', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + + // Set capitalize the first character of all words mode. + setAutoCapsMode(CAP_MODE_WORDS); + // Press/release auto caps trigger letter to enter alphabet automatic shifted. + pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); + // Press/release shift key + pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('j', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + // Rapidly press/release shift key. + secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED); + // Rapidly press/release letter key. + secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateTestsBase.java b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateTestsBase.java new file mode 100644 index 000000000..016578ce6 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardStateTestsBase.java @@ -0,0 +1,253 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import android.test.AndroidTestCase; + +import org.kelar.inputmethod.latin.common.Constants; + +public class KeyboardStateTestsBase extends AndroidTestCase + implements MockKeyboardSwitcher.MockConstants { + protected MockKeyboardSwitcher mSwitcher; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mSwitcher = new MockKeyboardSwitcher(); + mSwitcher.setAutoCapsMode(CAP_MODE_OFF); + + loadKeyboard(ALPHABET_UNSHIFTED); + } + + /** + * Set auto caps mode. + * + * @param autoCaps the auto cap mode. + */ + public void setAutoCapsMode(final int autoCaps) { + mSwitcher.setAutoCapsMode(autoCaps); + } + + private static void assertLayout(final String message, final int expected, final int actual) { + assertTrue(message + ": expected=" + MockKeyboardSwitcher.getLayoutName(expected) + + " actual=" + MockKeyboardSwitcher.getLayoutName(actual), + expected == actual); + } + + /** + * Emulate update keyboard shift state. + * + * @param afterUpdate the keyboard state after updating the keyboard shift state. + */ + public void updateShiftState(final int afterUpdate) { + mSwitcher.updateShiftState(); + assertLayout("afterUpdate", afterUpdate, mSwitcher.getLayoutId()); + } + + /** + * Emulate load default keyboard. + * + * @param afterLoad the keyboard state after loading default keyboard. + */ + public void loadKeyboard(final int afterLoad) { + mSwitcher.loadKeyboard(); + mSwitcher.updateShiftState(); + assertLayout("afterLoad", afterLoad, mSwitcher.getLayoutId()); + } + + /** + * Emulate rotate device. + * + * @param afterRotate the keyboard state after rotating device. + */ + public void rotateDevice(final int afterRotate) { + mSwitcher.saveKeyboardState(); + mSwitcher.loadKeyboard(); + assertLayout("afterRotate", afterRotate, mSwitcher.getLayoutId()); + } + + private void pressKeyWithoutTimerExpire(final int code, final boolean isSinglePointer, + final int afterPress) { + mSwitcher.onPressKey(code, isSinglePointer); + assertLayout("afterPress", afterPress, mSwitcher.getLayoutId()); + } + + /** + * Emulate key press. + * + * @param code the key code to press. + * @param afterPress the keyboard state after pressing the key. + */ + public void pressKey(final int code, final int afterPress) { + mSwitcher.expireDoubleTapTimeout(); + pressKeyWithoutTimerExpire(code, true, afterPress); + } + + /** + * Emulate key release and register. + * + * @param code the key code to release and register + * @param afterRelease the keyboard state after releasing the key. + */ + public void releaseKey(final int code, final int afterRelease) { + mSwitcher.onCodeInput(code); + mSwitcher.onReleaseKey(code, NOT_SLIDING); + assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId()); + } + + /** + * Emulate key press and release. + * + * @param code the key code to press and release. + * @param afterPress the keyboard state after pressing the key. + * @param afterRelease the keyboard state after releasing the key. + */ + public void pressAndReleaseKey(final int code, final int afterPress, final int afterRelease) { + pressKey(code, afterPress); + releaseKey(code, afterRelease); + } + + /** + * Emulate chording key press. + * + * @param code the chording key code. + * @param afterPress the keyboard state after pressing chording key. + */ + public void chordingPressKey(final int code, final int afterPress) { + mSwitcher.expireDoubleTapTimeout(); + pressKeyWithoutTimerExpire(code, false, afterPress); + } + + /** + * Emulate chording key release. + * + * @param code the cording key code. + * @param afterRelease the keyboard state after releasing chording key. + */ + public void chordingReleaseKey(final int code, final int afterRelease) { + mSwitcher.onCodeInput(code); + mSwitcher.onReleaseKey(code, NOT_SLIDING); + assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId()); + } + + /** + * Emulate chording key press and release. + * + * @param code the chording key code. + * @param afterPress the keyboard state after pressing chording key. + * @param afterRelease the keyboard state after releasing chording key. + */ + public void chordingPressAndReleaseKey(final int code, final int afterPress, + final int afterRelease) { + chordingPressKey(code, afterPress); + chordingReleaseKey(code, afterRelease); + } + + /** + * Emulate start of the sliding key input. + * + * @param code the key code to start sliding. + * @param afterPress the keyboard state after pressing the key. + * @param afterSlide the keyboard state after releasing the key with sliding input. + */ + public void pressAndSlideFromKey(final int code, final int afterPress, final int afterSlide) { + pressKey(code, afterPress); + mSwitcher.onReleaseKey(code, SLIDING); + assertLayout("afterSlide", afterSlide, mSwitcher.getLayoutId()); + } + + /** + * Emulate end of the sliding key input. + * + * @param code the key code to stop sliding. + * @param afterPress the keyboard state after pressing the key. + * @param afterSlide the keyboard state after releasing the key and stop sliding. + */ + public void stopSlidingOnKey(final int code, final int afterPress, final int afterSlide) { + pressKey(code, afterPress); + mSwitcher.onCodeInput(code); + mSwitcher.onReleaseKey(code, NOT_SLIDING); + mSwitcher.onFinishSlidingInput(); + assertLayout("afterSlide", afterSlide, mSwitcher.getLayoutId()); + } + + /** + * Emulate cancel the sliding key input. + * + * @param afterCancelSliding the keyboard state after canceling sliding input. + */ + public void stopSlidingAndCancel(final int afterCancelSliding) { + mSwitcher.onFinishSlidingInput(); + assertLayout("afterCancelSliding", afterCancelSliding, mSwitcher.getLayoutId()); + } + + /** + * Emulate long press shift key. + * + * @param afterPress the keyboard state after pressing shift key. + * @param afterLongPress the keyboard state after long press fired. + */ + public void longPressShiftKey(final int afterPress, final int afterLongPress) { + // Long press shift key will register {@link Constants#CODE_CAPS_LOCK}. See + // {@link R.xml#key_styles_common} and its baseForShiftKeyStyle. We thus emulate the + // behavior that is implemented in {@link MainKeyboardView#onLongPress(PointerTracker)}. + pressKey(Constants.CODE_SHIFT, afterPress); + mSwitcher.onPressKey(Constants.CODE_CAPSLOCK, true /* isSinglePointer */); + mSwitcher.onCodeInput(Constants.CODE_CAPSLOCK); + assertLayout("afterLongPress", afterLongPress, mSwitcher.getLayoutId()); + } + + /** + * Emulate long press shift key and release. + * + * @param afterPress the keyboard state after pressing shift key. + * @param afterLongPress the keyboard state after long press fired. + * @param afterRelease the keyboard state after shift key is released. + */ + public void longPressAndReleaseShiftKey(final int afterPress, final int afterLongPress, + final int afterRelease) { + // Long press shift key will register {@link Constants#CODE_CAPS_LOCK}. See + // {@link R.xml#key_styles_common} and its baseForShiftKeyStyle. We thus emulate the + // behavior that is implemented in {@link MainKeyboardView#onLongPress(PointerTracker)}. + longPressShiftKey(afterPress, afterLongPress); + releaseKey(Constants.CODE_CAPSLOCK, afterRelease); + } + + /** + * Emulate the second press of the double tap. + * + * @param code the key code to double tap. + * @param afterPress the keyboard state after pressing the second tap. + */ + public void secondPressKey(final int code, final int afterPress) { + pressKeyWithoutTimerExpire(code, true, afterPress); + } + + /** + * Emulate the second tap of the double tap. + * + * @param code the key code to double tap. + * @param afterPress the keyboard state after pressing the second tap. + * @param afterRelease the keyboard state after releasing the second tap. + */ + public void secondPressAndReleaseKey(final int code, final int afterPress, + final int afterRelease) { + secondPressKey(code, afterPress); + releaseKey(code, afterRelease); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardTextsSetTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardTextsSetTests.java new file mode 100644 index 000000000..34a16cfb7 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/KeyboardTextsSetTests.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.internal; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import android.content.Context; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.RichInputMethodManager; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public final class KeyboardTextsSetTests { + // All input method subtypes of LatinIME. + private List<InputMethodSubtype> mAllSubtypesList; + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + @Before + public void setUp() throws Exception { + RichInputMethodManager.init(getContext()); + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + + final ArrayList<InputMethodSubtype> allSubtypesList = new ArrayList<>(); + final InputMethodInfo imi = richImm.getInputMethodInfoOfThisIme(); + final int subtypeCount = imi.getSubtypeCount(); + for (int index = 0; index < subtypeCount; index++) { + final InputMethodSubtype subtype = imi.getSubtypeAt(index); + allSubtypesList.add(subtype); + } + mAllSubtypesList = Collections.unmodifiableList(allSubtypesList); + } + + // Test that the text {@link KeyboardTextsSet#SWITCH_TO_ALPHA_KEY_LABEL} exists for all + // subtypes. The text is needed to implement Emoji Keyboard, see + // {@link KeyboardSwitcher#setEmojiKeyboard()}. + @Test + public void testSwitchToAlphaKeyLabel() { + final Context context = getContext(); + final KeyboardTextsSet textsSet = new KeyboardTextsSet(); + for (final InputMethodSubtype subtype : mAllSubtypesList) { + final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype); + textsSet.setLocale(locale, context); + final String switchToAlphaKeyLabel = textsSet.getText( + KeyboardTextsSet.SWITCH_TO_ALPHA_KEY_LABEL); + assertNotNull("Switch to alpha key label of " + locale, switchToAlphaKeyLabel); + assertFalse("Switch to alpha key label of " + locale, switchToAlphaKeyLabel.isEmpty()); + } + } + + private static final String[] TEXT_NAMES_FROM_RESOURCE = { + // Labels for action. + "label_go_key", + "label_send_key", + "label_next_key", + "label_done_key", + "label_previous_key", + // Other labels. + "label_pause_key", + "label_wait_key", + }; + + // Test that the text from resources are correctly loaded for all subtypes. + @Test + public void testTextFromResources() { + final Context context = getContext(); + final KeyboardTextsSet textsSet = new KeyboardTextsSet(); + for (final InputMethodSubtype subtype : mAllSubtypesList) { + final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype); + textsSet.setLocale(locale, context); + for (final String name : TEXT_NAMES_FROM_RESOURCE) { + final String text = textsSet.getText(name); + assertNotNull(name + " of " + locale, text); + assertFalse(name + " of " + locale, text.isEmpty()); + } + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/MatrixUtilsTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/MatrixUtilsTests.java new file mode 100644 index 000000000..2c7d986c9 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/MatrixUtilsTests.java @@ -0,0 +1,85 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.keyboard.internal.MatrixUtils.MatrixOperationFailedException; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class MatrixUtilsTests { + // "run tests" -c org.kelar.inputmethod.keyboard.internal.MatrixUtilsTests + private static final boolean DEBUG = false; + private static final float EPSILON = 0.00001f; + + @Test + public void testMulti() { + final float[][] matrixA = {{1, 2}, {3, 4}}; + final float[][] matrixB = {{5, 6}, {7, 8}}; + final float[][] retval = new float[2][2]; + try { + MatrixUtils.multiply(matrixA, matrixB, retval); + } catch (MatrixOperationFailedException e) { + assertTrue(false); + } + if (DEBUG) { + MatrixUtils.dump("multi", retval); + } + assertEquals(retval[0][0], 19, EPSILON); + assertEquals(retval[0][1], 22, EPSILON); + assertEquals(retval[1][0], 43, EPSILON); + assertEquals(retval[1][1], 50, EPSILON); + } + + @Test + public void testInverse() { + final int N = 4; + final float[][] matrix = + {{1, 2, 3, 4}, {4, 0, 5, 6}, {6, 4, 2, 0}, {6, 4, 2, 1}}; + final float[][] inverse = new float[N][N]; + final float[][] tempMatrix = new float[N][N]; + for (int i = 0; i < N; ++i) { + for (int j = 0; j < N; ++j) { + tempMatrix[i][j] = matrix[i][j]; + } + } + final float[][] retval = new float[N][N]; + try { + MatrixUtils.inverse(tempMatrix, inverse); + } catch (MatrixOperationFailedException e) { + assertTrue(false); + } + try { + MatrixUtils.multiply(matrix, inverse, retval); + } catch (MatrixOperationFailedException e) { + assertTrue(false); + } + for (int i = 0; i < N; ++i) { + for (int j = 0; j < N; ++j) { + assertEquals(((i == j) ? 1.0f : 0.0f), retval[i][j], EPSILON); + } + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/org/kelar/inputmethod/keyboard/internal/MockKeyboardSwitcher.java new file mode 100644 index 000000000..197652783 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/MockKeyboardSwitcher.java @@ -0,0 +1,197 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import android.text.TextUtils; + +import org.kelar.inputmethod.event.Event; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.utils.RecapitalizeStatus; + +public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { + public interface MockConstants { + // Argument for {@link KeyboardState#onPressKey} and {@link KeyboardState#onReleaseKey}. + public static final boolean NOT_SLIDING = false; + public static final boolean SLIDING = true; + // Argument for {@link KeyboardState#onEvent}. + public static final boolean SINGLE = true; + public static final boolean MULTI = false; + public static final int CAP_MODE_OFF = Constants.TextUtils.CAP_MODE_OFF; + public static final int CAP_MODE_WORDS = TextUtils.CAP_MODE_WORDS; + public static final int CAP_MODE_CHARACTERS = TextUtils.CAP_MODE_CHARACTERS; + + public static final int CODE_SHIFT = Constants.CODE_SHIFT; + public static final int CODE_SYMBOL = Constants.CODE_SWITCH_ALPHA_SYMBOL; + public static final int CODE_SPACE = Constants.CODE_SPACE; + public static final int CODE_AUTO_CAPS_TRIGGER = Constants.CODE_SPACE; + + public static final int ALPHABET_UNSHIFTED = 0; + public static final int ALPHABET_MANUAL_SHIFTED = 1; + public static final int ALPHABET_AUTOMATIC_SHIFTED = 2; + public static final int ALPHABET_SHIFT_LOCKED = 3; + public static final int ALPHABET_SHIFT_LOCK_SHIFTED = 4; + public static final int SYMBOLS_UNSHIFTED = 5; + public static final int SYMBOLS_SHIFTED = 6; + } + + private int mLayout = MockConstants.ALPHABET_UNSHIFTED; + + private int mAutoCapsMode = MockConstants.CAP_MODE_OFF; + // Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS. + private int mAutoCapsState = MockConstants.CAP_MODE_OFF; + + private boolean mIsInDoubleTapShiftKeyTimeout; + private int mLongPressTimeoutCode; + + private final KeyboardState mState = new KeyboardState(this); + + public int getLayoutId() { + return mLayout; + } + + public static String getLayoutName(final int layoutId) { + switch (layoutId) { + case MockConstants.ALPHABET_UNSHIFTED: return "ALPHABET_UNSHIFTED"; + case MockConstants.ALPHABET_MANUAL_SHIFTED: return "ALPHABET_MANUAL_SHIFTED"; + case MockConstants.ALPHABET_AUTOMATIC_SHIFTED: return "ALPHABET_AUTOMATIC_SHIFTED"; + case MockConstants.ALPHABET_SHIFT_LOCKED: return "ALPHABET_SHIFT_LOCKED"; + case MockConstants.ALPHABET_SHIFT_LOCK_SHIFTED: return "ALPHABET_SHIFT_LOCK_SHIFTED"; + case MockConstants.SYMBOLS_UNSHIFTED: return "SYMBOLS_UNSHIFTED"; + case MockConstants.SYMBOLS_SHIFTED: return "SYMBOLS_SHIFTED"; + default: return "UNKNOWN<" + layoutId + ">"; + } + } + + public void setAutoCapsMode(final int autoCaps) { + mAutoCapsMode = autoCaps; + mAutoCapsState = autoCaps; + } + + public void expireDoubleTapTimeout() { + mIsInDoubleTapShiftKeyTimeout = false; + } + + @Override + public void setAlphabetKeyboard() { + mLayout = MockConstants.ALPHABET_UNSHIFTED; + } + + @Override + public void setAlphabetManualShiftedKeyboard() { + mLayout = MockConstants.ALPHABET_MANUAL_SHIFTED; + } + + @Override + public void setAlphabetAutomaticShiftedKeyboard() { + mLayout = MockConstants.ALPHABET_AUTOMATIC_SHIFTED; + } + + @Override + public void setAlphabetShiftLockedKeyboard() { + mLayout = MockConstants.ALPHABET_SHIFT_LOCKED; + } + + @Override + public void setAlphabetShiftLockShiftedKeyboard() { + mLayout = MockConstants.ALPHABET_SHIFT_LOCK_SHIFTED; + } + + @Override + public void setSymbolsKeyboard() { + mLayout = MockConstants.SYMBOLS_UNSHIFTED; + } + + @Override + public void setSymbolsShiftedKeyboard() { + mLayout = MockConstants.SYMBOLS_SHIFTED; + } + + @Override + public void setEmojiKeyboard() { + // Just ignore. + } + + @Override + public void requestUpdatingShiftState(final int currentAutoCapsState, + final int currentRecapitalizeState) { + mState.onUpdateShiftState(currentAutoCapsState, currentRecapitalizeState); + } + + @Override + public void startDoubleTapShiftKeyTimer() { + mIsInDoubleTapShiftKeyTimeout = true; + } + + @Override + public void cancelDoubleTapShiftKeyTimer() { + mIsInDoubleTapShiftKeyTimeout = false; + } + + @Override + public boolean isInDoubleTapShiftKeyTimeout() { + return mIsInDoubleTapShiftKeyTimeout; + } + + public void updateShiftState() { + mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + } + + public void loadKeyboard() { + mState.onLoadKeyboard(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + } + + public void saveKeyboardState() { + mState.onSaveKeyboardState(); + } + + public void onPressKey(final int code, final boolean isSinglePointer) { + mState.onPressKey(code, isSinglePointer, mAutoCapsState, + RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + } + + public void onReleaseKey(final int code, final boolean withSliding) { + onReleaseKey(code, withSliding, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + } + + public void onReleaseKey(final int code, final boolean withSliding, + final int currentAutoCapsState, final int currentRecapitalizeState) { + mState.onReleaseKey(code, withSliding, currentAutoCapsState, currentRecapitalizeState); + if (mLongPressTimeoutCode == code) { + mLongPressTimeoutCode = 0; + } + } + + public void onCodeInput(final int code) { + if (mAutoCapsMode == MockConstants.CAP_MODE_WORDS) { + if (Constants.isLetterCode(code)) { + mAutoCapsState = (code == MockConstants.CODE_AUTO_CAPS_TRIGGER) + ? mAutoCapsMode : MockConstants.CAP_MODE_OFF; + } + } else { + mAutoCapsState = mAutoCapsMode; + } + final Event event = + Event.createSoftwareKeypressEvent(code /* codePoint */, code /* keyCode */, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */); + mState.onEvent(event, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + } + + public void onFinishSlidingInput() { + mState.onFinishSlidingInput(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java new file mode 100644 index 000000000..ca7c96a38 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2010 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 org.kelar.inputmethod.keyboard.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import android.content.Context; +import android.content.res.Resources; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.R; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class MoreKeySpecSplitTests { + private static final Locale TEST_LOCALE = Locale.ENGLISH; + private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); + + @Before + public void setUp() throws Exception { + final Context targetContext = InstrumentationRegistry.getTargetContext(); + final Resources targetRes = targetContext.getResources(); + final String targetPackageName = targetRes.getResourcePackageName( + R.string.english_ime_name); + mTextsSet.setLocale(TEST_LOCALE, targetRes, targetPackageName); + } + + static <T> void assertArrayEquals(final String message, final T[] expected, final T[] actual) { + if (expected == actual) { + return; + } + if (expected == null || actual == null) { + assertEquals(message, Arrays.toString(expected), Arrays.toString(actual)); + return; + } + if (expected.length != actual.length) { + assertEquals(message + " [length]", Arrays.toString(expected), Arrays.toString(actual)); + return; + } + for (int i = 0; i < expected.length; i++) { + final T e = expected[i]; + final T a = actual[i]; + if (e == a) { + continue; + } + assertEquals(message + " [" + i + "]", e, a); + } + } + + private void assertTextArray(final String message, final String value, + final String ... expectedArray) { + final String resolvedActual = mTextsSet.resolveTextReference(value); + final String[] actual = MoreKeySpec.splitKeySpecs(resolvedActual); + final String[] expected = (expectedArray.length == 0) ? null : expectedArray; + assertArrayEquals(message, expected, actual); + } + + private void assertError(final String message, final String value, final String ... expected) { + try { + assertTextArray(message, value, expected); + fail(message); + } catch (Exception pcpe) { + // success. + } + } + + // \U001d11e: MUSICAL SYMBOL G CLEF + private static final String PAIR1 = "\ud834\udd1e"; + // \U001d122: MUSICAL SYMBOL F CLEF + private static final String PAIR2 = "\ud834\udd22"; + // \U002f8a6: CJK COMPATIBILITY IDEOGRAPH-2F8A6; variant character of \u6148. + private static final String PAIR3 = "\ud87e\udca6"; + private static final String SURROGATE1 = PAIR1 + PAIR2; + private static final String SURROGATE2 = PAIR1 + PAIR2 + PAIR3; + + @Test + public void testSplitZero() { + assertTextArray("Empty string", ""); + assertTextArray("Empty entry", ","); + assertTextArray("Empty entry at beginning", ",a", "a"); + assertTextArray("Empty entry at end", "a,", "a"); + assertTextArray("Empty entry at middle", "a,,b", "a", "b"); + assertTextArray("Empty entries with escape", ",a,b\\,c,,d,", "a", "b\\,c", "d"); + } + + @Test + public void testSplitSingle() { + assertTextArray("Single char", "a", "a"); + assertTextArray("Surrogate pair", PAIR1, PAIR1); + assertTextArray("Single escape", "\\", "\\"); + assertTextArray("Space", " ", " "); + assertTextArray("Single label", "abc", "abc"); + assertTextArray("Single surrogate pairs label", SURROGATE2, SURROGATE2); + assertTextArray("Spaces", " ", " "); + assertTextArray("Spaces in label", "a b c", "a b c"); + assertTextArray("Spaces at beginning of label", " abc", " abc"); + assertTextArray("Spaces at end of label", "abc ", "abc "); + assertTextArray("Label surrounded by spaces", " abc ", " abc "); + assertTextArray("Surrogate pair surrounded by space", + " " + PAIR1 + " ", + " " + PAIR1 + " "); + assertTextArray("Surrogate pair within characters", + "ab" + PAIR2 + "cd", + "ab" + PAIR2 + "cd"); + assertTextArray("Surrogate pairs within characters", + "ab" + SURROGATE1 + "cd", + "ab" + SURROGATE1 + "cd"); + + assertTextArray("Incomplete resource reference 1", "text", "text"); + assertTextArray("Incomplete resource reference 2", "!text", "!text"); + assertTextArray("Incomplete RESOURCE REFERENCE 2", "!TEXT", "!TEXT"); + assertTextArray("Incomplete resource reference 3", "text/", "text/"); + assertTextArray("Incomplete resource reference 4", "!" + SURROGATE2, "!" + SURROGATE2); + } + + @Test + public void testSplitSingleEscaped() { + assertTextArray("Escaped char", "\\a", "\\a"); + assertTextArray("Escaped surrogate pair", "\\" + PAIR1, "\\" + PAIR1); + assertTextArray("Escaped comma", "\\,", "\\,"); + assertTextArray("Escaped comma escape", "a\\,\\", "a\\,\\"); + assertTextArray("Escaped escape", "\\\\", "\\\\"); + assertTextArray("Escaped label", "a\\bc", "a\\bc"); + assertTextArray("Escaped surrogate", "a\\" + PAIR1 + "c", "a\\" + PAIR1 + "c"); + assertTextArray("Escaped label at beginning", "\\abc", "\\abc"); + assertTextArray("Escaped surrogate at beginning", "\\" + SURROGATE2, "\\" + SURROGATE2); + assertTextArray("Escaped label at end", "abc\\", "abc\\"); + assertTextArray("Escaped surrogate at end", SURROGATE2 + "\\", SURROGATE2 + "\\"); + assertTextArray("Escaped label with comma", "a\\,c", "a\\,c"); + assertTextArray("Escaped surrogate with comma", + PAIR1 + "\\," + PAIR2, PAIR1 + "\\," + PAIR2); + assertTextArray("Escaped label with comma at beginning", "\\,bc", "\\,bc"); + assertTextArray("Escaped surrogate with comma at beginning", + "\\," + SURROGATE1, "\\," + SURROGATE1); + assertTextArray("Escaped label with comma at end", "ab\\,", "ab\\,"); + assertTextArray("Escaped surrogate with comma at end", + SURROGATE2 + "\\,", SURROGATE2 + "\\,"); + assertTextArray("Escaped label with successive", "\\,\\\\bc", "\\,\\\\bc"); + assertTextArray("Escaped surrogate with successive", + "\\,\\\\" + SURROGATE1, "\\,\\\\" + SURROGATE1); + assertTextArray("Escaped label with escape", "a\\\\c", "a\\\\c"); + assertTextArray("Escaped surrogate with escape", + PAIR1 + "\\\\" + PAIR2, PAIR1 + "\\\\" + PAIR2); + + assertTextArray("Escaped !text", "\\!text", "\\!text"); + assertTextArray("Escaped !text/", "\\!text/", "\\!text/"); + assertTextArray("Escaped !TEXT/", "\\!TEXT/", "\\!TEXT/"); + assertTextArray("Escaped !text/name", "\\!text/empty_string", "\\!text/empty_string"); + assertTextArray("Escaped !TEXT/NAME", "\\!TEXT/EMPTY_STRING", "\\!TEXT/EMPTY_STRING"); + } + + @Test + public void testSplitMulti() { + assertTextArray("Multiple chars", "a,b,c", "a", "b", "c"); + assertTextArray("Multiple chars", "a,b,\\c", "a", "b", "\\c"); + assertTextArray("Multiple chars and escape at beginning and end", + "\\a,b,\\c\\", "\\a", "b", "\\c\\"); + assertTextArray("Multiple surrogates", PAIR1 + "," + PAIR2 + "," + PAIR3, + PAIR1, PAIR2, PAIR3); + assertTextArray("Multiple chars surrounded by spaces", " a , b , c ", " a ", " b ", " c "); + assertTextArray("Multiple labels", "abc,def,ghi", "abc", "def", "ghi"); + assertTextArray("Multiple surrogated", SURROGATE1 + "," + SURROGATE2, + SURROGATE1, SURROGATE2); + assertTextArray("Multiple labels surrounded by spaces", " abc , def , ghi ", + " abc ", " def ", " ghi "); + } + + @Test + public void testSplitMultiEscaped() { + assertTextArray("Multiple chars with comma", "a,\\,,c", "a", "\\,", "c"); + assertTextArray("Multiple chars with comma surrounded by spaces", " a , \\, , c ", + " a ", " \\, ", " c "); + assertTextArray("Multiple labels with escape", + "\\abc,d\\ef,gh\\i", "\\abc", "d\\ef", "gh\\i"); + assertTextArray("Multiple labels with escape surrounded by spaces", + " \\abc , d\\ef , gh\\i ", " \\abc ", " d\\ef ", " gh\\i "); + assertTextArray("Multiple labels with comma and escape", + "ab\\\\,d\\\\\\,,g\\,i", "ab\\\\", "d\\\\\\,", "g\\,i"); + assertTextArray("Multiple labels with comma and escape surrounded by spaces", + " ab\\\\ , d\\\\\\, , g\\,i ", " ab\\\\ ", " d\\\\\\, ", " g\\,i "); + + assertTextArray("Multiple escaped !text", "\\!,\\!text/empty_string", + "\\!", "\\!text/empty_string"); + assertTextArray("Multiple escaped !TEXT", "\\!,\\!TEXT/EMPTY_STRING", + "\\!", "\\!TEXT/EMPTY_STRING"); + } + + @Test + public void testSplitTextReferenceError() { + assertError("Incomplete text name", "!text/", "!text/"); + assertError("Non existing text", "!text/non_existing"); + } + + @Test + public void testSplitEmptyTextReference() { + // Note that morekeys_q of English locale is empty. + assertTextArray("Empty string", "!text/morekeys_q"); + } + + @Test + public void testLabelReferece() { + assertTextArray("Label time am", "!text/keylabel_time_am", "AM"); + + assertTextArray("More keys for am pm", "!text/morekeys_am_pm", + "!fixedColumnOrder!2", "!hasLabels!", "AM", "PM"); + + assertTextArray("Settings as more key", "!text/keyspec_settings", + "!icon/settings_key|!code/key_settings"); + } + + @Test + public void testUselessUpperCaseSpecifier() { + assertTextArray("EMPTY STRING", + "!TEXT/EMPTY_STRING", "!TEXT/EMPTY_STRING"); + + assertTextArray("SINGLE CHAR", + "!TEXT/SINGLE_CHAR", "!TEXT/SINGLE_CHAR"); + assertTextArray("Escape and SINGLE CHAR", + "\\\\!TEXT/SINGLE_CHAR", "\\\\!TEXT/SINGLE_CHAR"); + + assertTextArray("MULTIPLE CHARS", + "!TEXT/MULTIPLE_CHARS", "!TEXT/MULTIPLE_CHARS"); + + assertTextArray("Literals and RESOURCES", + "1,!TEXT/MULTIPLE_CHARS,z", "1", "!TEXT/MULTIPLE_CHARS", "z"); + assertTextArray("Multiple single RESOURCE chars and LABELS 2", + "!TEXT/SINGLE_CHAR,!TEXT/SINGLE_LABEL,!TEXT/ESCAPED_COMMA_ESCAPE", + "!TEXT/SINGLE_CHAR", "!TEXT/SINGLE_LABEL", "!TEXT/ESCAPED_COMMA_ESCAPE"); + + assertTextArray("INDIRECT", + "!TEXT/INDIRECT_STRING", "!TEXT/INDIRECT_STRING"); + assertTextArray("INDIRECT with literal", + "1,!TEXT/INDIRECT_STRING_WITH_LITERAL,2", + "1", "!TEXT/INDIRECT_STRING_WITH_LITERAL", "2"); + assertTextArray("INDIRECT2", + "!TEXT/INDIRECT2_STRING", "!TEXT/INDIRECT2_STRING"); + + assertTextArray("UPPER INDIRECT", + "!TEXT/upper_INDIRECT_STRING", "!TEXT/upper_INDIRECT_STRING"); + assertTextArray("Upper INDIRECT with literal", + "1,!TEXT/upper_INDIRECT_STRING_WITH_LITERAL,2", + "1", "!TEXT/upper_INDIRECT_STRING_WITH_LITERAL", "2"); + assertTextArray("Upper INDIRECT2", + "!TEXT/upper_INDIRECT2_STRING", "!TEXT/upper_INDIRECT2_STRING"); + + assertTextArray("INFINITE INDIRECTION", + "1,!TEXT/INFINITE_INDIRECTION,2", "1", "!TEXT/INFINITE_INDIRECTION", "2"); + + assertTextArray("Upper INFINITE INDIRECTION", + "1,!TEXT/UPPER_INFINITE_INDIRECTION,2", + "1", "!TEXT/UPPER_INFINITE_INDIRECTION", "2"); + + assertTextArray("LABEL TIME AM", "!TEXT/LABEL_TIME_AM", "!TEXT/LABEL_TIME_AM"); + assertTextArray("MORE KEYS FOR AM OM", "!TEXT/MORE_KEYS_FOR_AM_PM", + "!TEXT/MORE_KEYS_FOR_AM_PM"); + assertTextArray("SETTINGS AS MORE KEY", "!TEXT/SETTINGS_AS_MORE_KEY", + "!TEXT/SETTINGS_AS_MORE_KEY"); + assertTextArray("INDIRECT NAVIGATE ACTIONS AS MORE KEY", + "!TEXT/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY", + "!TEXT/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecStringReferenceTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecStringReferenceTests.java new file mode 100644 index 000000000..0faf9cdc9 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecStringReferenceTests.java @@ -0,0 +1,307 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import android.app.Instrumentation; +import android.content.Context; +import android.content.res.Resources; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.tests.R; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class MoreKeySpecStringReferenceTests { + private static final Locale TEST_LOCALE = Locale.ENGLISH; + private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); + + @Before + public void setUp() throws Exception { + final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); + final Context testContext = instrumentation.getContext(); + final Resources testRes = testContext.getResources(); + final String testPackageName = testRes.getResourcePackageName(R.string.empty_string); + mTextsSet.setLocale(TEST_LOCALE, testRes, testPackageName); + } + + private void assertTextArray(final String message, final String value, + final String ... expectedArray) { + final String resolvedActual = mTextsSet.resolveTextReference(value); + final String[] actual = MoreKeySpec.splitKeySpecs(resolvedActual); + final String[] expected = (expectedArray.length == 0) ? null : expectedArray; + MoreKeySpecSplitTests.assertArrayEquals(message, expected, actual); + } + + private void assertError(final String message, final String value, final String ... expected) { + try { + assertTextArray(message, value, expected); + fail(message); + } catch (Exception pcpe) { + // success. + } + } + + @Test + public void testResolveNullText() { + assertEquals("resolve null", + mTextsSet.resolveTextReference(null), null); + } + + @Test + public void testResolveEmptyText() { + assertEquals("resolve empty text", + mTextsSet.resolveTextReference("!string/empty_string"), null); + } + + @Test + public void testSplitSingleEscaped() { + assertTextArray("Escaped !string", "\\!string", + "\\!string"); + assertTextArray("Escaped !string/", "\\!string/", + "\\!string/"); + assertTextArray("Escaped !STRING/", "\\!STRING/", + "\\!STRING/"); + assertTextArray("Escaped !string/name", "\\!string/empty_string", + "\\!string/empty_string"); + assertTextArray("Escaped !STRING/NAME", "\\!STRING/EMPTY_STRING", + "\\!STRING/EMPTY_STRING"); + } + + @Test + public void testSplitMultiEscaped() { + assertTextArray("Multiple escaped !string", "\\!,\\!string/empty_string", + "\\!", "\\!string/empty_string"); + assertTextArray("Multiple escaped !STRING", "\\!,\\!STRING/EMPTY_STRING", + "\\!", "\\!STRING/EMPTY_STRING"); + } + + @Test + public void testSplitStringReferenceError() { + assertError("Incomplete resource name", "!string/", "!string/"); + assertError("Non existing resource", "!string/non_existing"); + } + + @Test + public void testSplitEmptyStringReference() { + assertTextArray("Empty string", "!string/empty_string"); + } + + @Test + public void testSplitResourceSingle() { + assertTextArray("Single char", "!string/single_char", + "a"); + assertTextArray("Space", "!string/space", + " "); + assertTextArray("Single label", "!string/single_label", + "abc"); + assertTextArray("Spaces", "!string/spaces", + " "); + assertTextArray("Spaces in label", "!string/spaces_in_label", + "a b c"); + assertTextArray("Spaces at beginning of label", "!string/spaces_at_beginning_of_label", + " abc"); + assertTextArray("Spaces at end of label", "!string/spaces_at_end_of_label", + "abc "); + assertTextArray("label surrounded by spaces", "!string/label_surrounded_by_spaces", + " abc "); + assertTextArray("Escape and single char", "\\\\!string/single_char", + "\\\\a"); + } + + @Test + public void testSplitResourceSingleEscaped() { + assertTextArray("Escaped char", + "!string/escaped_char", "\\a"); + assertTextArray("Escaped comma", + "!string/escaped_comma", "\\,"); + assertTextArray("Escaped comma escape", + "!string/escaped_comma_escape", "a\\,\\"); + assertTextArray("Escaped escape", + "!string/escaped_escape", "\\\\"); + assertTextArray("Escaped label", + "!string/escaped_label", "a\\bc"); + assertTextArray("Escaped label at beginning", + "!string/escaped_label_at_beginning", "\\abc"); + assertTextArray("Escaped label at end", + "!string/escaped_label_at_end", "abc\\"); + assertTextArray("Escaped label with comma", + "!string/escaped_label_with_comma", "a\\,c"); + assertTextArray("Escaped label with comma at beginning", + "!string/escaped_label_with_comma_at_beginning", "\\,bc"); + assertTextArray("Escaped label with comma at end", + "!string/escaped_label_with_comma_at_end", "ab\\,"); + assertTextArray("Escaped label with successive", + "!string/escaped_label_with_successive", "\\,\\\\bc"); + assertTextArray("Escaped label with escape", + "!string/escaped_label_with_escape", "a\\\\c"); + } + + @Test + public void testSplitResourceMulti() { + assertTextArray("Multiple chars", + "!string/multiple_chars", "a", "b", "c"); + assertTextArray("Multiple chars surrounded by spaces", + "!string/multiple_chars_surrounded_by_spaces", + " a ", " b ", " c "); + assertTextArray("Multiple labels", + "!string/multiple_labels", "abc", "def", "ghi"); + assertTextArray("Multiple labels surrounded by spaces", + "!string/multiple_labels_surrounded_by_spaces", " abc ", " def ", " ghi "); + } + + @Test + public void testSplitResourcetMultiEscaped() { + assertTextArray("Multiple chars with comma", + "!string/multiple_chars_with_comma", + "a", "\\,", "c"); + assertTextArray("Multiple chars with comma surrounded by spaces", + "!string/multiple_chars_with_comma_surrounded_by_spaces", + " a ", " \\, ", " c "); + assertTextArray("Multiple labels with escape", + "!string/multiple_labels_with_escape", + "\\abc", "d\\ef", "gh\\i"); + assertTextArray("Multiple labels with escape surrounded by spaces", + "!string/multiple_labels_with_escape_surrounded_by_spaces", + " \\abc ", " d\\ef ", " gh\\i "); + assertTextArray("Multiple labels with comma and escape", + "!string/multiple_labels_with_comma_and_escape", + "ab\\\\", "d\\\\\\,", "g\\,i"); + assertTextArray("Multiple labels with comma and escape surrounded by spaces", + "!string/multiple_labels_with_comma_and_escape_surrounded_by_spaces", + " ab\\\\ ", " d\\\\\\, ", " g\\,i "); + } + + @Test + public void testSplitMultipleResources() { + assertTextArray("Literals and resources", + "1,!string/multiple_chars,z", + "1", "a", "b", "c", "z"); + assertTextArray("Literals and resources and escape at end", + "\\1,!string/multiple_chars,z\\", + "\\1", "a", "b", "c", "z\\"); + assertTextArray("Multiple single resource chars and labels", + "!string/single_char,!string/single_label,!string/escaped_comma", + "a", "abc", "\\,"); + assertTextArray("Multiple single resource chars and labels 2", + "!string/single_char,!string/single_label,!string/escaped_comma_escape", + "a", "abc", "a\\,\\"); + assertTextArray("Multiple multiple resource chars and labels", + "!string/multiple_chars,!string/multiple_labels,!string/multiple_chars_with_comma", + "a", "b", "c", "abc", "def", "ghi", "a", "\\,", "c"); + assertTextArray("Concatenated resources", + "!string/multiple_chars!string/multiple_labels!string/multiple_chars_with_comma", + "a", "b", "cabc", "def", "ghia", "\\,", "c"); + assertTextArray("Concatenated resource and literal", + "abc!string/multiple_labels", + "abcabc", "def", "ghi"); + } + + @Test + public void testSplitIndirectReference() { + assertTextArray("Indirect", + "!string/indirect_string", "a", "b", "c"); + assertTextArray("Indirect with literal", + "1,!string/indirect_string_with_literal,2", "1", "x", "a", "b", "c", "y", "2"); + assertTextArray("Indirect2", + "!string/indirect2_string", "a", "b", "c"); + } + + @Test + public void testSplitInfiniteIndirectReference() { + assertError("Infinite indirection", + "1,!string/infinite_indirection,2", "1", "infinite", "<infinite>", "loop", "2"); + } + + @Test + public void testLabelReferece() { + assertTextArray("Indirect naviagte actions as more key", + "!string/keyspec_indirect_navigate_actions", + "!fixedColumnOrder!2", + "!hasLabels!", "ActionPrevious|!code/key_action_previous", + "!hasLabels!", "ActionNext|!code/key_action_next"); + } + + @Test + public void testUselessUpperCaseSpecifier() { + assertTextArray("EMPTY STRING", + "!STRING/EMPTY_STRING", "!STRING/EMPTY_STRING"); + + assertTextArray("SINGLE CHAR", + "!STRING/SINGLE_CHAR", "!STRING/SINGLE_CHAR"); + assertTextArray("Escape and SINGLE CHAR", + "\\\\!STRING/SINGLE_CHAR", "\\\\!STRING/SINGLE_CHAR"); + + assertTextArray("MULTIPLE CHARS", + "!STRING/MULTIPLE_CHARS", "!STRING/MULTIPLE_CHARS"); + + assertTextArray("Literals and RESOURCES", + "1,!STRING/MULTIPLE_CHARS,z", "1", "!STRING/MULTIPLE_CHARS", "z"); + assertTextArray("Multiple single RESOURCE chars and LABELS 2", + "!STRING/SINGLE_CHAR,!STRING/SINGLE_LABEL,!STRING/ESCAPED_COMMA_ESCAPE", + "!STRING/SINGLE_CHAR", "!STRING/SINGLE_LABEL", "!STRING/ESCAPED_COMMA_ESCAPE"); + + assertTextArray("INDIRECT", + "!STRING/INDIRECT_STRING", "!STRING/INDIRECT_STRING"); + assertTextArray("INDIRECT with literal", + "1,!STRING/INDIRECT_STRING_WITH_LITERAL,2", + "1", "!STRING/INDIRECT_STRING_WITH_LITERAL", "2"); + assertTextArray("INDIRECT2", + "!STRING/INDIRECT2_STRING", "!STRING/INDIRECT2_STRING"); + + assertTextArray("Upper indirect", + "!string/upper_indirect_string", "!STRING/MULTIPLE_CHARS"); + assertTextArray("Upper indirect with literal", + "1,!string/upper_indirect_string_with_literal,2", + "1", "x", "!STRING/MULTIPLE_CHARS", "y", "2"); + assertTextArray("Upper indirect2", + "!string/upper_indirect2_string", "!STRING/UPPER_INDIRECT_STRING"); + + assertTextArray("UPPER INDIRECT", + "!STRING/upper_INDIRECT_STRING", "!STRING/upper_INDIRECT_STRING"); + assertTextArray("Upper INDIRECT with literal", + "1,!STRING/upper_INDIRECT_STRING_WITH_LITERAL,2", + "1", "!STRING/upper_INDIRECT_STRING_WITH_LITERAL", "2"); + assertTextArray("Upper INDIRECT2", + "!STRING/upper_INDIRECT2_STRING", "!STRING/upper_INDIRECT2_STRING"); + + assertTextArray("INFINITE INDIRECTION", + "1,!STRING/INFINITE_INDIRECTION,2", "1", "!STRING/INFINITE_INDIRECTION", "2"); + + assertTextArray("Upper infinite indirection", + "1,!string/upper_infinite_indirection,2", + "1", "infinite", "!STRING/INFINITE_INDIRECTION", "loop", "2"); + assertTextArray("Upper INFINITE INDIRECTION", + "1,!STRING/UPPER_INFINITE_INDIRECTION,2", + "1", "!STRING/UPPER_INFINITE_INDIRECTION", "2"); + + assertTextArray("INDIRECT NAVIGATE ACTIONS AS MORE KEY", + "!STRING/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY", + "!STRING/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecTests.java new file mode 100644 index 000000000..b56308f5d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/MoreKeySpecTests.java @@ -0,0 +1,378 @@ +/* + * Copyright (C) 2010 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 org.kelar.inputmethod.keyboard.internal; + +import static org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UNDEFINED; +import static org.kelar.inputmethod.latin.common.Constants.CODE_UNSPECIFIED; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Arrays; +import java.util.Locale; + +@SmallTest +public final class MoreKeySpecTests extends KeySpecParserTestsBase { + @Override + protected void assertParser(final String message, final String moreKeySpec, + final String expectedLabel, final String expectedOutputText, final int expectedIconId, + final int expectedCode) { + final String labelResolved = mTextsSet.resolveTextReference(moreKeySpec); + final MoreKeySpec spec = new MoreKeySpec( + labelResolved, false /* needsToUpperCase */, Locale.US); + assertEquals(message + " [label]", expectedLabel, spec.mLabel); + assertEquals(message + " [ouptputText]", expectedOutputText, spec.mOutputText); + assertEquals(message + " [icon]", + KeyboardIconsSet.getIconName(expectedIconId), + KeyboardIconsSet.getIconName(spec.mIconId)); + assertEquals(message + " [code]", + Constants.printableCode(expectedCode), + Constants.printableCode(spec.mCode)); + } + + // TODO: Move this method to {@link KeySpecParserBase}. + public void testEmptySpec() { + assertParserError("Null spec", null, + null, null, ICON_UNDEFINED, CODE_UNSPECIFIED); + assertParserError("Empty spec", "", + null, null, ICON_UNDEFINED, CODE_UNSPECIFIED); + } + + private static void assertArrayEquals(final String message, final Object[] expected, + final Object[] actual) { + if (expected == actual) { + return; + } + if (expected == null || actual == null) { + assertEquals(message, Arrays.toString(expected), Arrays.toString(actual)); + return; + } + if (expected.length != actual.length) { + assertEquals(message + " [length]", Arrays.toString(expected), Arrays.toString(actual)); + return; + } + for (int i = 0; i < expected.length; i++) { + assertEquals(message + " [" + i + "]", + Arrays.toString(expected), Arrays.toString(actual)); + } + } + + private static void assertInsertAdditionalMoreKeys(final String message, + final String[] moreKeys, final String[] additionalMoreKeys, final String[] expected) { + final String[] actual = MoreKeySpec.insertAdditionalMoreKeys(moreKeys, additionalMoreKeys); + assertArrayEquals(message, expected, actual); + } + + @SuppressWarnings("static-method") + public void testEmptyEntry() { + assertInsertAdditionalMoreKeys("null more keys and null additons", + null, + null, + null); + assertInsertAdditionalMoreKeys("null more keys and empty additons", + null, + new String[0], + null); + assertInsertAdditionalMoreKeys("empty more keys and null additons", + new String[0], + null, + null); + assertInsertAdditionalMoreKeys("empty more keys and empty additons", + new String[0], + new String[0], + null); + + assertInsertAdditionalMoreKeys("filter out empty more keys", + new String[] { null, "a", "", "b", null }, + null, + new String[] { "a", "b" }); + assertInsertAdditionalMoreKeys("filter out empty additons", + new String[] { "a", "%", "b", "%", "c", "%", "d" }, + new String[] { null, "A", "", "B", null }, + new String[] { "a", "A", "b", "B", "c", "d" }); + } + + @SuppressWarnings("static-method") + public void testInsertAdditionalMoreKeys() { + // Escaped marker. + assertInsertAdditionalMoreKeys("escaped marker", + new String[] { "\\%", "%-)" }, + new String[] { "1", "2" }, + new String[] { "1", "2", "\\%", "%-)" }); + + // 0 more key. + assertInsertAdditionalMoreKeys("null & null", null, null, null); + assertInsertAdditionalMoreKeys("null & 1 additon", + null, + new String[] { "1" }, + new String[] { "1" }); + assertInsertAdditionalMoreKeys("null & 2 additons", + null, + new String[] { "1", "2" }, + new String[] { "1", "2" }); + + // 0 additional more key. + assertInsertAdditionalMoreKeys("1 more key & null", + new String[] { "A" }, + null, + new String[] { "A" }); + assertInsertAdditionalMoreKeys("2 more keys & null", + new String[] { "A", "B" }, + null, + new String[] { "A", "B" }); + + // No marker. + assertInsertAdditionalMoreKeys("1 more key & 1 addtional & no marker", + new String[] { "A" }, + new String[] { "1" }, + new String[] { "1", "A" }); + assertInsertAdditionalMoreKeys("1 more key & 2 addtionals & no marker", + new String[] { "A" }, + new String[] { "1", "2" }, + new String[] { "1", "2", "A" }); + assertInsertAdditionalMoreKeys("2 more keys & 1 addtional & no marker", + new String[] { "A", "B" }, + new String[] { "1" }, + new String[] { "1", "A", "B" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 addtionals & no marker", + new String[] { "A", "B" }, + new String[] { "1", "2" }, + new String[] { "1", "2", "A", "B" }); + + // 1 marker. + assertInsertAdditionalMoreKeys("1 more key & 1 additon & marker at head", + new String[] { "%", "A" }, + new String[] { "1" }, + new String[] { "1", "A" }); + assertInsertAdditionalMoreKeys("1 more key & 1 additon & marker at tail", + new String[] { "A", "%" }, + new String[] { "1" }, + new String[] { "A", "1" }); + assertInsertAdditionalMoreKeys("2 more keys & 1 additon & marker at middle", + new String[] { "A", "%", "B" }, + new String[] { "1" }, + new String[] { "A", "1", "B" }); + + // 1 marker & excess additional more keys. + assertInsertAdditionalMoreKeys("1 more key & 2 additons & marker at head", + new String[] { "%", "A", "B" }, + new String[] { "1", "2" }, + new String[] { "1", "A", "B", "2" }); + assertInsertAdditionalMoreKeys("1 more key & 2 additons & marker at tail", + new String[] { "A", "B", "%" }, + new String[] { "1", "2" }, + new String[] { "A", "B", "1", "2" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 additons & marker at middle", + new String[] { "A", "%", "B" }, + new String[] { "1", "2" }, + new String[] { "A", "1", "B", "2" }); + + // 2 markers. + assertInsertAdditionalMoreKeys("0 more key & 2 addtional & 2 markers", + new String[] { "%", "%" }, + new String[] { "1", "2" }, + new String[] { "1", "2" }); + assertInsertAdditionalMoreKeys("1 more key & 2 addtional & 2 markers at head", + new String[] { "%", "%", "A" }, + new String[] { "1", "2" }, + new String[] { "1", "2", "A" }); + assertInsertAdditionalMoreKeys("1 more key & 2 addtional & 2 markers at tail", + new String[] { "A", "%", "%" }, + new String[] { "1", "2" }, + new String[] { "A", "1", "2" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 addtional & 2 markers at middle", + new String[] { "A", "%", "%", "B" }, + new String[] { "1", "2" }, + new String[] { "A", "1", "2", "B" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 addtional & 2 markers at head & middle", + new String[] { "%", "A", "%", "B" }, + new String[] { "1", "2" }, + new String[] { "1", "A", "2", "B" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 addtional & 2 markers at head & tail", + new String[] { "%", "A", "B", "%" }, + new String[] { "1", "2" }, + new String[] { "1", "A", "B", "2" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 addtional & 2 markers at middle & tail", + new String[] { "A", "%", "B", "%" }, + new String[] { "1", "2" }, + new String[] { "A", "1", "B", "2" }); + + // 2 markers & excess additional more keys. + assertInsertAdditionalMoreKeys("0 more key & 2 additons & 2 markers", + new String[] { "%", "%" }, + new String[] { "1", "2", "3" }, + new String[] { "1", "2", "3" }); + assertInsertAdditionalMoreKeys("1 more key & 2 additons & 2 markers at head", + new String[] { "%", "%", "A" }, + new String[] { "1", "2", "3" }, + new String[] { "1", "2", "A", "3" }); + assertInsertAdditionalMoreKeys("1 more key & 2 additons & 2 markers at tail", + new String[] { "A", "%", "%" }, + new String[] { "1", "2", "3" }, + new String[] { "A", "1", "2", "3" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 additons & 2 markers at middle", + new String[] { "A", "%", "%", "B" }, + new String[] { "1", "2", "3" }, + new String[] { "A", "1", "2", "B", "3" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 additons & 2 markers at head & middle", + new String[] { "%", "A", "%", "B" }, + new String[] { "1", "2", "3" }, + new String[] { "1", "A", "2", "B", "3" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 additons & 2 markers at head & tail", + new String[] { "%", "A", "B", "%" }, + new String[] { "1", "2", "3" }, + new String[] { "1", "A", "B", "2", "3" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 additons & 2 markers at middle & tail", + new String[] { "A", "%", "B", "%" }, + new String[] { "1", "2", "3" }, + new String[] { "A", "1", "B", "2", "3" }); + + // 0 addtional more key and excess markers. + assertInsertAdditionalMoreKeys("0 more key & null & excess marker", + new String[] { "%" }, + null, + null); + assertInsertAdditionalMoreKeys("1 more key & null & excess marker at head", + new String[] { "%", "A" }, + null, + new String[] { "A" }); + assertInsertAdditionalMoreKeys("1 more key & null & excess marker at tail", + new String[] { "A", "%" }, + null, + new String[] { "A" }); + assertInsertAdditionalMoreKeys("2 more keys & null & excess marker at middle", + new String[] { "A", "%", "B" }, + null, + new String[] { "A", "B" }); + assertInsertAdditionalMoreKeys("2 more keys & null & excess markers", + new String[] { "%", "A", "%", "B", "%" }, + null, + new String[] { "A", "B" }); + + // Excess markers. + assertInsertAdditionalMoreKeys("0 more key & 1 additon & excess marker", + new String[] { "%", "%" }, + new String[] { "1" }, + new String[] { "1" }); + assertInsertAdditionalMoreKeys("1 more key & 1 additon & excess marker at head", + new String[] { "%", "%", "A" }, + new String[] { "1" }, + new String[] { "1", "A" }); + assertInsertAdditionalMoreKeys("1 more key & 1 additon & excess marker at tail", + new String[] { "A", "%", "%" }, + new String[] { "1" }, + new String[] { "A", "1" }); + assertInsertAdditionalMoreKeys("2 more keys & 1 additon & excess marker at middle", + new String[] { "A", "%", "%", "B" }, + new String[] { "1" }, + new String[] { "A", "1", "B" }); + assertInsertAdditionalMoreKeys("2 more keys & 1 additon & excess markers", + new String[] { "%", "A", "%", "B", "%" }, + new String[] { "1" }, + new String[] { "1", "A", "B" }); + assertInsertAdditionalMoreKeys("2 more keys & 2 additons & excess markers", + new String[] { "%", "A", "%", "B", "%" }, + new String[] { "1", "2" }, + new String[] { "1", "A", "2", "B" }); + assertInsertAdditionalMoreKeys("2 more keys & 3 additons & excess markers", + new String[] { "%", "A", "%", "%", "B", "%" }, + new String[] { "1", "2", "3" }, + new String[] { "1", "A", "2", "3", "B" }); + } + + private static final String HAS_LABEL = "!hasLabel!"; + private static final String NEEDS_DIVIDER = "!needsDividers!"; + private static final String AUTO_COLUMN_ORDER = "!autoColumnOrder!"; + private static final String FIXED_COLUMN_ORDER = "!fixedColumnOrder!"; + + private static void assertGetBooleanValue(final String message, final String key, + final String[] moreKeys, final String[] expected, final boolean expectedValue) { + final String[] actual = Arrays.copyOf(moreKeys, moreKeys.length); + final boolean actualValue = MoreKeySpec.getBooleanValue(actual, key); + assertEquals(message + " [value]", expectedValue, actualValue); + assertArrayEquals(message, expected, actual); + } + + @SuppressWarnings("static-method") + public void testGetBooleanValue() { + assertGetBooleanValue("Has label", HAS_LABEL, + new String[] { HAS_LABEL, "a", "b", "c" }, + new String[] { null, "a", "b", "c" }, true); + // Upper case specification will not work. + assertGetBooleanValue("HAS LABEL", HAS_LABEL, + new String[] { HAS_LABEL.toUpperCase(Locale.ROOT), "a", "b", "c" }, + new String[] { "!HASLABEL!", "a", "b", "c" }, false); + + assertGetBooleanValue("No has label", HAS_LABEL, + new String[] { "a", "b", "c" }, + new String[] { "a", "b", "c" }, false); + assertGetBooleanValue("No has label with fixed clumn order", HAS_LABEL, + new String[] { FIXED_COLUMN_ORDER + "3", "a", "b", "c" }, + new String[] { FIXED_COLUMN_ORDER + "3", "a", "b", "c" }, false); + + // Upper case specification will not work. + assertGetBooleanValue("Multiple has label", HAS_LABEL, + new String[] { + "a", HAS_LABEL.toUpperCase(Locale.ROOT), "b", "c", HAS_LABEL, "d" }, + new String[] { + "a", "!HASLABEL!", "b", "c", null, "d" }, true); + // Upper case specification will not work. + assertGetBooleanValue("Multiple has label with needs dividers", HAS_LABEL, + new String[] { + "a", HAS_LABEL, "b", NEEDS_DIVIDER, HAS_LABEL.toUpperCase(Locale.ROOT), "d" }, + new String[] { + "a", null, "b", NEEDS_DIVIDER, "!HASLABEL!", "d" }, true); + } + + private static void assertGetIntValue(final String message, final String key, + final int defaultValue, final String[] moreKeys, final String[] expected, + final int expectedValue) { + final String[] actual = Arrays.copyOf(moreKeys, moreKeys.length); + final int actualValue = MoreKeySpec.getIntValue(actual, key, defaultValue); + assertEquals(message + " [value]", expectedValue, actualValue); + assertArrayEquals(message, expected, actual); + } + + @SuppressWarnings("static-method") + public void testGetIntValue() { + assertGetIntValue("Fixed column order 3", FIXED_COLUMN_ORDER, -1, + new String[] { FIXED_COLUMN_ORDER + "3", "a", "b", "c" }, + new String[] { null, "a", "b", "c" }, 3); + // Upper case specification will not work. + assertGetIntValue("FIXED COLUMN ORDER 3", FIXED_COLUMN_ORDER, -1, + new String[] { FIXED_COLUMN_ORDER.toUpperCase(Locale.ROOT) + "3", "a", "b", "c" }, + new String[] { "!FIXEDCOLUMNORDER!3", "a", "b", "c" }, -1); + + assertGetIntValue("No fixed column order", FIXED_COLUMN_ORDER, -1, + new String[] { "a", "b", "c" }, + new String[] { "a", "b", "c" }, -1); + assertGetIntValue("No fixed column order with auto column order", FIXED_COLUMN_ORDER, -1, + new String[] { AUTO_COLUMN_ORDER + "5", "a", "b", "c" }, + new String[] { AUTO_COLUMN_ORDER + "5", "a", "b", "c" }, -1); + + assertGetIntValue("Multiple fixed column order 3,5", FIXED_COLUMN_ORDER, -1, + new String[] { FIXED_COLUMN_ORDER + "3", "a", FIXED_COLUMN_ORDER + "5", "b" }, + new String[] { null, "a", null, "b" }, 3); + // Upper case specification will not work. + assertGetIntValue("Multiple fixed column order 5,3 with has label", FIXED_COLUMN_ORDER, -1, + new String[] { + FIXED_COLUMN_ORDER.toUpperCase(Locale.ROOT) + "5", HAS_LABEL, "a", + FIXED_COLUMN_ORDER + "3", "b" }, + new String[] { "!FIXEDCOLUMNORDER!5", HAS_LABEL, "a", null, "b" }, 3); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/PointerTrackerQueueTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/PointerTrackerQueueTests.java new file mode 100644 index 000000000..e491ca955 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/PointerTrackerQueueTests.java @@ -0,0 +1,342 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class PointerTrackerQueueTests { + public static class Element implements PointerTrackerQueue.Element { + public static int sPhantomUpCount; + public static final long NOT_HAPPENED = -1; + + public final int mId; + public boolean mIsModifier; + public boolean mIsInDraggingFinger; + public long mPhantomUpEventTime = NOT_HAPPENED; + + public Element(int id) { + mId = id; + } + + @Override + public boolean isModifier() { + return mIsModifier; + } + + @Override + public boolean isInDraggingFinger() { + return mIsInDraggingFinger; + } + + @Override + public void onPhantomUpEvent(long eventTime) { + sPhantomUpCount++; + mPhantomUpEventTime = eventTime + sPhantomUpCount; + } + + @Override + public void cancelTrackingForAction() {} + + @Override + public String toString() { + return Integer.toString(mId); + } + } + + private final Element mElement1 = new Element(1); + private final Element mElement2 = new Element(2); + private final Element mElement3 = new Element(3); + private final Element mElement4 = new Element(4); + private final PointerTrackerQueue mQueue = new PointerTrackerQueue(); + + @Test + public void testEmpty() { + assertEquals(0, mQueue.size()); + assertEquals("[]", mQueue.toString()); + } + + @Test + public void testAdd() { + mQueue.add(mElement1); + assertEquals(1, mQueue.size()); + assertEquals("[1]", mQueue.toString()); + mQueue.add(mElement2); + assertEquals(2, mQueue.size()); + assertEquals("[1 2]", mQueue.toString()); + mQueue.add(mElement3); + assertEquals(3, mQueue.size()); + assertEquals("[1 2 3]", mQueue.toString()); + mQueue.add(mElement4); + assertEquals(4, mQueue.size()); + assertEquals("[1 2 3 4]", mQueue.toString()); + } + + @Test + public void testRemove() { + Element.sPhantomUpCount = 0; + + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + mQueue.remove(mElement2); + assertEquals(3, mQueue.size()); + assertEquals("[1 3 4]", mQueue.toString()); + mQueue.remove(mElement4); + assertEquals(2, mQueue.size()); + assertEquals("[1 3]", mQueue.toString()); + mQueue.remove(mElement4); + assertEquals(2, mQueue.size()); + assertEquals("[1 3]", mQueue.toString()); + mQueue.remove(mElement1); + assertEquals(1, mQueue.size()); + assertEquals("[3]", mQueue.toString()); + mQueue.remove(mElement3); + assertEquals(0, mQueue.size()); + assertEquals("[]", mQueue.toString()); + mQueue.remove(mElement1); + assertEquals(0, mQueue.size()); + assertEquals("[]", mQueue.toString()); + + assertEquals(0, Element.sPhantomUpCount); + assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime); + } + + @Test + public void testAddAndRemove() { + Element.sPhantomUpCount = 0; + + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + mQueue.remove(mElement2); + assertEquals(3, mQueue.size()); + assertEquals("[1 3 4]", mQueue.toString()); + mQueue.remove(mElement4); + assertEquals(2, mQueue.size()); + assertEquals("[1 3]", mQueue.toString()); + mQueue.add(mElement2); + assertEquals(3, mQueue.size()); + assertEquals("[1 3 2]", mQueue.toString()); + mQueue.remove(mElement4); + assertEquals(3, mQueue.size()); + assertEquals("[1 3 2]", mQueue.toString()); + mQueue.remove(mElement1); + assertEquals(2, mQueue.size()); + assertEquals("[3 2]", mQueue.toString()); + mQueue.add(mElement1); + assertEquals(3, mQueue.size()); + assertEquals("[3 2 1]", mQueue.toString()); + mQueue.remove(mElement3); + assertEquals(2, mQueue.size()); + assertEquals("[2 1]", mQueue.toString()); + mQueue.remove(mElement1); + assertEquals(1, mQueue.size()); + assertEquals("[2]", mQueue.toString()); + + assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime); + } + + @Test + public void testReleaseAllPointers() { + mElement2.mIsModifier = true; + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + final long eventTime = 123; + Element.sPhantomUpCount = 0; + mQueue.releaseAllPointers(eventTime); + assertEquals(4, Element.sPhantomUpCount); + assertEquals(0, mQueue.size()); + assertEquals("[]", mQueue.toString()); + assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime); + assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime); + assertEquals(eventTime + 3, mElement3.mPhantomUpEventTime); + assertEquals(eventTime + 4, mElement4.mPhantomUpEventTime); + } + + @Test + public void testReleaseAllPointersOlderThanFirst() { + mElement2.mIsModifier = true; + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + + final long eventTime = 123; + Element.sPhantomUpCount = 0; + mQueue.releaseAllPointersOlderThan(mElement1, eventTime); + assertEquals(0, Element.sPhantomUpCount); + assertEquals(3, mQueue.size()); + assertEquals("[1 2 3]", mQueue.toString()); + assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime); + } + + @Test + public void testReleaseAllPointersOlderThanLast() { + mElement2.mIsModifier = true; + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + final long eventTime = 123; + Element.sPhantomUpCount = 0; + mQueue.releaseAllPointersOlderThan(mElement4, eventTime); + assertEquals(2, Element.sPhantomUpCount); + assertEquals(2, mQueue.size()); + assertEquals("[2 4]", mQueue.toString()); + assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); + assertEquals(eventTime + 2, mElement3.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime); + } + + @Test + public void testReleaseAllPointersOlderThanWithoutModifierMiddle() { + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + final long eventTime = 123; + Element.sPhantomUpCount = 0; + mQueue.releaseAllPointersOlderThan(mElement3, eventTime); + assertEquals(2, Element.sPhantomUpCount); + assertEquals(2, mQueue.size()); + assertEquals("[3 4]", mQueue.toString()); + assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime); + assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime); + } + + @Test + public void testReleaseAllPointersOlderThanWithoutModifierLast() { + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + final long eventTime = 123; + Element.sPhantomUpCount = 0; + mQueue.releaseAllPointersOlderThan(mElement4, eventTime); + assertEquals(3, Element.sPhantomUpCount); + assertEquals(1, mQueue.size()); + assertEquals("[4]", mQueue.toString()); + assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime); + assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime); + assertEquals(eventTime + 3, mElement3.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime); + } + + @Test + public void testReleaseAllPointersExcept() { + mElement2.mIsModifier = true; + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + final long eventTime = 123; + Element.sPhantomUpCount = 0; + mQueue.releaseAllPointersExcept(mElement3, eventTime); + assertEquals(3, Element.sPhantomUpCount); + assertEquals(1, mQueue.size()); + assertEquals("[3]", mQueue.toString()); + assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime); + assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime); + assertEquals(eventTime + 3, mElement4.mPhantomUpEventTime); + } + + @Test + public void testHasModifierKeyOlderThan() { + Element.sPhantomUpCount = 0; + assertFalse("hasModifierKeyOlderThan empty", mQueue.hasModifierKeyOlderThan(mElement1)); + + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + assertFalse(mQueue.hasModifierKeyOlderThan(mElement1)); + assertFalse(mQueue.hasModifierKeyOlderThan(mElement2)); + assertFalse(mQueue.hasModifierKeyOlderThan(mElement3)); + assertFalse(mQueue.hasModifierKeyOlderThan(mElement4)); + + mElement2.mIsModifier = true; + assertFalse(mQueue.hasModifierKeyOlderThan(mElement1)); + assertFalse(mQueue.hasModifierKeyOlderThan(mElement2)); + assertTrue(mQueue.hasModifierKeyOlderThan(mElement3)); + assertTrue(mQueue.hasModifierKeyOlderThan(mElement4)); + + assertEquals(0, Element.sPhantomUpCount); + assertEquals(4, mQueue.size()); + assertEquals("[1 2 3 4]", mQueue.toString()); + assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime); + } + + @Test + public void testIsAnyInDraggingFinger() { + Element.sPhantomUpCount = 0; + assertFalse(mQueue.isAnyInDraggingFinger()); + + mQueue.add(mElement1); + mQueue.add(mElement2); + mQueue.add(mElement3); + mQueue.add(mElement4); + + assertFalse(mQueue.isAnyInDraggingFinger()); + + mElement3.mIsInDraggingFinger = true; + assertTrue(mQueue.isAnyInDraggingFinger()); + + assertEquals(0, Element.sPhantomUpCount); + assertEquals(4, mQueue.size()); + assertEquals("[1 2 3 4]", mQueue.toString()); + assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime); + assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/internal/SmoothingUtilsTests.java b/tests/src/org/kelar/inputmethod/keyboard/internal/SmoothingUtilsTests.java new file mode 100644 index 000000000..4de2dda81 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/internal/SmoothingUtilsTests.java @@ -0,0 +1,53 @@ +/* + * 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 org.kelar.inputmethod.keyboard.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.keyboard.internal.MatrixUtils.MatrixOperationFailedException; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SmoothingUtilsTests { + // "run tests" -c org.kelar.inputmethod.keyboard.internal.SmoothingUtilsTests + private static final boolean DEBUG = false; + + @Test + public void testGet3DParamaters() { + final float[] xs = new float[] {0, 1, 2, 3, 4}; + final float[] ys = new float[] {1, 4, 15, 40, 85}; // y = x^3 + x^2 + x + 1 + final float[][] retval = new float[4][1]; + try { + SmoothingUtils.get3DParameters(xs, ys, retval); + if (DEBUG) { + MatrixUtils.dump("3d", retval); + } + for (int i = 0; i < 4; ++i) { + assertEquals(retval[i][0], 1.0f, 0.001f); + } + } catch (MatrixOperationFailedException e) { + assertTrue(false); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Arabic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Arabic.java new file mode 100644 index 000000000..c0d267a0a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Arabic.java @@ -0,0 +1,349 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.Symbols.RtlSymbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted.RtlSymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public final class Arabic extends LayoutBase { + private static final String LAYOUT_NAME = "arabic"; + + public Arabic(final Locale locale) { + super(new ArabicCustomizer(locale), ArabicSymbols.class, ArabicSymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class ArabicCustomizer extends LayoutCustomizer { + ArabicCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return ARABIC_ALPHABET_KEY; } + + @Override + public ExpectedKey getSymbolsKey() { return ARABIC_SYMBOLS_KEY; } + + @Override + public ExpectedKey getBackToSymbolsKey() { return ARABIC_BACK_TO_SYMBOLS_KEY; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { + return RtlSymbols.DOUBLE_ANGLE_QUOTES_LR_RTL; + } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { + return RtlSymbols.SINGLE_ANGLE_QUOTES_LR_RTL; + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + if (isPhone) { + // U+060C: "،" ARABIC COMMA + return joinKeys(key("\u060C", SETTINGS_KEY)); + } + // U+060C: "،" ARABIC COMMA + // U+061F: "؟" ARABIC QUESTION MARK + // U+061B: "؛" ARABIC SEMICOLON + return joinKeys(key("\u060C", joinMoreKeys( + ":", "!", "\u061F", "\u061B", "-", "\"", "'", SETTINGS_KEY))); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + if (isPhone) { + return super.getKeysRightToSpacebar(isPhone); + } + // U+060C: "،" ARABIC COMMA + // U+061F: "؟" ARABIC QUESTION MARK + // U+061B: "؛" ARABIC SEMICOLON + return joinKeys(key(".", getPunctuationMoreKeys(isPhone))); + } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return ARABIC_DIACRITICS; + } + + // U+0623: "أ" ARABIC LETTER ALEF WITH HAMZA ABOVE + // U+200C: ZERO WIDTH NON-JOINER + // U+0628: "ب" ARABIC LETTER BEH + // U+062C: "ج" ARABIC LETTER JEEM + private static final ExpectedKey ARABIC_ALPHABET_KEY = key( + "\u0623\u200C\u0628\u200C\u062C", Constants.CODE_SWITCH_ALPHA_SYMBOL); + // U+0663: "٣" ARABIC-INDIC DIGIT THREE + // U+0662: "٢" ARABIC-INDIC DIGIT TWO + // U+0661: "١" ARABIC-INDIC DIGIT ONE + // U+061F: "؟" ARABIC QUESTION MARK + private static final ExpectedKey ARABIC_SYMBOLS_KEY = key( + "\u0663\u0662\u0661\u061F", Constants.CODE_SWITCH_ALPHA_SYMBOL); + private static final ExpectedKey ARABIC_BACK_TO_SYMBOLS_KEY = key( + "\u0663\u0662\u0661\u061F", Constants.CODE_SHIFT); + + private static final ExpectedKey[] ARABIC_DIACRITICS = { + // U+0655: "ٕ" ARABIC HAMZA BELOW + // U+0654: "ٔ" ARABIC HAMZA ABOVE + // U+0652: "ْ" ARABIC SUKUN + // U+064D: "ٍ" ARABIC KASRATAN + // U+064C: "ٌ" ARABIC DAMMATAN + // U+064B: "ً" ARABIC FATHATAN + // U+0651: "ّ" ARABIC SHADDA + // U+0656: "ٖ" ARABIC SUBSCRIPT ALEF + // U+0670: "ٰ" ARABIC LETTER SUPERSCRIPT ALEF + // U+0653: "ٓ" ARABIC MADDAH ABOVE + // U+0650: "ِ" ARABIC KASRA + // U+064F: "ُ" ARABIC DAMMA + // U+064E: "َ" ARABIC FATHA + // U+0640: "ـ" ARABIC TATWEEL + moreKey(" \u0655", "\u0655"), moreKey(" \u0654", "\u0654"), + moreKey(" \u0652", "\u0652"), moreKey(" \u064D", "\u064D"), + moreKey(" \u064C", "\u064C"), moreKey(" \u064B", "\u064B"), + moreKey(" \u0651", "\u0651"), moreKey(" \u0656", "\u0656"), + moreKey(" \u0670", "\u0670"), moreKey(" \u0653", "\u0653"), + moreKey(" \u0650", "\u0650"), moreKey(" \u064F", "\u064F"), + moreKey(" \u064E", "\u064E"), moreKey("\u0640\u0640\u0640", "\u0640") + }; + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + if (isPhone) { + return ALPHABET_COMMON; + } + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + // U+0626: "ئ" ARABIC LETTER YEH WITH HAMZA ABOVE + builder.insertKeysAtRow(3, 2, "\u0626"); + return builder.build(); + } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0636: "ض" ARABIC LETTER DAD + // U+0661: "١" ARABIC-INDIC DIGIT ONE + key("\u0636", joinMoreKeys("1", "\u0661")), + // U+0635: "ص" ARABIC LETTER SAD + // U+0662: "٢" ARABIC-INDIC DIGIT TWO + key("\u0635", joinMoreKeys("2", "\u0662")), + // U+062B: "ث" ARABIC LETTER THEH + // U+0663: "٣" ARABIC-INDIC DIGIT THREE + key("\u062B", joinMoreKeys("3", "\u0663")), + // U+0642: "ق" ARABIC LETTER QAF + // U+0664: "٤" ARABIC-INDIC DIGIT FOUR + // U+06A8: "ڨ" ARABIC LETTER QAF WITH THREE DOTS ABOVE + key("\u0642", joinMoreKeys("4", "\u0664", "\u06A8")), + // U+0641: "ف" ARABIC LETTER FEH + // U+0665: "٥" ARABIC-INDIC DIGIT FIVE + // U+06A4: "ڤ" ARABIC LETTER VEH + // U+06A2: "ڢ" ARABIC LETTER FEH WITH DOT MOVED BELOW + // U+06A5: "ڥ" ARABIC LETTER FEH WITH THREE DOTS BELOW + key("\u0641", joinMoreKeys("5", "\u0665", "\u06A4", "\u06A2", "\u06A5")), + // U+063A: "غ" ARABIC LETTER GHAIN + // U+0666: "٦" ARABIC-INDIC DIGIT SIX + key("\u063A", joinMoreKeys("6", "\u0666")), + // U+0639: "ع" ARABIC LETTER AIN + // U+0667: "٧" ARABIC-INDIC DIGIT SEVEN + key("\u0639", joinMoreKeys("7", "\u0667")), + // U+0647: "ه" ARABIC LETTER HEH + // U+0668: "٨" ARABIC-INDIC DIGIT EIGHT + // U+FEEB: "ﻫ" ARABIC LETTER HEH INITIAL FORM + // U+0647 U+200D: ARABIC LETTER HEH + ZERO WIDTH JOINER + key("\u0647", joinMoreKeys("8", "\u0668", moreKey("\uFEEB", "\u0647\u200D"))), + // U+062E: "خ" ARABIC LETTER KHAH + // U+0669: "٩" ARABIC-INDIC DIGIT NINE + key("\u062E", joinMoreKeys("9", "\u0669")), + // U+062D: "ح" ARABIC LETTER HAH + // U+0660: "٠" ARABIC-INDIC DIGIT ZERO + key("\u062D", joinMoreKeys("0", "\u0660")), + // U+062C: "ج" ARABIC LETTER JEEM + // U+0686: "چ" ARABIC LETTER TCHEH + key("\u062C", moreKey("\u0686"))) + .setKeysOfRow(2, + // U+0634: "ش" ARABIC LETTER SHEEN + // U+069C: "ڜ" ARABIC LETTER SEEN WITH THREE DOTS BELOW AND THREE DOTS ABOVE + key("\u0634", moreKey("\u069C")), + // U+0633: "س" ARABIC LETTER SEEN + "\u0633", + // U+064A: "ي" ARABIC LETTER YEH + // U+0626: "ئ" ARABIC LETTER YEH WITH HAMZA ABOVE + // U+0649: "ى" ARABIC LETTER ALEF MAKSURA + key("\u064A", joinMoreKeys("\u0626", "\u0649")), + // U+0628: "ب" ARABIC LETTER BEH + // U+067E: "پ" ARABIC LETTER PEH + key("\u0628", moreKey("\u067E")), + // U+0644: "ل" ARABIC LETTER LAM + // U+FEFB: "ﻻ" ARABIC LIGATURE LAM WITH ALEF ISOLATED FORM + // U+0627: "ا" ARABIC LETTER ALEF + // U+FEF7: "ﻷ" ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE ISOLATED FORM + // U+0623: "أ" ARABIC LETTER ALEF WITH HAMZA ABOVE + // U+FEF9: "ﻹ" ARABIC LIGATURE LAM WITH ALEF WITH HAMZA BELOW ISOLATED FORM + // U+0625: "إ" ARABIC LETTER ALEF WITH HAMZA BELOW + // U+FEF5: "ﻵ" ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE ISOLATED FORM + // U+0622: "آ" ARABIC LETTER ALEF WITH MADDA ABOVE + key("\u0644", + moreKey("\uFEFB", "\u0644\u0627"), moreKey("\uFEF7", "\u0644\u0623"), + moreKey("\uFEF9", "\u0644\u0625"), moreKey("\uFEF5", "\u0644\u0622")), + // U+0627: "ا" ARABIC LETTER ALEF + // U+0622: "آ" ARABIC LETTER ALEF WITH MADDA ABOVE + // U+0621: "ء" ARABIC LETTER HAMZA + // U+0623: "أ" ARABIC LETTER ALEF WITH HAMZA ABOVE + // U+0625: "إ" ARABIC LETTER ALEF WITH HAMZA BELOW + // U+0671: "ٱ" ARABIC LETTER ALEF WASLA + key("\u0627", joinMoreKeys("\u0622", "\u0621", "\u0623", "\u0625", "\u0671")), + // U+062A: "ت" ARABIC LETTER TEH + // U+0646: "ن" ARABIC LETTER NOON + // U+0645: "م" ARABIC LETTER MEEM + "\u062A", "\u0646", "\u0645", + // U+0643: "ك" ARABIC LETTER KAF + // U+06AF: "گ" ARABIC LETTER GAF + // U+06A9: "ک" ARABIC LETTER KEHEH + key("\u0643", joinMoreKeys("\u06AF", "\u06A9")), + // U+0637: "ط" ARABIC LETTER TAH + "\u0637") + .setKeysOfRow(3, + // U+0630: "ذ" ARABIC LETTER THAL + // U+0621: "ء" ARABIC LETTER HAMZA + // U+0624: "ؤ" ARABIC LETTER WAW WITH HAMZA ABOVE + // U+0631: "ر" ARABIC LETTER REH + "\u0630", "\u0621", "\u0624", "\u0631", + // U+0649: "ى" ARABIC LETTER ALEF MAKSURA + // U+0626: "ئ" ARABIC LETTER YEH WITH HAMZA ABOVE + key("\u0649", moreKey("\u0626")), + // U+0629: "ة" ARABIC LETTER TEH MARBUTA + // U+0648: "و" ARABIC LETTER WAW + "\u0629", "\u0648", + // U+0632: "ز" ARABIC LETTER ZAIN + // U+0698: "ژ" ARABIC LETTER JEH + key("\u0632", moreKey("\u0698")), + // U+0638: "ظ" ARABIC LETTER ZAH + // U+062F: "د" ARABIC LETTER DAL + "\u0638", "\u062F") + .build(); + + private static class ArabicSymbols extends RtlSymbols { + public ArabicSymbols(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + // U+0661: "١" ARABIC-INDIC DIGIT ONE + // U+00B9: "¹" SUPERSCRIPT ONE + // U+00BD: "½" VULGAR FRACTION ONE HALF + // U+2153: "⅓" VULGAR FRACTION ONE THIRD + // U+00BC: "¼" VULGAR FRACTION ONE QUARTER + // U+215B: "⅛" VULGAR FRACTION ONE EIGHTH + .replaceKeyOfLabel("1", key("\u0661", + joinMoreKeys("1", "\u00B9", "\u00BD", "\u2153", "\u00BC", "\u215B"))) + // U+0662: "٢" ARABIC-INDIC DIGIT TWO + // U+00B2: "²" SUPERSCRIPT TWO + // U+2154: "⅔" VULGAR FRACTION TWO THIRDS + .replaceKeyOfLabel("2", key("\u0662", joinMoreKeys("2", "\u00B2", "\u2154"))) + // U+0663: "٣" ARABIC-INDIC DIGIT THREE + // U+00B3: "³" SUPERSCRIPT THREE + // U+00BE: "¾" VULGAR FRACTION THREE QUARTERS + // U+215C: "⅜" VULGAR FRACTION THREE EIGHTHS + .replaceKeyOfLabel("3", key("\u0663", + joinMoreKeys("3", "\u00B3", "\u00BE", "\u215C"))) + // U+0664: "٤" ARABIC-INDIC DIGIT FOUR + // U+2074: "⁴" SUPERSCRIPT FOUR + .replaceKeyOfLabel("4", key("\u0664", joinMoreKeys("4", "\u2074"))) + // U+0665: "٥" ARABIC-INDIC DIGIT FIVE + // U+215D: "⅝" VULGAR FRACTION FIVE EIGHTHS + .replaceKeyOfLabel("5", key("\u0665", joinMoreKeys("5", "\u215D"))) + // U+0666: "٦" ARABIC-INDIC DIGIT SIX + .replaceKeyOfLabel("6", key("\u0666", moreKey("6"))) + // U+0667: "٧" ARABIC-INDIC DIGIT SEVEN + // U+215E: "⅞" VULGAR FRACTION SEVEN EIGHTHS + .replaceKeyOfLabel("7", key("\u0667", joinMoreKeys("7", "\u215E"))) + // U+0668: "٨" ARABIC-INDIC DIGIT EIGHT + .replaceKeyOfLabel("8", key("\u0668", moreKey("8"))) + // U+0669: "٩" ARABIC-INDIC DIGIT NINE + .replaceKeyOfLabel("9", key("\u0669", moreKey("9"))) + // U+0660: "٠" ARABIC-INDIC DIGIT ZERO + // U+066B: "٫" ARABIC DECIMAL SEPARATOR + // U+066C: "٬" ARABIC THOUSANDS SEPARATOR + // U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N + // U+2205: "∅" EMPTY SET + .replaceKeyOfLabel("0", key("\u0660", + joinMoreKeys("0", "\u066B", "\u066C", "\u207F", "\u2205"))) + // U+066A: "٪" ARABIC PERCENT SIGN + // U+2030: "‰" PER MILLE SIGN + .replaceKeyOfLabel("%", key("\u066A", joinMoreKeys("%", "\u2030"))) + // U+061B: "؛" ARABIC SEMICOLON + .replaceKeyOfLabel(";", key("\u061B", moreKey(";"))) + // U+061F: "؟" ARABIC QUESTION MARK + // U+00BF: "¿" INVERTED QUESTION MARK + .replaceKeyOfLabel("?", key("\u061F", joinMoreKeys("?", "\u00BF"))) + // U+060C: "،" ARABIC COMMA + .replaceKeyOfLabel(",", "\u060C") + // U+FD3E: "﴾" ORNATE LEFT PARENTHESIS + // U+FD3F: "﴿" ORNATE RIGHT PARENTHESIS + .replaceKeyOfLabel("(", key("(", ")", + moreKey("\uFD3E", "\uFD3F"), moreKey("<", ">"), moreKey("{", "}"), + moreKey("[", "]"))) + // U+FD3F: "﴿" ORNATE RIGHT PARENTHESIS + // U+FD3E: "﴾" ORNATE LEFT PARENTHESIS + .replaceKeyOfLabel(")", key(")", "(", + moreKey("\uFD3F", "\uFD3E"), moreKey(">", "<"), moreKey("}", "{"), + moreKey("]", "["))) + // U+2605: "★" BLACK STAR + // U+066D: "٭" ARABIC FIVE POINTED STAR + .setMoreKeysOf("*", "\u2605", "\u066D") + .build(); + } + } + + private static class ArabicSymbolsShifted extends RtlSymbolsShifted { + public ArabicSymbolsShifted(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + // U+2022: "•" BULLET + // U+266A: "♪" EIGHTH NOTE + .setMoreKeysOf("\u2022", "\u266A") + // U+060C: "،" ARABIC COMMA + .replaceKeyOfLabel(",", "\u060C") + .build(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/ArmenianPhonetic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/ArmenianPhonetic.java new file mode 100644 index 000000000..94a5bf40c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/ArmenianPhonetic.java @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Armenian Phonetic alphabet keyboard. + */ +public final class ArmenianPhonetic extends LayoutBase { + private static final String LAYOUT_NAME = "armenian_phonetic"; + + public ArmenianPhonetic(final Locale locale) { + super(new ArmenianPhoneticCustomizer(locale), ArmenianSymbols.class, + ArmenianSymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class ArmenianPhoneticCustomizer extends LayoutCustomizer { + ArmenianPhoneticCustomizer(final Locale locale) { super(locale); } + + @Override + public int getNumberOfRows() { return 5; } + + @Override + public ExpectedKey getAlphabetKey() { return ARMENIAN_ALPHABET_KEY; } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + if (isPhone) { + return EMPTY_KEYS; + } + // U+055C: "՜" ARMENIAN EXCLAMATION MARK + // U+00A1: "¡" INVERTED EXCLAMATION MARK + // U+055E: "՞" ARMENIAN QUESTION MARK + // U+00BF: "¿" INVERTED QUESTION MARK + return joinKeys(key("!", joinMoreKeys("\u055C", "\u00A1")), + key("?", joinMoreKeys("\u055E", "\u00BF")), + SHIFT_KEY); + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + // U+055D: "՝" ARMENIAN COMMA + return isPhone ? joinKeys(key("\u055D", SETTINGS_KEY)) + : joinKeys(key("\u055D", SETTINGS_KEY)); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + // U+0589: "։" ARMENIAN FULL STOP + final ExpectedKey fullStopKey = key("\u0589", getPunctuationMoreKeys(isPhone)); + return joinKeys(fullStopKey); + } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return ARMENIAN_PUNCTUATION_MORE_KEYS; + } + + // U+0531: "Ա" ARMENIAN CAPITAL LETTER AYB + // U+0532: "Բ" ARMENIAN CAPITAL LETTER BEN + // U+0533: "Գ" ARMENIAN CAPITAL LETTER GIM + private static final ExpectedKey ARMENIAN_ALPHABET_KEY = key( + "\u0531\u0532\u0533", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+055E: "՞" ARMENIAN QUESTION MARK + // U+055C: "՜" ARMENIAN EXCLAMATION MARK + // U+055A: "՚" ARMENIAN APOSTROPHE + // U+0559: "ՙ" ARMENIAN MODIFIER LETTER LEFT HALF RING + // U+055D: "՝" ARMENIAN COMMA + // U+055B: "՛" ARMENIAN EMPHASIS MARK + // U+058A: "֊" ARMENIAN HYPHEN + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+055F: "՟" ARMENIAN ABBREVIATION MARK + private static final ExpectedKey[] ARMENIAN_PUNCTUATION_MORE_KEYS = joinMoreKeys( + ",", "\u055E", "\u055C", ".", "\u055A", "\u0559", "?", "!", + "\u055D", "\u055B", "\u058A", "\u00BB", "\u00AB", "\u055F", ";", ":"); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + if (isPhone) { + // U+056D: "խ" ARMENIAN SMALL LETTER XEH + // U+0577: "շ" ARMENIAN SMALL LETTER SHA + builder.addKeysOnTheRightOfRow(3, "\u056D") + .addKeysOnTheRightOfRow(4, "\u0577"); + } else { + // U+056D: "խ" ARMENIAN SMALL LETTER XEH + // U+0577: "շ" ARMENIAN SMALL LETTER SHA + builder.addKeysOnTheRightOfRow(2, "\u056D") + .addKeysOnTheRightOfRow(3, "\u0577"); + } + return builder.build(); + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0567: "է" ARMENIAN SMALL LETTER EH + key("\u0567", moreKey("1")), + // U+0569: "թ" ARMENIAN SMALL LETTER TO + key("\u0569", moreKey("2")), + // U+0583: "փ" ARMENIAN SMALL LETTER PIWR + key("\u0583", moreKey("3")), + // U+0571: "ձ" ARMENIAN SMALL LETTER JA + key("\u0571", moreKey("4")), + // U+057B: "ջ" ARMENIAN SMALL LETTER JHEH + key("\u057B", moreKey("5")), + // U+0580: "ր" ARMENIAN SMALL LETTER REH + key("\u0580", moreKey("6")), + // U+0579: "չ" ARMENIAN SMALL LETTER CHA + key("\u0579", moreKey("7")), + // U+0573: "ճ" ARMENIAN SMALL LETTER CHEH + key("\u0573", moreKey("8")), + // U+056A: "ժ" ARMENIAN SMALL LETTER ZHE + key("\u056A", moreKey("9")), + // U+056E: "ծ" ARMENIAN SMALL LETTER CA + key("\u056E", moreKey("0"))) + .setKeysOfRow(2, + // U+0584: "ք" ARMENIAN SMALL LETTER KEH + // U+0578: "ո" ARMENIAN SMALL LETTER VO + "\u0584", "\u0578", + // U+0565: "ե" ARMENIAN SMALL LETTER ECH + // U+0587: "և" ARMENIAN SMALL LIGATURE ECH YIWN + key("\u0565", moreKey("\u0587")), + // U+057C: "ռ" ARMENIAN SMALL LETTER RA + // U+057F: "տ" ARMENIAN SMALL LETTER TIWN + // U+0568: "ը" ARMENIAN SMALL LETTER ET + // U+0582: "ւ" ARMENIAN SMALL LETTER YIWN + // U+056B: "ի" ARMENIAN SMALL LETTER INI + // U+0585: "օ" ARMENIAN SMALL LETTER OH + // U+057A: "պ" ARMENIAN SMALL LETTER PEH + "\u057C", "\u057F", "\u0568", "\u0582", "\u056B", "\u0585", "\u057A") + .setKeysOfRow(3, + // U+0561: "ա" ARMENIAN SMALL LETTER AYB + // U+057D: "ս" ARMENIAN SMALL LETTER SEH + // U+0564: "դ" ARMENIAN SMALL LETTER DA + // U+0586: "ֆ" ARMENIAN SMALL LETTER FEH + // U+0563: "գ" ARMENIAN SMALL LETTER GIM + // U+0570: "հ" ARMENIAN SMALL LETTER HO + // U+0575: "յ" ARMENIAN SMALL LETTER YI + // U+056F: "կ" ARMENIAN SMALL LETTER KEN + // U+056C: "լ" ARMENIAN SMALL LETTER LIWN + "\u0561", "\u057D", "\u0564", "\u0586", "\u0563", "\u0570", "\u0575", "\u056F", + "\u056C") + .setKeysOfRow(4, + // U+0566: "զ" ARMENIAN SMALL LETTER ZA + // U+0572: "ղ" ARMENIAN SMALL LETTER GHAD + // U+0581: "ց" ARMENIAN SMALL LETTER CO + // U+057E: "վ" ARMENIAN SMALL LETTER VEW + // U+0562: "բ" ARMENIAN SMALL LETTER BEN + // U+0576: "ն" ARMENIAN SMALL LETTER NOW + // U+0574: "մ" ARMENIAN SMALL LETTER MEN + "\u0566", "\u0572", "\u0581", "\u057E", "\u0562", "\u0576", "\u0574") + .build(); + + private static final class ArmenianSymbols extends Symbols { + public ArmenianSymbols(final LayoutCustomizer customizer) { super(customizer); } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( + super.getLayout(isPhone)); + // U+055D: "՝" ARMENIAN COMMA + builder.replaceKeyOfLabel(",", "\u055D"); + // U+055C: "՜" ARMENIAN EXCLAMATION MARK + // U+00A1: "¡" INVERTED EXCLAMATION MARK + // U+055E: "՞" ARMENIAN QUESTION MARK + // U+00BF: "¿" INVERTED QUESTION MARK + builder.setMoreKeysOf("!", "\u055C", "\u00A1") + .setMoreKeysOf("?", "\u055E", "\u00BF"); + return builder.build(); + } + } + + private static final class ArmenianSymbolsShifted extends SymbolsShifted { + public ArmenianSymbolsShifted(final LayoutCustomizer customizer) { super(customizer); } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( + super.getLayout(isPhone)); + // U+055D: "՝" ARMENIAN COMMA + builder.replaceKeyOfLabel(",", "\u055D"); + return builder.build(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Azerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Azerty.java new file mode 100644 index 000000000..c7df7eb9f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Azerty.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The AZERTY alphabet keyboard. + */ +public final class Azerty extends LayoutBase { + public Azerty(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return "azerty"; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + final LayoutCustomizer customizer = getCustomizer(); + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + customizer.setAccentedLetters(builder); + builder.replaceKeyOfLabel(ROW3_QUOTE, key("'", joinMoreKeys( + customizer.getSingleQuoteMoreKeys(), + customizer.getSingleAngleQuoteKeys()))); + return builder.build(); + } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + final ExpectedKeyboardBuilder builder; + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED + || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED) { + builder = new ExpectedKeyboardBuilder(getCommonAlphabetLayout(isPhone)); + } else { + builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + getCustomizer().setAccentedLetters(builder); + builder.replaceKeyOfLabel(ROW3_QUOTE, "?"); + } + builder.toUpperCase(getLocale()); + return builder.build(); + } + + private static final String ROW3_QUOTE = "ROW3_QUOUTE"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("a", additionalMoreKey("1")), + key("z", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("y", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0"))) + .setKeysOfRow(2, "q", "s", "d", "f", "g", "h", "j", "k", "l", "m") + .setKeysOfRow(3, "w", "x", "c", "v", "b", "n", ROW3_QUOTE) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Bengali.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Bengali.java new file mode 100644 index 000000000..fa62ffc30 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Bengali.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Bengali keyboard. + */ +public final class Bengali extends LayoutBase { + private static final String LAYOUT_NAME = "bengali"; + + public Bengali(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0994: "ঔ" BENGALI LETTER AU + // U+09CC: "ৌ" BENGALI VOWEL SIGN AU + // U+09E7: "১" BENGALI DIGIT ONE + key("\u0994", joinMoreKeys("\u09CC", "\u09E7", "1")), + // U+0990: "ঐ" BENGALI LETTER AI + // U+09C8: "ৈ" BENGALI VOWEL SIGN AI + // U+09E8: "২" BENGALI DIGIT TWO + key("\u0990", joinMoreKeys("\u09C8", "\u09E8", "2")), + // U+0986: "আ" BENGALI LETTER AA + // U+09BE: "া" BENGALI VOWEL SIGN AA + // U+09E9: "৩" BENGALI DIGIT THREE + key("\u0986", joinMoreKeys("\u09BE", "\u09E9", "3")), + // U+0988: "ঈ" BENGALI LETTER II + // U+09C0: "ী" BENGALI VOWEL SIGN II + // U+09EA: "৪" BENGALI DIGIT FOUR + key("\u0988", joinMoreKeys("\u09C0", "\u09EA", "4")), + // U+098A: "ঊ" BENGALI LETTER UU + // U+09C2: "ূ" BENGALI VOWEL SIGN UU + // U+09EB: "৫" BENGALI DIGIT FIVE + key("\u098A", joinMoreKeys("\u09C2", "\u09EB", "5")), + // U+09AC: "ব" BENGALI LETTER BA + // U+09AD: "ভ" BENGALI LETTER BHA + // U+09EC: "৬" BENGALI DIGIT SIX + key("\u09AC", joinMoreKeys("\u09AD", "\u09EC", "6")), + // U+09B9: "হ" BENGALI LETTER HA + // U+09ED: "৭" BENGALI DIGIT SEVEN + key("\u09B9", joinMoreKeys("\u09ED", "7")), + // U+0997: "গ" BENGALI LETTER GA + // U+0998: "ঘ" BENGALI LETTER GHA + // U+09EE: "৮" BENGALI DIGIT EIGHT + key("\u0997", joinMoreKeys("\u0998", "\u09EE", "8")), + // U+09A6: "দ" BENGALI LETTER DA + // U+09A7: "ধ" BENGALI LETTER DHA + // U+09EF: "৯" BENGALI DIGIT NINE + key("\u09A6", joinMoreKeys("\u09A7", "\u09EF", "9")), + // U+099C: "জ" BENGALI LETTER JA + // U+099D: "ঝ" BENGALI LETTER JHA + // U+099C/U+09CD/U+099E: + // "জ্ঞ" BENGALI LETTER JA/BENGALI SIGN VIRAMA/BENGALI LETTER NYA + // U+09E6: "০" BENGALI DIGIT ZERO + key("\u099C", joinMoreKeys("\u099D", "\u099C\u09CD\u099E", "\u09E6", "0")), + // U+09A1: "ড" BENGALI LETTER DDA + // U+09A1/U+09BC: "ড়" BENGALI LETTER DDA/BENGALI SIGN NUKTA + key("\u09A1", moreKey("\u09A1\u09BC"))) + .setKeysOfRow(2, + // U+0993: "ও" BENGALI LETTER O + // U+09CB: "ো" BENGALI VOWEL SIGN O + key("\u0993", moreKey("\u09CB")), + // U+098F: "এ" BENGALI LETTER E + // U+09C7: "ে" BENGALI VOWEL SIGN E + key("\u098F", moreKey("\u09C7")), + // U+0985: "অ" BENGALI LETTER A + // U+09CD: "্" BENGALI SIGN VIRAMA + key("\u0985", moreKey("\u09CD")), + // U+0987: "ই" BENGALI LETTER I + // U+09BF: "ি" BENGALI VOWEL SIGN I + key("\u0987", moreKey("\u09BF")), + // U+0989: "উ" BENGALI LETTER U + // U+09C1: "ু" BENGALI VOWEL SIGN U + key("\u0989", moreKey("\u09C1")), + // U+09AA: "প" BENGALI LETTER PA + // U+09AB: "ফ" BENGALI LETTER PHA + key("\u09AA", moreKey("\u09AB")), + // U+09B0: "র" BENGALI LETTER RA + // U+09C3: "ৃ" BENGALI VOWEL SIGN VOCALIC R + // U+098B: "ঋ" BENGALI LETTER VOCALIC R + // U+09A4/U+09CD/U+09B0: + // "ত্র" BENGALI LETTER TA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + key("\u09B0", joinMoreKeys("\u09C3", "\u098B", "\u09A4\u09CD\u09B0")), + // U+0995: "ক" BENGALI LETTER KA + // U+0996: "খ" BENGALI LETTER KHA + key("\u0995", moreKey("\u0996")), + // U+09A4: "ত" BENGALI LETTER TA + // U+09CE: "ৎ" BENGALI LETTER KHANDA TA + // U+09A5: "থ" BENGALI LETTER THA + // U+09A4/U+09CD/U+09A4: + // "ত্ত" BENGALI LETTER TA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + key("\u09A4", joinMoreKeys("\u09CE", "\u09A5", "\u09A4\u09CD\u09A4")), + // U+099A: "চ" BENGALI LETTER CA + // U+099B: "ছ" BENGALI LETTER CHA + key("\u099A", moreKey("\u099B")), + // U+099F: "ট" BENGALI LETTER TTA + // U+09A0: "ঠ" BENGALI LETTER TTHA + key("\u099F", moreKey("\u09A0"))) + .setKeysOfRow(3, + // U+0981: "ঁ" BENGALI SIGN CANDRABINDU + // U+0983: "ঃ" BENGALI SIGN VISARGA + // U+0982: "ং" BENGALI SIGN ANUSVARA + key("\u0981", joinMoreKeys("\u0983", "\u0982")), + // U+09A2: "ঢ" BENGALI LETTER DDHA + // U+09A2/U+09BC: "ঢ়" BENGALI LETTER DDHA/BENGALI SIGN NUKTA + key("\u09A2", moreKey("\u09A2\u09BC")), + // U+09AE: "ম" BENGALI LETTER MA + "\u09AE", + // U+09A8: "ন" BENGALI LETTER NA + // U+09A3: "ণ" BENGALI LETTER NNA + key("\u09A8", moreKey("\u09A3")), + // U+099E: "ঞ" BENGALI LETTER NYA + // U+0999: "ঙ" BENGALI LETTER NGA + // U+099E/U+09CD/U+099C: + // "ঞ্জ" BENGALI LETTER NYA/BENGALI SIGN VIRAMA/BENGALI LETTER JA + key("\u099E", joinMoreKeys("\u0999", "\u099E\u09CD\u099C")), + // U+09B2: "ল" BENGALI LETTER LA + "\u09B2", + // U+09B7: "ষ" BENGALI LETTER SSA + // U+0995/U+09CD/U+09B7: + // "ক্ষ" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER SSA + key("\u09B7", moreKey("\u0995\u09CD\u09B7")), + // U+09B8: "স" BENGALI LETTER SA + // U+09B6: "শ" BENGALI LETTER SHA + key("\u09B8", moreKey("\u09B6")), + // U+09DF: "য়" BENGALI LETTER YYA + // U+09AF: "য" BENGALI LETTER YA + key("\u09DF", moreKey("\u09AF")), + // U+0964: "।" DEVANAGARI DANDA + // U+0965: "॥" DEVANAGARI DOUBLE DANDA + key("\u0964", moreKey("\u0965"))) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/BengaliAkkhor.java b/tests/src/org/kelar/inputmethod/keyboard/layout/BengaliAkkhor.java new file mode 100644 index 000000000..765c698f6 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/BengaliAkkhor.java @@ -0,0 +1,497 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Bengali Akkhor keyboard. + */ +public final class BengaliAkkhor extends LayoutBase { + private static final String LAYOUT_NAME = "bengali_akkhor"; + + public BengaliAkkhor(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+09A7: "ধ" BENGALI LETTER DHA + // U+09E7: "১" BENGALI DIGIT ONE + // U+09A7/U+09CD/U+09AC: + // "ধ্ব্র" BENGALI LETTER DHA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09A7/U+09CD/U+09AF: + // "ধ্য্র" BENGALI LETTER DHA/BENGALI SIGN VIRAMA/BENGALI LETTER YA + // U+09A7/U+09CD/U+09B0: + // "ধ্র" BENGALI LETTER DHA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + key("\u09A7", joinMoreKeys("\u09E7", "\u09A7\u09CD\u09AC", "\u09A7\u09CD\u09AF", + "\u09A7\u09CD\u09B0")), + // U+09A5: "থ" BENGALI LETTER THA + // U+09E8: "২" BENGALI DIGIT TWO + // U+09A5/U+09CD/U+09AF: + // "থ্য" BENGALI LETTER THA/BENGALI SIGN VIRAMA/BENGALI LETTER YA + // U+09A5/U+09CD/U+09B0: + // "থ্র" BENGALI LETTER THA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + key("\u09A5", joinMoreKeys("\u09E8", "\u09A5\u09CD\u09AF", + "\u09A5\u09CD\u09B0")), + // U+09C7: "ে" BENGALI VOWEL SIGN E + // U+09E9: "৩" BENGALI DIGIT THREE + // U+098F: "এ" BENGALI LETTER E + key("\u09C7", joinMoreKeys("\u09E9", "\u098F")), + // U+09B0: "র" BENGALI LETTER RA + // U+09EA: "৪" BENGALI DIGIT FOUR + key("\u09B0", joinMoreKeys("\u09EA")), + // U+09A4: "ত" BENGALI LETTER TA + // U+09EB: "৫" BENGALI DIGIT FIVE + // U+09CE: "ৎ" BENGALI LETTER KHANDA TA + // U+09A4/U+09CD/U+09A4: + // "ত্ত" BENGALI LETTER TA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + // U+09A4/U+09CD/U+09A8: + // "ত্ন" BENGALI LETTER TA/BENGALI SIGN VIRAMA/BENGALI LETTER NA + // U+09A4/U+09CD/U+09AC: + // "ত্ব" BENGALI LETTER TA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09A4/U+09CD/U+09AE: + // "ত্ম" BENGALI LETTER TA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + key("\u09A4", joinMoreKeys("\u09EB", "\u09CE", "\u09A4\u09CD\u09A4", + "\u09A4\u09CD\u09A8", "\u09A4\u09CD\u09AC", "\u09A4\u09CD\u09AE")), + // U+09DF: "য়" BENGALI LETTER YYA + // U+09EC: "৬" BENGALI DIGIT SIX + key("\u09DF", joinMoreKeys("\u09EC")), + // U+09C1: "ু" BENGALI VOWEL SIGN U + // U+09ED: "৭" BENGALI DIGIT SEVEN + // U+0989: "উ" BENGALI LETTER U + key("\u09C1", joinMoreKeys("\u09ED", "\u0989")), + // U+09BF: "ি" BENGALI VOWEL SIGN I + // U+09EE: "৮" BENGALI DIGIT EIGHT + // U+0987: "ই BENGALI LETTER I + key("\u09Bf", joinMoreKeys("\u09EE", "\u0987")), + // U+09CB: "ো" BENGALI VOWEL SIGN O + // U+09EF: "৯" BENGALI DIGIT NINE + // U+0993: "ও" BENGALI LETTER O + key("\u09CB", joinMoreKeys("\u09EF", "\u0993")), + // U+09AA: "প" BENGALI LETTER PA + // U+09E6: "০" BENGALI DIGIT ZERO + // U+09AA/U+09CD/U+09A4: + // "প্ত" BENGALI LETTER PA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + // U+09AA/U+09CD/U+09A8: + // "প্ন" BENGALI LETTER PA/BENGALI SIGN VIRAMA/BENGALI LETTER NA + // U+09AA/U+09CD/U+09AA: + // "প্প" BENGALI LETTER PA/BENGALI SIGN VIRAMA/BENGALI LETTER PA + // U+09AA/U+09CD/U+09AF: + // "প্য" BENGALI LETTER PA/BENGALI SIGN VIRAMA/BENGALI LETTER YA + // U+09AA/U+09CD/U+09B0: + // "প্র" BENGALI LETTER PA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+09AA/U+09CD/U+09B2: + // "প্ল" BENGALI LETTER PA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + // U+09AA/U+09CD/U+09B8: + // "প্স" BENGALI LETTER PA/BENGALI SIGN VIRAMA/BENGALI LETTER SA + key("\u09AA", joinMoreKeys("\u09E6", "\u09AA\u09CD\u09A4", "\u09AA\u09CD\u09A8", + "\u09AA\u09CD\u09AA", "\u09AA\u09CD\u09AF", "\u09AA\u09CD\u09B0", + "\u09AA\u09CD\u09B2", "\u09AA\u09CD\u09B8")), + // U+0986: "আ" BENGALI LETTER AA + key("\u0986")) + .setKeysOfRow(2, + // U+09BE: "া BENGALI VOWEL SIGN AA + // U+0986: "আ" BENGALI LETTER AA + key("\u09BE", moreKey("\u0986")), + // U+09B8: "স" BENGALI LETTER SA + // U+09B8/U+09CD/U+09AC: + // "স্ব" BENGALI LETTER SA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09B8/U+09CD/U+09A4: + // "স্ত" BENGALI LETTER SA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + // U+09B8/U+09CD/U+099F: + // "স্ট" BENGALI LETTER SA/BENGALI SIGN VIRAMA/BENGALI LETTER TTA + // U+09B8/U+09CD/U+0995: + // "স্ক" BENGALI LETTER SA/BENGALI SIGN VIRAMA/BENGALI LETTER KA + // U+09B8/U+09CD/U+09AA: + // "স্প" BENGALI LETTER SA/BENGALI SIGN VIRAMA/BENGALI LETTER PA + key("\u09B8", joinMoreKeys("\u09B8\u09CD\u09AC", "\u09B8\u09CD\u09A4", + "\u09B8\u09CD\u099F", "\u09B8\u09CD\u0995", "\u09B8\u09CD\u09AA")), + // U+09A6: "দ" BENGALI LETTER DA + // U+09A6/U+09CD/U+09A6: + // "দ্দ" BENGALI LETTER DA/BENGALI SIGN VIRAMA/BENGALI LETTER DA + // U+09A6/U+09CD/U+09A7: + // "দ্ধ" BENGALI LETTER DA/BENGALI SIGN VIRAMA/BENGALI LETTER DHA + // U+09A6/U+09CD/U+09AC: + // "দ্ব" BENGALI LETTER DA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09A6/U+09CD/U+09AD: + // "দ্ভ" BENGALI LETTER DA/BENGALI SIGN VIRAMA/BENGALI LETTER BHA + // U+09A6/U+09CD/U+09AE: + // "দ্ম" BENGALI LETTER DA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + // U+09A6/U+09CD/U+09AF: + // "দ্য" BENGALI LETTER DA/BENGALI SIGN VIRAMA/BENGALI LETTER YA + // U+09A6/U+09CD/U+09B0: + // "দ্র" BENGALI LETTER DA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + key("\u09A6", joinMoreKeys("\u09A6\u09CD\u09A6", "\u09A6\u09CD\u09A7", + "\u09A6\u09CD\u09AC", "\u09A6\u09CD\u09AD", "\u09A6\u09CD\u09AE", + "\u09A6\u09CD\u09AF", "\u09A6\u09CD\u09B0")), + // U+09C3: "ৃ" BENGALI VOWEL SIGN VOCALIC R + // U+098B: "ঋ" BENGALI LETTER VOCALIC R + key("\u09C3", moreKey("\u098B")), + // U+0997: "গ" BENGALI LETTER GA + // U+0997/U+09CD/U+09A7: + // "গ্ধ" BENGALI LETTER GA/BENGALI SIGN VIRAMA/BENGALI LETTER DH A + // U+0997/U+09CD/U+09B0: + // "গ্র" BENGALI LETTER GA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+0997/U+09CD/U+09B2: + // "গ্ল" BENGALI LETTER GA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + // U+0997/U+09CD/U+09A8: + // "গ্ন" BENGALI LETTER GA/BENGALI SIGN VIRAMA/BENGALI LETTER NA + key("\u0997", joinMoreKeys("\u0997\u09CD\u09A7", "\u0997\u09CD\u09B0", + "\u0997\u09CD\u09B2", "\u0997\u09CD\u09A8")), + // U+09CD: "্" BENGALI SIGN VIRAMA + key("\u09CD"), + // U+099C: "জ" BENGALI LETTER JA + // U+099C/U+09CD/U+099E: + // "জ্ঞ" BENGALI LETTER JA/BENGALI SIGN VIRAMA/BENGALI LETTER NYA + // U+099C/U+09CD/U+099C: + // "জ্জ" BENGALI LETTER JA/BENGALI SIGN VIRAMA/BENGALI LETTER JA + // U+099C/U+09CD/U+09AF: + // "জ্ব" BENGALI LETTER JA/BENGALI SIGN VIRAMA/BENGALI LETTER YA + // U+099C/U+09CD/U+09AC: + // "জ্য" BENGALI LETTER JA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+099C/U+09CD/U+09B0: + // "জ্র" BENGALI LETTER JA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + key("\u099C", joinMoreKeys("\u099C\u09CD\u099E", "\u099C\u09CD\u099C", + "\u099C\u09CD\u09AF", "\u099C\u09CD\u09AC", "\u099C\u09CD\u09B0")), + // U+0995: "ক" BENGALI LETTER KA + // U+0995/U+09CD/U+09B7: + // "ক্ষ" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER SSA + // U+0995/U+09CD/U+0995: + // "ক্ক" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER KA + // U+0995/U+09CD/U+099F: + // "ক্ট" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER TTA + // U+0995/U+09CD/U+09A4: + // "ক্ত" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + // U+0995/U+09CD/U+09B0: + // "ক্র" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+0995/U+09CD/U+09B8: + // "ক্স" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER SA + // U+0995/U+09CD/U+09B2: + // "ক্ল" BENGALI LETTER KA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + key("\u0995", joinMoreKeys("\u0995\u09CD\u09B7", "\u0995\u09CD\u0995", + "\u0995\u09CD\u099F", "\u0995\u09CD\u09A4", "\u0995\u09CD\u09B0", + "\u0995\u09CD\u09B8", "\u0995\u09CD\u09B2")), + // U+09B2: "ল" BENGALI LETTER LA + // U+09B2/U+09CD/U+0995: + // "ল্ক" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER KA + // U+09B2/U+09CD/U+0997: + // "ল্গ" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER GA + // U+09B2/U+09CD/U+099F: + // "ল্ট" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER TTA + // U+09B2/U+09CD/U+09A1: + // "ল্ড" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER DDA + // U+09B2/U+09CD/U+09A4: + // "ল্ত" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + // U+09B2/U+09CD/U+09A6: + // "ল্দ" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER DA + // U+09B2/U+09CD/U+09A7: + // "ল্ধ" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER DHA + // U+09B2/U+09CD/U+09AA: + // "ল্প" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER PA + // U+09B2/U+09CD/U+09AB: + // "ল্ফ" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER PHA + // U+09B2/U+09CD/U+09AC: + // "ল্ব" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09B2/U+09CD/U+09AE: + // "ল্ম" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + // U+09B2/U+09CD/U+09B2: + // "ল্ল" BENGALI LETTER LA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + key("\u09B2", joinMoreKeys("\u09B2\u09CD\u0995", "\u09B2\u09CD\u0997", + "\u09B2\u09CD\u099F", "\u09B2\u09CD\u09A1", "\u09B2\u09CD\u09A4", + "\u09B2\u09CD\u09A6", "\u09B2\u09CD\u09A7", "\u09B2\u09CD\u09AA", + "\u09B2\u09CD\u09AB", "\u09B2\u09CD\u09AC", "\u09B2\u09CD\u09AE", + "\u09B2\u09CD\u09B2")), + // U+0987: "ই" BENGALI LETTER I + key("\u0987"), + // U+0989: "উ" BENGALI LETTER U + key("\u0989")) + .setKeysOfRow(3, + // U+09AF: "য" BENGALI LETTER YA + // U+09CD/U+09AF: "্য" BENGALI SIGN VIRAMA/BENGALI LETTER YA + key("\u09AF", moreKey("\u09CD\u09AF")), + // U+09B7: "ষ" BENGALI LETTER SSA + // U+09B7/U+09CD/U+0995: + // "ষ্ক" BENGALI LETTER SSA/BENGALI SIGN VIRAMA/BENGALI LETTER KA + // U+09B7/U+09CD/U+099F: + // "ষ্ট" BENGALI LETTER SSA/BENGALI SIGN VIRAMA/BENGALI LETTER TTA + // U+09B7/U+09CD/U+09A0: + // "ষ্ঠ" BENGALI LETTER SSA/BENGALI SIGN VIRAMA/BENGALI LETTER TTHA + // U+09B7/U+09CD/U+09A3: + // "ষ্ণ" BENGALI LETTER SSA/BENGALI SIGN VIRAMA/BENGALI LETTER NNA + // U+09B7/U+09CD/U+09AA: + // "ষ্প" BENGALI LETTER SSA/BENGALI SIGN VIRAMA/BENGALI LETTER PA + // U+09B7/U+09CD/U+09AB: + // "ষ্ফ" BENGALI LETTER SSA/BENGALI SIGN VIRAMA/BENGALI LETTER PHA + // U+09B7/U+09CD/U+09AE: + // "ষ্ম" BENGALI LETTER SSA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + key("\u09B7", joinMoreKeys("\u09B7\u09CD\u0995", "\u09B7\u09CD\u099F", + "\u09B7\u09CD\u09A0", "\u09B7\u09CD\u09A3", "\u09B7\u09CD\u09AA", + "\u09B7\u09CD\u09AB", "\u09B7\u09CD\u09AE")), + // U+099A: "চ" BENGALI LETTER CA + // U+099A/U+09CD/U+099A: + // "চ্চ" BENGALI LETTER CA/BENGALI SIGN VIRAMA/BENGALI LETTER CA + // U+099A/U+09CD/U+099B: + // "চ্ছ" BENGALI LETTER CA/BENGALI SIGN VIRAMA/BENGALI LETTER CHA + key("\u099A", joinMoreKeys("\u099A\u09CD\u099A", "\u099A\u09CD\u099B")), + // U+09AD: "ভ" BENGALI LETTER BHA + // U+09AD/U+09CD/U+09AF: + // "ভ্" BENGALI LETTER BHA/BENGALI SIGN VIRAMA/BENGALI LETTER YA + // U+09AD/U+09CD/U+09B0: + // "ভ্র" BENGALI LETTER BHA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+09AD/U+09CD/U+09B2: + // "ভ্ল" BENGALI LETTER BHA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + key("\u09AD", joinMoreKeys("\u09AD\u09CD\u09AF", "\u09AD\u09CD\u09B0", + "\u09AD\u09CD\u09B2")), + // U+09AC: "ব" BENGALI LETTER BA + // U+09CD/U+09AC: "্ব" BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09AC/U+09CD/U+09B0: + // "ব্র" BENGALI LETTER BA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+09AC/U+09CD/U+099C: + // "ব্জ" BENGALI LETTER BA/BENGALI SIGN VIRAMA/BENGALI LETTER JA + // U+09AC/U+09CD/U+09A6: + // "ব্দ" BENGALI LETTER BA/BENGALI SIGN VIRAMA/BENGALI LETTER DA + // U+09AC/U+09CD/U+09A7: + // "ব্ধ" BENGALI LETTER BA/BENGALI SIGN VIRAMA/BENGALI LETTER DHA + // U+09AC/U+09CD/U+09AC: + // "ব্ব" BENGALI LETTER BA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09AC/U+09CD/U+09B2: + // "ব্ল" BENGALI LETTER BA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + // U+09F1: "ৱ" BENGALI LETTER RA WITH MIDDLE DIAGONAL + // U+09F0: "ৰ" BENGALI LETTER RA WITH LOWER DIAGONAL + key("\u09AC", joinMoreKeys("\u09CD\u09AC", "\u09AC\u09CD\u09B0", + "\u09AC\u09CD\u099C", "\u09AC\u09CD\u09A6", "\u09AC\u09CD\u09A7", + "\u09AC\u09CD\u09AC", "\u09AC\u09CD\u09B2", "\u09F1", "\u09F0")), + // U+09A8: "ন" BENGALI LETTER NA + // U+09A8/U+09CD/U+09A4: + // "ন্ত" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + // U+09A8/U+09CD/U+09A5: + // "ন্থ" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER THA + // U+09A8/U+09CD/U+099F: + // "ন্ট" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER TTA + // U+09A8/U+09CD/U+09A6: + // "ন্দ" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER DA + // U+09A8/U+09CD/U+09A7: + // "ন্ধ" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER DHA + // U+09A8/U+09CD/U+09A1: + // "ন্ড" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER DDA + // U+09A8/U+09CD/U+09A8: + // "ন্ন" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER NA + // U+09A8/U+09CD/U+09AC: + // "ন্ব" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09A8/U+09CD/U+09AE: + // "ন্ম" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + // U+09A8/U+09CD/U+09B8: + // "ন্স" BENGALI LETTER NA/BENGALI SIGN VIRAMA/BENGALI LETTER SA + key("\u09A8", joinMoreKeys("\u09A8\u09CD\u09A4", "\u09A8\u09CD\u09A5", + "\u09A8\u09CD\u099F", "\u09A8\u09CD\u09A6", "\u09A8\u09CD\u09A7", + "\u09A8\u09CD\u09A1", "\u09A8\u09CD\u09A8", "\u09A8\u09CD\u09AC", + "\u09A8\u09CD\u09AE", "\u09A8\u09CD\u09B8")), + // U+09AE: "ম" BENGALI LETTER MA + // U+09AE/U+09CD/U+09A8: + // "ম্ন" BENGALI LETTER MA/BENGALI SIGN VIRAMA/BENGALI LETTER NA + // U+09AE/U+09CD/U+09AA: + // "ম্প" BENGALI LETTER MA/BENGALI SIGN VIRAMA/BENGALI LETTER PA + // U+09AE/U+09CD/U+09AC: + // "ম্ব" BENGALI LETTER MA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09AE/U+09CD/U+09AD: + // "ম্ভ" BENGALI LETTER MA/BENGALI SIGN VIRAMA/BENGALI LETTER BHA + // U+09AE/U+09CD/U+09AE: + // "ম্ম" BENGALI LETTER MA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + // U+09AE/U+09CD/U+09B0: + // "ম্র" BENGALI LETTER MA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+09AE/U+09CD/U+09B2: + // "ম্ল" BENGALI LETTER MA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + key("\u09AE", joinMoreKeys("\u09AE\u09CD\u09A8", "\u09AE\u09CD\u09AA", + "\u09AE\u09CD\u09AC", "\u09AE\u09CD\u09AD", "\u09AE\u09CD\u09AE", + "\u09AE\u09CD\u09B0", "\u09AE\u09CD\u09B2")), + // U+098F: "এ" BENGALI LETTER E + key("\u098F"), + // U+0993: "ও" BENGALI LETTER O + key("\u0993")) + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+09A2: "ঢ" BENGALI LETTER DDHA + key("\u09A2"), + // U+09A0: "ঠ" BENGALI LETTER TTHA + key("\u09A0"), + // U+09C8: "ৈ" BENGALI VOWEL SIGN AI + // U+0990: "ঐ" BENGALI LETTER AI + key("\u09C8", moreKey("\u0990")), + // U+09DC: "ড়" BENGALI LETTER RRA + // U+09BC: "়" BENGALI SIGN NUKTA + key("\u09DC", moreKey("\u09BC")), + // U+099F: "ট" BENGALI LETTER TTA + // U+09F3: "৳" BENGALI RUPEE SIGN + // U+099F/U+09CD/U+099F: + // "ট্ট" BENGALI LETTER TTA/BENGALI SIGN VIRAMA/BENGALI LETTER TTA + // U+099F/U+09CD/U+09AC: + // "ট্ব" BENGALI LETTER TTA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+099F/U+09CD/U+09AE: + // "ট্ম" BENGALI LETTER TTA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + key("\u099F", joinMoreKeys("\u09F3", "\u099F\u09CD\u099F", "\u099F\u09CD\u09AC", + "\u099F\u09CD\u09AE")), + // U+099E: "ঞ" BENGALI LETTER NYA + // U+099E/U+09CD/U+099A: + // "ঞ্চ" BENGALI LETTER NYA/BENGALI SIGN VIRAMA/BENGALI LETTER CA + // U+099E/U+09CD/U+099B: + // "ঞ্ছ" BENGALI LETTER NYA/BENGALI SIGN VIRAMA/BENGALI LETTER CHA + // U+099E/U+09CD/U+099C: + // "ঞ্জ" BENGALI LETTER NYA/BENGALI SIGN VIRAMA/BENGALI LETTER JA + key("\u099E", joinMoreKeys("\u099E\u09CD\u099A", "\u099E\u09CD\u099B", + "\u099E\u09CD\u099C")), + // U+09C2: "ূ" BENGALI VOWEL SIGN UU + // U+098A: "ঊ" BENGALI LETTER UU + key("\u09C2", moreKey("\u098A")), + // U+09C0: "ী" BENGALI VOWEL SIGN II + // U+0988: "ঈ" BENGALI LETTER II + key("\u09C0", moreKey("\u0988")), + // U+09CC: "ৌ" BENGALI VOWEL SIGN AU + // U+099A: "ঔ" BENGALI LETTER CA + // U+09D7: "ৗ" BENGALI AU LENGTH MARK + key("\u09CC", joinMoreKeys("\u099A", "\u09D7")), + // U+09AB: "ফ" BENGALI LETTER PHA + // U+09AB/U+09CD/U+099F: + // "ফ্ট" BENGALI LETTER PHA/BENGALI SIGN VIRAMA/BENGALI LETTER TTA + // U+09AB/U+09CD/U+09AF: + // "ফ্য" BENGALI LETTER PHA/BENGALI SIGN VIRAMA/BENGALI LETTER YA + // U+09AB/U+09CD/U+09B0: + // "ফ্র" BENGALI LETTER PHA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+09AB/U+09CD/U+09B2: + // "ফ্ল" BENGALI LETTER PHA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + key("\u09AB", joinMoreKeys("\u09AB\u09CD\u099F", "\u09AB\u09CD\u09AF", + "\u09AB\u09CD\u09B0", "\u09AB\u09CD\u09B2")), + // U+098B: "ঋ" BENGALI LETTER VOCALIC R + // U+098C: "ঌ" BENGALI LETTER VOCALIC L + // U+09E1: "ৡ" BENGALI LETTER VOCALIC LL + // U+09F4: "৴" BENGALI CURRENCY NUMERATOR ONE + // U+09F5: "৵" BENGALI CURRENCY NUMERATOR TWO + // U+09F6: "৶" BENGALI CURRENCY NUMERATOR THREE + // U+09E2: " ৢ" BENGALI VOWEL SIGN VOCALIC L + // U+09E3: " ৣ" BENGALI VOWEL SIGN VOCALIC LL + key("\u098B", joinMoreKeys("\u098C", "\u09E1", "\u09F4", "\u09F5", "\u09F6", + "\u09E2", "\u09E3"))) + .setKeysOfRow(2, + // U+0985: "অ" BENGALI LETTER A + key("\u0985"), + // U+09B6: "শ" BENGALI LETTER SHA + // U+09B6/U+09CD/U+099A: + // "শ্চ" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER CA + // U+09B6/U+09CD/U+099B: + // "শ্ছ" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER CHA + // U+09B6/U+09CD/U+09A4: + // "শ্ত" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER TA + // U+09B6/U+09CD/U+09A8: + // "শ্ন" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER NA + // U+09B6/U+09CD/U+09AC: + // "শ্ব" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09B6/U+09CD/U+09AE: + // "শ্ম" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + // U+09B6/U+09CD/U+09B0: + // "শ্র" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+09B6/U+09CD/U+09B2: + // "শ্ল" BENGALI LETTER SHA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + key("\u09B6", joinMoreKeys("\u09B6\u09CD\u099A", "\u09B6\u09CD\u099B", + "\u09B6\u09CD\u09A4", "\u09B6\u09CD\u09A8", "\u09B6\u09CD\u09AC", + "\u09B6\u09CD\u09AE", "\u09B6\u09CD\u09B0", "\u09B6\u09CD\u09B2")), + // U+09A1: "ড" BENGALI LETTER DDA + // U+09A1/U+09CD/U+09A1: + // "ড্ড" BENGALI LETTER DDA/BENGALI SIGN VIRAMA/BENGALI LETTER DDA + key("\u09A1", moreKey("\u09A1\u09CD\u09A1")), + // U+09DD: "ঢ়" BENGALI LETTER RHA + key("\u09DD"), + // U+0998: "ঘ" BENGALI LETTER GHA + key("\u0998"), + // U+09B9: "হ" BENGALI LETTER HA + // U+09BD: "ঽ" BENGALI SIGN AVAGRAHA + // U+09B9/U+09CD/U+09A3: + // "হ্ণ" BENGALI LETTER HA/BENGALI SIGN VIRAMA/BENGALI LETTER NNA + // U+09B9/U+09CD/U+09A8: + // "হ্ন" BENGALI LETTER HA/BENGALI SIGN VIRAMA/BENGALI LETTER NA + // U+09B9/U+09CD/U+09AC: + // "হ্ব" BENGALI LETTER HA/BENGALI SIGN VIRAMA/BENGALI LETTER BA + // U+09B9/U+09CD/U+09AE: + // "হ্ম" BENGALI LETTER HA/BENGALI SIGN VIRAMA/BENGALI LETTER MA + // U+09B9/U+09CD/U+09B0: + // "হ্র" BENGALI LETTER HA/BENGALI SIGN VIRAMA/BENGALI LETTER RA + // U+09B9/U+09CD/U+09B2: + // "হ্ল" BENGALI LETTER HA/BENGALI SIGN VIRAMA/BENGALI LETTER LA + key("\u09B9", joinMoreKeys("\u09BD", "\u09B9\u09CD\u09A3", "\u09B9\u09CD\u09A8", + "\u09B9\u09CD\u09AC", "\u09B9\u09CD\u09AE", "\u09B9\u09CD\u09B0", + "\u09B9\u09CD\u09B2")), + // U+099D: "ঝ" BENGALI LETTER JHA + key("\u099D"), + // U+0996: "খ" BENGALI LETTER KHA + key("\u0996"), + // U+09CE: "ৎ" BENGALI LETTER KHANDA TA + key("\u09CE"), + // U+0988: "ঈ" BENGALI LETTER II + key("\u0988"), + // U+098A: "ঊ" BENGALI LETTER UU + key("\u098A")) + .setKeysOfRow(3, + // U+0964: "।" DEVANAGARI DANDA + // U+0965: "॥" DEVANAGARI DOUBLE DANDA + key("\u0964", moreKey("\u0965")), + // U+0999: "ঙ BENGALI LETTER NGA + // U+0999/U+09CD/U+0995: "ঙ্ক" + // U+0999/U+09CD/U+0996: "ঙ্খ" + // U+0999/U+09CD/U+0997: "ঙ্গ" + key("\u0999", joinMoreKeys("\u0999\u09CD\u0995", "\u0999\u09CD\u0996", + "\u0999\u09CD\u0997")), + // U+099B: "ছ" BENGALI LETTER CHA + key("\u099B"), + // U+0983: "ঃ" BENGALI SIGN VISARGA + key("\u0983"), + // U+0981: "ঁ" BENGALI SIGN CANDRABINDU + key("\u0981"), + // U+09A3: "ণ" BENGALI LETTER NNA + // U+09A3/U+09CD/U+099F: + // "ণ্ট" BENGALI LETTER NNA/BENGALI SIGN VIRAMA/BENGALI LETTER TT/A + // U+09A3/U+09CD/U+09A1: + // "ণ্ড" BENGALI LETTER NNA/BENGALI SIGN VIRAMA/BENGALI LETTER DDA + // U+09A3/U+09CD/U+09A3: + // "ণ্ণ" BENGALI LETTER NNA/BENGALI SIGN VIRAMA/BENGALI LETTER NN + key("\u09A3", joinMoreKeys("\u09A3\u09CD\u099F", "\u09A3\u09CD\u09A1", + "\u09A3\u09CD\u09A3")), + // U+0982: "ং" BENGALI SIGN ANUSVARA + key("\u0982"), + // U+0990: "ঐ" BENGALI LETTER AI + key("\u0990"), + // U+0994: "ঔ" BENGALI LETTER AU + key("\u0994")) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Bulgarian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Bulgarian.java new file mode 100644 index 000000000..99c15d281 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Bulgarian.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public final class Bulgarian extends LayoutBase { + private static final String LAYOUT_NAME = "bulgarian"; + + public Bulgarian(final Locale locale) { + super(new BulgarianCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class BulgarianCustomizer extends LayoutCustomizer { + private final EastSlavicCustomizer mEastSlavicCustomizer; + + BulgarianCustomizer(final Locale locale) { + super(locale); + mEastSlavicCustomizer = new EastSlavicCustomizer(locale); + } + + @Override + public ExpectedKey getAlphabetKey() { + return mEastSlavicCustomizer.getAlphabetKey(); + } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+044F: "я" CYRILLIC SMALL LETTER YA + key("\u044F", moreKey("1")), + // U+0432: "в" CYRILLIC SMALL LETTER VE + key("\u0432", moreKey("2")), + // U+0435: "е" CYRILLIC SMALL LETTER IE + key("\u0435", moreKey("3")), + // U+0440: "р" CYRILLIC SMALL LETTER ER + key("\u0440", moreKey("4")), + // U+0442: "т" CYRILLIC SMALL LETTER TE + key("\u0442", moreKey("5")), + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + key("\u044A", moreKey("6")), + // U+0443: "у" CYRILLIC SMALL LETTER U + key("\u0443", moreKey("7")), + // U+0438: "и" CYRILLIC SMALL LETTER I + // U+045D: "ѝ" CYRILLIC SMALL LETTER I WITH GRAVE + key("\u0438", joinMoreKeys("8", "\u045D")), + // U+043E: "о" CYRILLIC SMALL LETTER O + key("\u043E", moreKey("9")), + // U+043F: "п" CYRILLIC SMALL LETTER PE + key("\u043F", moreKey("0")), + // U+0447: "ч" CYRILLIC SMALL LETTER CHE + "\u0447") + .setKeysOfRow(2, + // U+0430: "а" CYRILLIC SMALL LETTER A + // U+0441: "с" CYRILLIC SMALL LETTER ES + // U+0434: "д" CYRILLIC SMALL LETTER DE + // U+0444: "ф" CYRILLIC SMALL LETTER EF + // U+0433: "г" CYRILLIC SMALL LETTER GHE + // U+0445: "х" CYRILLIC SMALL LETTER HA + // U+0439: "й" CYRILLIC SMALL LETTER SHORT I + // U+043A: "к" CYRILLIC SMALL LETTER KA + // U+043B: "л" CYRILLIC SMALL LETTER EL + // U+0448: "ш" CYRILLIC SMALL LETTER SHA + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + "\u0430", "\u0441", "\u0434", "\u0444", "\u0433", "\u0445", "\u0439", "\u043A", + "\u043B", "\u0448", "\u0449") + .setKeysOfRow(3, + // U+0437: "з" CYRILLIC SMALL LETTER ZE + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+0446: "ц" CYRILLIC SMALL LETTER TSE + // U+0436: "ж" CYRILLIC SMALL LETTER ZHE + // U+0431: "б" CYRILLIC SMALL LETTER BE + // U+043D: "н" CYRILLIC SMALL LETTER EN + // U+043C: "м" CYRILLIC SMALL LETTER EM + // U+044E: "ю" CYRILLIC SMALL LETTER YU + "\u0437", "\u044C", "\u0446", "\u0436", "\u0431", "\u043D", "\u043C", "\u044E") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/BulgarianBds.java b/tests/src/org/kelar/inputmethod/keyboard/layout/BulgarianBds.java new file mode 100644 index 000000000..cba635e75 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/BulgarianBds.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public final class BulgarianBds extends LayoutBase { + private static final String LAYOUT_NAME = "bulgarian_bds"; + + public BulgarianBds(final Locale locale) { + super(new BulgarianBdsCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class BulgarianBdsCustomizer extends EastSlavicCustomizer { + BulgarianBdsCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0443: "у" CYRILLIC SMALL LETTER U + key("\u0443", moreKey("1")), + // U+0435: "е" CYRILLIC SMALL LETTER IE + key("\u0435", moreKey("2")), + // U+0438: "и" CYRILLIC SMALL LETTER I + // U+045D: "ѝ" CYRILLIC SMALL LETTER I WITH GRAVE + key("\u0438", joinMoreKeys("3", "\u045D")), + // U+0448: "ш" CYRILLIC SMALL LETTER SHA + key("\u0448", moreKey("4")), + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + key("\u0449", moreKey("5")), + // U+043A: "к" CYRILLIC SMALL LETTER KA + key("\u043A", moreKey("6")), + // U+0441: "с" CYRILLIC SMALL LETTER ES + key("\u0441", moreKey("7")), + // U+0434: "д" CYRILLIC SMALL LETTER DE + key("\u0434", moreKey("8")), + // U+0437: "з" CYRILLIC SMALL LETTER ZE + key("\u0437", moreKey("9")), + // U+0446: "ц" CYRILLIC SMALL LETTER TSE + key("\u0446", moreKey("0")), + // U+0431: "б" CYRILLIC SMALL LETTER BE + "\u0431") + .setKeysOfRow(2, + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+044F: "я" CYRILLIC SMALL LETTER YA + // U+0430: "а" CYRILLIC SMALL LETTER A + // U+043E: "о" CYRILLIC SMALL LETTER O + // U+0436: "ж" CYRILLIC SMALL LETTER ZHE + // U+0433: "г" CYRILLIC SMALL LETTER GHE + // U+0442: "т" CYRILLIC SMALL LETTER TE + // U+043D: "н" CYRILLIC SMALL LETTER EN + // U+0432: "в" CYRILLIC SMALL LETTER VE + // U+043C: "м" CYRILLIC SMALL LETTER EM + // U+0447: "ч" CYRILLIC SMALL LETTER CHE + "\u044C", "\u044F", "\u0430", "\u043E", "\u0436", "\u0433", "\u0442", "\u043D", + "\u0432", "\u043C", "\u0447") + .setKeysOfRow(3, + // U+044E: "ю" CYRILLIC SMALL LETTER YU + // U+0439: "й" CYRILLIC SMALL LETTER SHORT I + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + // U+044D: "э" CYRILLIC SMALL LETTER E + // U+0444: "ф" CYRILLIC SMALL LETTER EF + // U+0445: "х" CYRILLIC SMALL LETTER HA + // U+043F: "п" CYRILLIC SMALL LETTER PE + // U+0440: "р" CYRILLIC SMALL LETTER ER + // U+043B: "л" CYRILLIC SMALL LETTER EL + "\u044E", "\u0439", "\u044A", "\u044D", "\u0444", "\u0445", "\u043F", "\u0440", + "\u043B") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Colemak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Colemak.java new file mode 100644 index 000000000..fa64f80e3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Colemak.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Colemak alphabet keyboard. + */ +public final class Colemak extends LayoutBase { + private static final String LAYOUT_NAME = "colemak"; + + public Colemak(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + getCustomizer().setAccentedLetters(builder); + builder.replaceKeyOfLabel(ROW1_10, key(";", additionalMoreKey("0"), moreKey(":"))); + return builder.build(); + } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + final ExpectedKeyboardBuilder builder; + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED + || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED) { + builder = new ExpectedKeyboardBuilder(getCommonAlphabetLayout(isPhone)); + } else { + builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + getCustomizer().setAccentedLetters(builder); + builder.replaceKeyOfLabel(ROW1_10, key(":", additionalMoreKey("0"))); + } + builder.toUpperCase(getLocale()); + return builder.build(); + } + + private static final String ROW1_10 = "ROW1_10"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("f", additionalMoreKey("3")), + key("p", additionalMoreKey("4")), + key("g", additionalMoreKey("5")), + key("j", additionalMoreKey("6")), + key("l", additionalMoreKey("7")), + key("u", additionalMoreKey("8")), + key("y", additionalMoreKey("9")), + ROW1_10) + .setKeysOfRow(2, "a", "r", "s", "t", "d", "h", "n", "e", "i", "o") + .setKeysOfRow(3, "z", "x", "c", "v", "b", "k", "m") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/DevanagariLetterConstants.java b/tests/src/org/kelar/inputmethod/keyboard/layout/DevanagariLetterConstants.java new file mode 100644 index 000000000..1d2f7f46d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/DevanagariLetterConstants.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import android.os.Build; + +/** + * This class offers label strings of Devanagari letters that need the dotted circle to draw + * its glyph. + */ +class DevanagariLetterConstants { + private static final boolean NEEDS_DOTTED_CIRCLE = + Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN; + // U+25CC: "◌" DOTTED CIRCLE + private static final String DOTTED_CIRCLE = NEEDS_DOTTED_CIRCLE ? "\u25CC" : ""; + + // U+0901: "ँ" DEVANAGARI SIGN CANDRABINDU + static final String SIGN_CANDRABINDU = DOTTED_CIRCLE + "\u0901"; + // U+0902: "ं" DEVANAGARI SIGN ANUSVARA + static final String SIGN_ANUSVARA = DOTTED_CIRCLE + "\u0902"; + // U+0903: "ः" DEVANAGARI SIGN VISARGA + static final String SIGN_VISARGA = DOTTED_CIRCLE + "\u0903"; + // U+093C: "़" DEVANAGARI SIGN NUKTA + static final String SIGN_NUKTA = DOTTED_CIRCLE + "\u093C"; + // U+093D: "ऽ" DEVANAGARI SIGN AVAGRAHA + static final String SIGN_AVAGRAHA = DOTTED_CIRCLE + "\u093D"; + // U+093E: "ा" DEVANAGARI VOWEL SIGN AA + static final String VOWEL_SIGN_AA = DOTTED_CIRCLE + "\u093E"; + // U+093F: "ि" DEVANAGARI VOWEL SIGN I + static final String VOWEL_SIGN_I = DOTTED_CIRCLE + "\u093F"; + // U+0940: "ी" DEVANAGARI VOWEL SIGN II + static final String VOWEL_SIGN_II = DOTTED_CIRCLE + "\u0940"; + // U+0941: "ु" DEVANAGARI VOWEL SIGN U + static final String VOWEL_SIGN_U = DOTTED_CIRCLE + "\u0941"; + // U+0942: "ू" DEVANAGARI VOWEL SIGN UU + static final String VOWEL_SIGN_UU = DOTTED_CIRCLE + "\u0942"; + // U+0943: "ृ" DEVANAGARI VOWEL SIGN VOCALIC R + static final String VOWEL_SIGN_VOCALIC_R = DOTTED_CIRCLE + "\u0943"; + // U+0944: "ॄ" DEVANAGARI VOWEL SIGN VOCALIC RR + static final String VOWEL_SIGN_VOCALIC_RR = DOTTED_CIRCLE + "\u0944"; + // U+0945: "ॅ" DEVANAGARI VOWEL SIGN CANDRA E + static final String VOWEL_SIGN_CANDRA_E = DOTTED_CIRCLE + "\u0945"; + // U+0947: "े" DEVANAGARI VOWEL SIGN E + static final String VOWEL_SIGN_E = DOTTED_CIRCLE + "\u0947"; + // U+0948: "ै" DEVANAGARI VOWEL SIGN AI + static final String VOWEL_SIGN_AI = DOTTED_CIRCLE + "\u0948"; + // U+0949: "ॉ" DEVANAGARI VOWEL SIGN CANDRA O + static final String VOWEL_SIGN_CANDRA_O = DOTTED_CIRCLE + "\u0949"; + // U+094A: "ॊ" DEVANAGARI VOWEL SIGN SHORT O + static final String VOWEL_SIGN_SHORT_O = DOTTED_CIRCLE + "\u094A"; + // U+094B: "ो" DEVANAGARI VOWEL SIGN O + static final String VOWEL_SIGN_O = DOTTED_CIRCLE + "\u094B"; + // U+094C: "ौ" DEVANAGARI VOWEL SIGN AU + static final String VOWEL_SIGN_AU = DOTTED_CIRCLE + "\u094C"; + // U+094D: "्" DEVANAGARI SIGN VIRAMA + static final String SIGN_VIRAMA = DOTTED_CIRCLE + "\u094D"; + // U+0970: "॰" DEVANAGARI ABBREVIATION SIGN + static final String ABBREVIATION_SIGN = DOTTED_CIRCLE + "\u0970"; + // U+097D: "ॽ" DEVANAGARI LETTER GLOTTAL STOP + static final String LETTER_GLOTTAL_STOP = DOTTED_CIRCLE + "\u097D"; +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Dvorak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Dvorak.java new file mode 100644 index 000000000..9795427de --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Dvorak.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Dvorak alphabet keyboard. + */ +public class Dvorak extends LayoutBase { + private static final String LAYOUT_NAME = "dvorak"; + + public Dvorak(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + public ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + return ALPHABET_COMMON; + } + + /** + * Get the left most key of the first row. + * @param isPhone true if requesting phone's keys. + * @param elementId the element id of the requesting shifted mode. + * @return the left most key of the first row. + */ + protected ExpectedKey getRow1_1Key(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET + || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return key("'", joinMoreKeys(additionalMoreKey("1"), "!", "\"")); + } + return key("\"", additionalMoreKey("1")); + } + + /** + * Get the 2nd left key of the first row. + * @param isPhone true if requesting phone's keys. + * @param elementId the element id of the requesting shifted mode. + * @return the 2nd left key of the first row. + */ + protected ExpectedKey getRow1_2Key(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET + || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return key(",", joinMoreKeys(additionalMoreKey("2"), "?", "<")); + } + return key("<", additionalMoreKey("2")); + } + + /** + * Get the 3rd left key of the first row. + * @param isPhone true if requesting phone's keys. + * @param elementId the element id of the requesting shifted mode. + * @return the 3rd left key of the first row. + */ + protected ExpectedKey getRow1_3Key(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET + || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return key(".", joinMoreKeys(additionalMoreKey("3"), ">")); + } + return key(">", additionalMoreKey("3")); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_SYMBOLS + || elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) { + return super.getLayout(isPhone, elementId); + } + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( + getCommonAlphabetLayout(isPhone)); + builder.replaceKeyOfLabel(ROW1_1, getRow1_1Key(isPhone, elementId)) + .replaceKeyOfLabel(ROW1_2, getRow1_2Key(isPhone, elementId)) + .replaceKeyOfLabel(ROW1_3, getRow1_3Key(isPhone, elementId)); + convertCommonLayoutToKeyboard(builder, isPhone); + getCustomizer().setAccentedLetters(builder); + if (elementId != KeyboardId.ELEMENT_ALPHABET) { + builder.toUpperCase(getLocale()); + builder.replaceKeysOfAll(SHIFT_KEY, SHIFTED_SHIFT_KEY); + } + return builder.build(); + } + + public static final String ROW1_1 = "ROW1_1"; + public static final String ROW1_2 = "ROW1_2"; + public static final String ROW1_3 = "ROW1_3"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + ROW1_1, ROW1_2, ROW1_3, + key("p", additionalMoreKey("4")), + key("y", additionalMoreKey("5")), + key("f", additionalMoreKey("6")), + key("g", additionalMoreKey("7")), + key("c", additionalMoreKey("8")), + key("r", additionalMoreKey("9")), + key("l", additionalMoreKey("0"))) + .setKeysOfRow(2, "a", "o", "e", "u", "i", "d", "h", "t", "n", "s") + .setKeysOfRow(3, "j", "k", "x", "b", "m", "w", "v") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/EastSlavic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/EastSlavic.java new file mode 100644 index 000000000..e4bbcc24f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/EastSlavic.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +public final class EastSlavic extends LayoutBase { + private static final String LAYOUT_NAME = "east_slavic"; + + public EastSlavic(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW1_9 = "ROW1_9"; + public static final String ROW2_2 = "ROW2_2"; + public static final String ROW2_11 = "ROW2_11"; + public static final String ROW3_5 = "ROW3_5"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0443: "у" CYRILLIC SMALL LETTER U + key("\u0439", additionalMoreKey("1")), + // U+0446: "ц" CYRILLIC SMALL LETTER TSE + key("\u0446", additionalMoreKey("2")), + // U+0439: "й" CYRILLIC SMALL LETTER SHORT I + key("\u0443", additionalMoreKey("3")), + // U+043A: "к" CYRILLIC SMALL LETTER KA + key("\u043A", additionalMoreKey("4")), + // U+0435: "е" CYRILLIC SMALL LETTER IE + key("\u0435", additionalMoreKey("5")), + // U+043D: "н" CYRILLIC SMALL LETTER EN + key("\u043D", additionalMoreKey("6")), + // U+0433: "г" CYRILLIC SMALL LETTER GHE + key("\u0433", additionalMoreKey("7")), + // U+0448: "ш" CYRILLIC SMALL LETTER SHA + key("\u0448", additionalMoreKey("8")), + key(ROW1_9, additionalMoreKey("9")), + // U+0437: "з" CYRILLIC SMALL LETTER ZE + key("\u0437", additionalMoreKey("0")), + // U+0445: "х" CYRILLIC SMALL LETTER HA + "\u0445") + .setKeysOfRow(2, + // U+0444: "ф" CYRILLIC SMALL LETTER EF + // U+0432: "в" CYRILLIC SMALL LETTER VE + // U+0430: "а" CYRILLIC SMALL LETTER A + // U+043F: "п" CYRILLIC SMALL LETTER PE + // U+0440: "р" CYRILLIC SMALL LETTER ER + // U+043E: "о" CYRILLIC SMALL LETTER O + // U+043B: "л" CYRILLIC SMALL LETTER EL + // U+0434: "д" CYRILLIC SMALL LETTER DE + // U+0436: "ж" CYRILLIC SMALL LETTER ZHE + "\u0444", ROW2_2, "\u0432", "\u0430", "\u043F", "\u0440", "\u043E", "\u043B", + "\u0434", "\u0436", ROW2_11) + .setKeysOfRow(3, + // U+044F: "я" CYRILLIC SMALL LETTER YA + // U+0447: "ч" CYRILLIC SMALL LETTER CHE + // U+0441: "с" CYRILLIC SMALL LETTER ES + // U+043C: "м" CYRILLIC SMALL LETTER EM + // U+0442: "т" CYRILLIC SMALL LETTER TE + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+0431: "б" CYRILLIC SMALL LETTER BE + // U+044E: "ю" CYRILLIC SMALL LETTER YU + "\u044F", "\u0447", "\u0441", "\u043C", ROW3_5, "\u0442", "\u044C", "\u0431", + "\u044E") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Farsi.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Farsi.java new file mode 100644 index 000000000..d942600e0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Farsi.java @@ -0,0 +1,362 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.Symbols.RtlSymbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted.RtlSymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public final class Farsi extends LayoutBase { + private static final String LAYOUT_NAME = "farsi"; + + public Farsi(final Locale locale) { + super(new FarsiCustomizer(locale), FarsiSymbols.class, FarsiSymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class FarsiCustomizer extends LayoutCustomizer { + FarsiCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return FARSI_ALPHABET_KEY; } + + @Override + public ExpectedKey getSymbolsKey() { return FARSI_SYMBOLS_KEY; } + + @Override + public ExpectedKey getBackToSymbolsKey() { return FARSI_BACK_TO_SYMBOLS_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RIAL; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + if (isPhone) { + // U+060C: "،" ARABIC COMMA + return joinKeys(key("\u060C", SETTINGS_KEY)); + } + // U+060C: "،" ARABIC COMMA + // U+061F: "؟" ARABIC QUESTION MARK + // U+061B: "؛" ARABIC SEMICOLON + return joinKeys(key("\u060C", joinMoreKeys( + ":", "!", "\u061F", "\u061B", "-", RtlSymbols.DOUBLE_ANGLE_QUOTES_LR_RTL, + SETTINGS_KEY))); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + if (isPhone) { + return super.getKeysRightToSpacebar(isPhone); + } + return joinKeys(key(".", getPunctuationMoreKeys(isPhone))); + } + + @Override + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY, key(ZWNJ_KEY, ZWJ_KEY)); + } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return FARSI_DIACRITICS; + } + + // U+0627: "ا" ARABIC LETTER ALEF + // U+200C: ZERO WIDTH NON-JOINER + // U+0628: "ب" ARABIC LETTER BEH + // U+067E: "پ" ARABIC LETTER PEH + private static final ExpectedKey FARSI_ALPHABET_KEY = key( + "\u0627\u200C\u0628\u200C\u067E", Constants.CODE_SWITCH_ALPHA_SYMBOL); + // U+06F3: "۳" EXTENDED ARABIC-INDIC DIGIT THREE + // U+06F2: "۲" EXTENDED ARABIC-INDIC DIGIT TWO + // U+06F1: "۱" EXTENDED ARABIC-INDIC DIGIT ONE + // U+061F: "؟" ARABIC QUESTION MARK + private static final ExpectedKey FARSI_SYMBOLS_KEY = key( + "\u06F3\u06F2\u06F1\u061F", Constants.CODE_SWITCH_ALPHA_SYMBOL); + private static final ExpectedKey FARSI_BACK_TO_SYMBOLS_KEY = key( + "\u06F3\u06F2\u06F1\u061F", Constants.CODE_SHIFT); + // U+FDFC: "﷼" RIAL SIGN + private static final ExpectedKey CURRENCY_RIAL = key("\uFDFC", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + private static final ExpectedKey[] FARSI_DIACRITICS = { + // U+0655: "ٕ" ARABIC HAMZA BELOW + // U+0652: "ْ" ARABIC SUKUN + // U+0651: "ّ" ARABIC SHADDA + // U+064C: "ٌ" ARABIC DAMMATAN + // U+064D: "ٍ" ARABIC KASRATAN + // U+064B: "ً" ARABIC FATHATAN + // U+0654: "ٔ" ARABIC HAMZA ABOVE + // U+0656: "ٖ" ARABIC SUBSCRIPT ALEF + // U+0670: "ٰ" ARABIC LETTER SUPERSCRIPT ALEF + // U+0653: "ٓ" ARABIC MADDAH ABOVE + // U+064F: "ُ" ARABIC DAMMA + // U+0650: "ِ" ARABIC KASRA + // U+064E: "َ" ARABIC FATHA + // U+0640: "ـ" ARABIC TATWEEL + moreKey(" \u0655", "\u0655"), moreKey(" \u0652", "\u0652"), + moreKey(" \u0651", "\u0651"), moreKey(" \u064C", "\u064C"), + moreKey(" \u064D", "\u064D"), moreKey(" \u064B", "\u064B"), + moreKey(" \u0654", "\u0654"), moreKey(" \u0656", "\u0656"), + moreKey(" \u0670", "\u0670"), moreKey(" \u0653", "\u0653"), + moreKey(" \u064F", "\u064F"), moreKey(" \u0650", "\u0650"), + moreKey(" \u064E", "\u064E"), moreKey("\u0640\u0640\u0640", "\u0640") + }; + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + if (isPhone) { + return ALPHABET_COMMON; + } + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + // U+0622: "آ" ARABIC LETTER ALEF WITH MADDA ABOVE + builder.insertKeysAtRow(3, 10, "\u0622"); + return builder.build(); + } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0636: "ض" ARABIC LETTER DAD + // U+06F1: "۱" EXTENDED ARABIC-INDIC DIGIT ONE + key("\u0636", joinMoreKeys("\u06F1", "1")), + // U+0635: "ص" ARABIC LETTER SAD + // U+06F2: "۲" EXTENDED ARABIC-INDIC DIGIT TWO + key("\u0635", joinMoreKeys("\u06F2", "2")), + // U+062B: "ث" ARABIC LETTER THEH + // U+06F3: "۳" EXTENDED ARABIC-INDIC DIGIT THREE + key("\u062B", joinMoreKeys("\u06F3", "3")), + // U+0642: "ق" ARABIC LETTER QAF + // U+06F4: "۴" EXTENDED ARABIC-INDIC DIGIT FOUR + key("\u0642", joinMoreKeys("\u06F4", "4")), + // U+0641: "ف" ARABIC LETTER FEH + // U+06F5: "۵" EXTENDED ARABIC-INDIC DIGIT FIVE + key("\u0641", joinMoreKeys("\u06F5", "5")), + // U+063A: "غ" ARABIC LETTER GHAIN + // U+06F6: "۶" EXTENDED ARABIC-INDIC DIGIT SIX + key("\u063A", joinMoreKeys("\u06F6", "6")), + // U+0639: "ع" ARABIC LETTER AIN + // U+06F7: "۷" EXTENDED ARABIC-INDIC DIGIT SEVEN + key("\u0639", joinMoreKeys("\u06F7", "7")), + // U+0647: "ه" ARABIC LETTER HEH + // U+FEEB: "ﻫ" ARABIC LETTER HEH INITIAL FORM + // U+0647/U+200D: ARABIC LETTER HEH + ZERO WIDTH JOINER + // U+0647/U+0654: ARABIC LETTER HEH + ARABIC HAMZA ABOVE + // U+0629: "ة" ARABIC LETTER TEH MARBUTA + // U+06F8: "۸" EXTENDED ARABIC-INDIC DIGIT EIGHT + key("\u0647", joinMoreKeys(moreKey("\uFEEB", "\u0647\u200D"), "\u0647\u0654", + "\u0629", "\u06F8", "8")), + // U+062E: "خ" ARABIC LETTER KHAH + // U+06F9: "۹" EXTENDED ARABIC-INDIC DIGIT NINE + key("\u062E", joinMoreKeys("\u06F9", "9")), + // U+062D: "ح" ARABIC LETTER HAH + // U+06F0: "۰" EXTENDED ARABIC-INDIC DIGIT ZERO + key("\u062D", joinMoreKeys("\u06F0", "0")), + // U+062C: "ج" ARABIC LETTER JEEM + "\u062C") + .setKeysOfRow(2, + // U+0634: "ش" ARABIC LETTER SHEEN + // U+0633: "س" ARABIC LETTER SEEN + "\u0634", "\u0633", + // U+06CC: "ی" ARABIC LETTER FARSI YEH + // U+0626: "ئ" ARABIC LETTER YEH WITH HAMZA ABOVE + // U+064A: "ي" ARABIC LETTER YEH + // U+FBE8: "ﯨ" ARABIC LETTER UIGHUR KAZAKH KIRGHIZ ALEF MAKSURA INITIAL FORM + // U+0649: "ى" ARABIC LETTER ALEF MAKSURA + key("\u06CC", joinMoreKeys("\u0626", "\u064A", moreKey("\uFBE8", "\u0649"))), + // U+0628: "ب" ARABIC LETTER BEH + // U+0644: "ل" ARABIC LETTER LAM + "\u0628", "\u0644", + // U+0627: "ا" ARABIC LETTER ALEF + // U+0671: "ٱ" ARABIC LETTER ALEF WASLA + // U+0621: "ء" ARABIC LETTER HAMZA + // U+0622: "آ" ARABIC LETTER ALEF WITH MADDA ABOVE + // U+0623: "أ" ARABIC LETTER ALEF WITH HAMZA ABOVE + // U+0625: "إ" ARABIC LETTER ALEF WITH HAMZA BELOW + key("\u0627", joinMoreKeys("\u0671", "\u0621", "\u0622", "\u0623", "\u0625")), + // U+062A: "ت" ARABIC LETTER TEH + // U+0629: "ة": ARABIC LETTER TEH MARBUTA + key("\u062A", moreKey("\u0629")), + // U+0646: "ن" ARABIC LETTER NOON + // U+0645: "م" ARABIC LETTER MEEM + "\u0646", "\u0645", + // U+06A9: "ک" ARABIC LETTER KEHEH + // U+0643: "ك" ARABIC LETTER KAF + key("\u06A9", moreKey("\u0643")), + // U+06AF: "گ" ARABIC LETTER GAF + "\u06AF") + .setKeysOfRow(3, + // U+0638: "ظ" ARABIC LETTER ZAH + // U+0637: "ط" ARABIC LETTER TAH + // U+0698: "ژ" ARABIC LETTER JEH + // U+0632: "ز" ARABIC LETTER ZAIN + // U+0631: "ر" ARABIC LETTER REH + // U+0630: "ذ" ARABIC LETTER THAL + // U+062F: "د" ARABIC LETTER DAL + // U+067E: "پ" ARABIC LETTER PEH + "\u0638", "\u0637", "\u0698", "\u0632", "\u0631", "\u0630", "\u062F", "\u067E", + // U+0648: "و" ARABIC LETTER WAW + // U+0624: "ؤ" ARABIC LETTER WAW WITH HAMZA ABOVE + key("\u0648", moreKey("\u0624")), + // U+0686: "چ" ARABIC LETTER TCHEH + "\u0686") + .build(); + + private static class FarsiSymbols extends RtlSymbols { + public FarsiSymbols(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + // U+06F1: "۱" EXTENDED ARABIC-INDIC DIGIT ONE + // U+00B9: "¹" SUPERSCRIPT ONE + // U+00BD: "½" VULGAR FRACTION ONE HALF + // U+2153: "⅓" VULGAR FRACTION ONE THIRD + // U+00BC: "¼" VULGAR FRACTION ONE QUARTER + // U+215B: "⅛" VULGAR FRACTION ONE EIGHTH + .replaceKeyOfLabel("1", key("\u06F1", + joinMoreKeys("1", "\u00B9", "\u00BD", "\u2153", "\u00BC", "\u215B"))) + // U+06F2: "۲" EXTENDED ARABIC-INDIC DIGIT TWO + // U+00B2: "²" SUPERSCRIPT TWO + // U+2154: "⅔" VULGAR FRACTION TWO THIRDS + .replaceKeyOfLabel("2", key("\u06F2", joinMoreKeys("2", "\u00B2", "\u2154"))) + // U+06F3: "۳" EXTENDED ARABIC-INDIC DIGIT THREE + // U+00B3: "³" SUPERSCRIPT THREE + // U+00BE: "¾" VULGAR FRACTION THREE QUARTERS + // U+215C: "⅜" VULGAR FRACTION THREE EIGHTHS + .replaceKeyOfLabel("3", key("\u06F3", + joinMoreKeys("3", "\u00B3", "\u00BE", "\u215C"))) + // U+06F4: "۴" EXTENDED ARABIC-INDIC DIGIT FOUR + // U+2074: "⁴" SUPERSCRIPT FOUR + .replaceKeyOfLabel("4", key("\u06F4", joinMoreKeys("4", "\u2074"))) + // U+06F5: "۵" EXTENDED ARABIC-INDIC DIGIT FIVE + // U+215D: "⅝" VULGAR FRACTION FIVE EIGHTHS + .replaceKeyOfLabel("5", key("\u06F5", joinMoreKeys("5", "\u215D"))) + // U+06F6: "۶" EXTENDED ARABIC-INDIC DIGIT SIX + .replaceKeyOfLabel("6", key("\u06F6", moreKey("6"))) + // U+06F7: "۷" EXTENDED ARABIC-INDIC DIGIT SEVEN + // U+215E: "⅞" VULGAR FRACTION SEVEN EIGHTHS + .replaceKeyOfLabel("7", key("\u06F7", joinMoreKeys("7", "\u215E"))) + // U+06F8: "۸" EXTENDED ARABIC-INDIC DIGIT EIGHT + .replaceKeyOfLabel("8", key("\u06F8", moreKey("8"))) + // U+06F9: "۹" EXTENDED ARABIC-INDIC DIGIT NINE + .replaceKeyOfLabel("9", key("\u06F9", moreKey("9"))) + // U+066C: "٬" ARABIC THOUSANDS SEPARATOR + .replaceKeyOfLabel("@", key("\u066C", moreKey("@"))) + // U+066B: "٫" ARABIC DECIMAL SEPARATOR + .replaceKeyOfLabel("#", key("\u066B", moreKey("#"))) + // U+06F0: "۰" EXTENDED ARABIC-INDIC DIGIT ZERO + // U+066B: "٫" ARABIC DECIMAL SEPARATOR + // U+066C: "٬" ARABIC THOUSANDS SEPARATOR + // U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N + // U+2205: "∅" EMPTY SET + .replaceKeyOfLabel("0", key("\u06F0", + joinMoreKeys("0", "\u066B", "\u066C", "\u207F", "\u2205"))) + // U+066A: "٪" ARABIC PERCENT SIGN + // U+2030: "‰" PER MILLE SIGN + .replaceKeyOfLabel("%", key("\u066A", joinMoreKeys("%", "\u2030"))) + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+2264: "≤" LESS-THAN OR EQUAL TO + .replaceKeyOfLabel("\"", key("\u00AB", "\u00BB", joinMoreKeys( + DOUBLE_QUOTES_9LR, DOUBLE_ANGLE_QUOTES_LR_RTL))) + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // U+2265: "≥" GREATER-THAN EQUAL TO + .replaceKeyOfLabel("'", key("\u00BB", "\u00AB", joinMoreKeys( + SINGLE_QUOTES_9LR, SINGLE_ANGLE_QUOTES_LR_RTL))) + // U+061B: "؛" ARABIC SEMICOLON + .replaceKeyOfLabel(";", key("\u061B", moreKey(";"))) + // U+061F: "؟" ARABIC QUESTION MARK + // U+00BF: "¿" INVERTED QUESTION MARK + .replaceKeyOfLabel("?", key("\u061F", joinMoreKeys("?", "\u00BF"))) + // U+060C: "،" ARABIC COMMA + .replaceKeyOfLabel(",", "\u060C") + // U+FD3E: "﴾" ORNATE LEFT PARENTHESIS + // U+FD3F: "﴿" ORNATE RIGHT PARENTHESIS + .replaceKeyOfLabel("(", key("(", ")", + moreKey("\uFD3E", "\uFD3F"), moreKey("<", ">"), moreKey("{", "}"), + moreKey("[", "]"))) + // U+FD3F: "﴿" ORNATE RIGHT PARENTHESIS + // U+FD3E: "﴾" ORNATE LEFT PARENTHESIS + .replaceKeyOfLabel(")", key(")", "(", + moreKey("\uFD3F", "\uFD3E"), moreKey(">", "<"), moreKey("}", "{"), + moreKey("]", "["))) + // U+2605: "★" BLACK STAR + // U+066D: "٭" ARABIC FIVE POINTED STAR + .setMoreKeysOf("*", "\u2605", "\u066D") + .build(); + } + } + + private static class FarsiSymbolsShifted extends RtlSymbolsShifted { + public FarsiSymbolsShifted(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + // U+2022: "•" BULLET + // U+266A: "♪" EIGHTH NOTE + .setMoreKeysOf("\u2022", "\u266A") + // U+060C: "،" ARABIC COMMA + .replaceKeyOfLabel(",", "\u060C") + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+2264: "≤" LESS-THAN OR EQUAL TO + .replaceKeyOfLabel("<", key("\u00AB", "\u00BB", + moreKey("\u2039", "\u203A"), moreKey("\u2264", "\u2265"), + moreKey("<", ">"))) + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // U+2265: "≥" GREATER-THAN EQUAL TO + .replaceKeyOfLabel(">", key("\u00BB", "\u00AB", + moreKey("\u203A", "\u2039"), moreKey("\u2265", "\u2264"), + moreKey(">", "<"))) + .build(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Georgian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Georgian.java new file mode 100644 index 000000000..e658e1ca0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Georgian.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Georgian alphabet keyboard. + */ +public final class Georgian extends LayoutBase { + private static final String LAYOUT_NAME = "georgian"; + + public Georgian(final Locale locale) { + super(new GeorgianCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class GeorgianCustomizer extends LayoutCustomizer { + GeorgianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return GEORGIAN_ALPHABET_KEY; } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + // U+10D0: "ა" GEORGIAN LETTER AN + // U+10D1: "ბ" GEORGIAN LETTER BAN + // U+10D2: "გ" GEORGIAN LETTER GAN + private static final ExpectedKey GEORGIAN_ALPHABET_KEY = key( + "\u10D0\u10D1\u10D2", Constants.CODE_SWITCH_ALPHA_SYMBOL); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + return ALPHABET_COMMON; + } + + @Override + public ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, + final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+10E5: "ქ" GEORGIAN LETTER GHAN + key("\u10E5", moreKey("1")), + // U+10EC: "წ" GEORGIAN LETTER CIL + key("\u10EC", moreKey("2")), + // U+10D4: "ე" GEORGIAN LETTER EN + // U+10F1: "ჱ" GEORGIAN LETTER HE + key("\u10D4", joinMoreKeys("3", "\u10F1")), + // U+10E0: "რ" GEORGIAN LETTER RAE + key("\u10E0", moreKey("4")), + // U+10E2: "ტ" GEORGIAN LETTER TAR + key("\u10E2", moreKey("5")), + // U+10E7: "ყ" GEORGIAN LETTER QAR + // U+10F8: "ჸ" GEORGIAN LETTER ELIFI + key("\u10E7", joinMoreKeys("6", "\u10F8")), + // U+10E3: "უ" GEORGIAN LETTER UN + key("\u10E3", moreKey("7")), + // U+10D8: "ი" GEORGIAN LETTER IN + // U+10F2: "ჲ" GEORGIAN LETTER HIE + key("\u10D8", joinMoreKeys("8", "\u10F2")), + // U+10DD: "ო" GEORGIAN LETTER ON + key("\u10DD", moreKey("9")), + // U+10DE: "პ" GEORGIAN LETTER PAR + key("\u10DE", moreKey("0"))) + .setKeysOfRow(2, + // U+10D0: "ა" GEORGIAN LETTER AN + // U+10FA: "ჺ" GEORGIAN LETTER AIN + key("\u10D0", moreKey("\u10FA")), + // U+10E1: "ს" GEORGIAN LETTER SAN + // U+10D3: "დ" GEORGIAN LETTER DON + "\u10E1", "\u10D3", + // U+10E4: "ფ" GEORGIAN LETTER PHAR + // U+10F6: "ჶ" GEORGIAN LETTER FI + key("\u10E4", moreKey("\u10F6")), + // U+10D2: "გ" GEORGIAN LETTER GAN + // U+10F9: "ჹ" GEORGIAN LETTER TURNED GAN + key("\u10D2", moreKey("\u10F9")), + // U+10F0: "ჰ" GEORGIAN LETTER HAE + // U+10F5: "ჵ" GEORGIAN LETTER HOE + key("\u10F0", moreKey("\u10F5")), + // U+10EF: "ჯ" GEORGIAN LETTER JHAN + // U+10F7: "ჷ" GEORGIAN LETTER YN + key("\u10EF", moreKey("\u10F7")), + // U+10D9: "კ" GEORGIAN LETTER KAN + // U+10DA: "ლ" GEORGIAN LETTER LAS + "\u10D9", "\u10DA") + .setKeysOfRow(3, + // U+10D6: "ზ" GEORGIAN LETTER ZEN + "\u10D6", + // U+10EE: "ხ" GEORGIAN LETTER XAN + // U+10F4: "ჴ" GEORGIAN LETTER HAR + key("\u10EE", moreKey("\u10F4")), + // U+10EA: "ც" GEORGIAN LETTER CAN + "\u10EA", + // U+10D5: "ვ" GEORGIAN LETTER VIN + // U+10F3: "ჳ" GEORGIAN LETTER WE + key("\u10D5", moreKey("\u10F3")), + // U+10D1: "ბ" GEORGIAN LETTER BAN + "\u10D1", + // U+10DC: "ნ" GEORGIAN LETTER NAR + // U+10FC: "ჼ" MODIFIER LETTER GEORGIAN NAR + key("\u10DC", moreKey("\u10FC")), + // U+10DB: "მ" GEORGIAN LETTER MAN + "\u10DB") + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("Q", moreKey("1")), + // U+10ED: "ჭ" GEORGIAN LETTER CHAR + key("\u10ED", moreKey("2")), + key("E", moreKey("3")), + // U+10E6: "ღ" GEORGIAN LETTER GHAN + key("\u10E6", moreKey("4")), + // U+10D7: "თ" GEORGIAN LETTER TAN + key("\u10D7", moreKey("5")), + key("Y", moreKey("6")), + key("U", moreKey("7")), + key("I", moreKey("8")), + key("O", moreKey("9")), + key("P", moreKey("0"))) + .setKeysOfRow(2, + // U+10E8: "შ" GEORGIAN LETTER SHIN + // U+10DF: "ჟ" GEORGIAN LETTER ZHAR + "A", "\u10E8", "D", "F", "G", "H", "\u10DF", "K", "L") + .setKeysOfRow(3, + // U+10EB: "ძ" GEORGIAN LETTER JIL + // U+10E9: "ჩ" GEORGIAN LETTER CHIN + "\u10EB", "X", "\u10E9", "V", "B", "N", "M") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Greek.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Greek.java new file mode 100644 index 000000000..e646fc663 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Greek.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Greek alphabet keyboard. + */ +public final class Greek extends LayoutBase { + private static final String LAYOUT_NAME = "greek"; + + public Greek(final Locale locale) { + super(new GreekCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class GreekCustomizer extends EuroCustomizer { + GreekCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return GREEK_ALPHABET_KEY; } + + // U+0391: "Α" GREEK CAPITAL LETTER ALPHA + // U+0392: "Β" GREEK CAPITAL LETTER BETA + // U+0393: "Γ" GREEK CAPITAL LETTER GAMMA + private static final ExpectedKey GREEK_ALPHABET_KEY = key( + "\u0391\u0392\u0393", Constants.CODE_SWITCH_ALPHA_SYMBOL); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + builder.replaceKeyOfLabel(ROW1_1, ROW1_1_SEMICOLON); + builder.replaceKeyOfLabel(ROW1_2, ROW1_2_FINAL_SIGMA); + return builder.build(); + } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + builder.toUpperCase(getLocale()); + if (elementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED + || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED) { + builder.replaceKeyOfLabel(ROW1_1, ROW1_1_COLON); + } else { + builder.replaceKeyOfLabel(ROW1_1, ROW1_1_SEMICOLON); + } + builder.replaceKeyOfLabel(ROW1_2, ROW1_2_FINAL_SIGMA); + return builder.build(); + } + + private static final String ROW1_1 = "ROW1_1"; + private static final ExpectedKey ROW1_1_SEMICOLON = key(";", joinMoreKeys("1", ":")); + private static final ExpectedKey ROW1_1_COLON = key(":", joinMoreKeys("1", ";")); + + private static final String ROW1_2 = "ROW2_2"; + // U+03C2: "ς" GREEK SMALL LETTER FINAL SIGMA + private static final ExpectedKey ROW1_2_FINAL_SIGMA = key("\u03C2", moreKey("2")); + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key(ROW1_1, moreKey("1")), + key(ROW1_2, moreKey("2")), + // U+03B5: "ε" GREEK SMALL LETTER EPSILON + // U+03AD: "έ" GREEK SMALL LETTER EPSILON WITH TONOS + key("\u03B5", joinMoreKeys("\u03AD", "3")), + // U+03C1: "ρ" GREEK SMALL LETTER RHO + key("\u03C1", moreKey("4")), + // U+03C4: "τ" GREEK SMALL LETTER TAU + key("\u03C4", moreKey("5")), + // U+03C5: "υ" GREEK SMALL LETTER UPSILON + // U+03CD: "ύ" GREEK SMALL LETTER UPSILON WITH TONOS + // U+03CB: "ϋ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA + // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS + key("\u03C5", joinMoreKeys("\u03CD", "6", "\u03CB", "\u03B0")), + // U+03B8: "θ" GREEK SMALL LETTER THETA + key("\u03B8", moreKey("7")), + // U+03B9: "ι" GREEK SMALL LETTER IOTA + // U+03AF: "ί" GREEK SMALL LETTER IOTA WITH TONOS + // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA + // U+0390: "ΐ" GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS + key("\u03B9", joinMoreKeys("\u03AF", "8", "\u03CA", "\u0390")), + // U+03BF: "ο" GREEK SMALL LETTER OMICRON + // U+03CC: "ό" GREEK SMALL LETTER OMICRON WITH TONOS + key("\u03BF", joinMoreKeys("\u03CC", "9")), + // U+03C0: "π" GREEK SMALL LETTER PI + key("\u03C0", moreKey("0"))) + .setKeysOfRow(2, + // U+03B1: "α" GREEK SMALL LETTER ALPHA + // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS + key("\u03B1", moreKey("\u03AC")), + // U+03C3: "σ" GREEK SMALL LETTER SIGMA + // U+03B4: "δ" GREEK SMALL LETTER DELTA + // U+03C6: "φ" GREEK SMALL LETTER PHI + // U+03B3: "γ" GREEK SMALL LETTER GAMMA + "\u03C3", "\u03B4", "\u03C6", "\u03B3", + // U+03B7: "η" GREEK SMALL LETTER ETA + // U+03AE: "ή" GREEK SMALL LETTER ETA WITH TONOS + key("\u03B7", moreKey("\u03AE")), + // U+03BE: "ξ" GREEK SMALL LETTER XI + // U+03BA: "κ" GREEK SMALL LETTER KAPPA + // U+03BB: "λ" GREEK SMALL LETTER LAMDA + "\u03BE", "\u03BA", "\u03BB") + .setKeysOfRow(3, + // U+03B6: "ζ" GREEK SMALL LETTER ZETA + // U+03C7: "χ" GREEK SMALL LETTER CHI + // U+03C8: "ψ" GREEK SMALL LETTER PSI + "\u03B6", "\u03C7", "\u03C8", + // U+03C9: "ω" GREEK SMALL LETTER OMEGA + // U+03CE: "ώ" GREEK SMALL LETTER OMEGA WITH TONOS + key("\u03C9", moreKey("\u03CE")), + // U+03B2: "β" GREEK SMALL LETTER BETA + // U+03BD: "ν" GREEK SMALL LETTER NU + // U+03BC: "μ" GREEK SMALL LETTER MU + "\u03B2", "\u03BD", "\u03BC") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Hebrew.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Hebrew.java new file mode 100644 index 000000000..5adb50ddc --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Hebrew.java @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.Symbols.RtlSymbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted.RtlSymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public final class Hebrew extends LayoutBase { + private static final String LAYOUT_NAME = "hebrew"; + + public Hebrew(final Locale locale) { + super(new HebrewCustomizer(locale), HebrewSymbols.class, RtlSymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class HebrewCustomizer extends LayoutCustomizer { + HebrewCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return HEBREW_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_NEW_SHEQEL; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_LR9; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_LR9; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { + return RtlSymbols.DOUBLE_ANGLE_QUOTES_LR_RTL; + } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { + return RtlSymbols.SINGLE_ANGLE_QUOTES_LR_RTL; + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return isPhone ? RTL_PHONE_PUNCTUATION_MORE_KEYS + : RTL_TABLET_PUNCTUATION_MORE_KEYS; + } + + // U+05D0: "א" HEBREW LETTER ALEF + // U+05D1: "ב" HEBREW LETTER BET + // U+05D2: "ג" HEBREW LETTER GIMEL + private static final ExpectedKey HEBREW_ALPHABET_KEY = key( + "\u05D0\u05D1\u05D2", Constants.CODE_SWITCH_ALPHA_SYMBOL); + // U+20AA: "₪" NEW SHEQEL SIGN + private static final ExpectedKey CURRENCY_NEW_SHEQEL = key("\u20AA", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + private static final ExpectedKey[] RTL_PHONE_PUNCTUATION_MORE_KEYS = joinKeys( + ",", "?", "!", "#", key(")", "("), key("(", ")"), "/", ";", + "'", "@", ":", "-", "\"", "+", "%", "&"); + // Punctuation more keys for tablet form factor. + private static final ExpectedKey[] RTL_TABLET_PUNCTUATION_MORE_KEYS = joinKeys( + ",", "'", "#", key(")", "("), key("(", ")"), "/", ";", + "@", ":", "-", "\"", "+", "%", "&"); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("'", joinMoreKeys("1", "\"")), + key("-", joinMoreKeys("2", "_")), + // U+05E7: "ק" HEBREW LETTER QOF + key("\u05E7", moreKey("3")), + // U+05E8: "ר" HEBREW LETTER RESH + key("\u05E8", moreKey("4")), + // U+05D0: "א" HEBREW LETTER ALEF + key("\u05D0", moreKey("5")), + // U+05D8: "ט" HEBREW LETTER TET + key("\u05D8", moreKey("6")), + // U+05D5: "ו" HEBREW LETTER VAV + key("\u05D5", moreKey("7")), + // U+05DF: "ן" HEBREW LETTER FINAL NUN + key("\u05DF", moreKey("8")), + // U+05DD: "ם" HEBREW LETTER FINAL MEM + key("\u05DD", moreKey("9")), + // U+05E4: "פ" HEBREW LETTER PE + key("\u05E4", moreKey("0"))) + .setKeysOfRow(2, + // U+05E9: "ש" HEBREW LETTER SHIN + // U+05D3: "ד" HEBREW LETTER DALET + "\u05E9", "\u05D3", + // U+05D2: "ג" HEBREW LETTER GIMEL + // U+05D2 U+05F3: "ג׳" HEBREW LETTER GIMEL + HEBREW PUNCTUATION GERESH + key("\u05D2", moreKey("\u05D2\u05F3")), + // U+05DB: "כ" HEBREW LETTER KAF + // U+05E2: "ע" HEBREW LETTER AYIN + "\u05DB", "\u05E2", + // U+05D9: "י" HEBREW LETTER YOD + // U+05F2 U+05B7: "ײַ" HEBREW LIGATURE YIDDISH DOUBLE YOD + HEBREW POINT PATAH + key("\u05D9", moreKey("\u05F2\u05B7")), + // U+05D7: "ח" HEBREW LETTER HET + // U+05D7 U+05F3: "ח׳" HEBREW LETTER HET + HEBREW PUNCTUATION GERESH + key("\u05D7", moreKey("\u05D7\u05F3")), + // U+05DC: "ל" HEBREW LETTER LAMED + // U+05DA: "ך" HEBREW LETTER FINAL KAF + // U+05E3: "ף" HEBREW LETTER FINAL PE + "\u05DC", "\u05DA", "\u05E3") + .setKeysOfRow(3, + // U+05D6: "ז" HEBREW LETTER ZAYIN + // U+05D6 U+05F3: "ז׳" HEBREW LETTER ZAYIN + HEBREW PUNCTUATION GERESH + key("\u05D6", moreKey("\u05D6\u05F3")), + // U+05E1: "ס" HEBREW LETTER SAMEKH + // U+05D1: "ב" HEBREW LETTER BET + // U+05D4: "ה" HEBREW LETTER HE + // U+05E0: "נ" HEBREW LETTER NUN + // U+05DE: "מ" HEBREW LETTER MEM + "\u05E1", "\u05D1", "\u05D4", "\u05E0", "\u05DE", + // U+05E6: "צ" HEBREW LETTER TSADI + // U+05E6 U+05F3: "צ׳" HEBREW LETTER TSADI + HEBREW PUNCTUATION GERESH + key("\u05E6", moreKey("\u05E6\u05F3")), + // U+05EA: "ת" HEBREW LETTER TAV + // U+05EA U+05F3: "ת׳" HEBREW LETTER TAV + HEBREW PUNCTUATION GERESH + key("\u05EA", moreKey("\u05EA\u05F3")), + // U+05E5: "ץ" HEBREW LETTER FINAL TSADI + // U+05E5 U+05F3: "ץ׳" HEBREW LETTER FINAL TSADI + HEBREW PUNCTUATION GERESH + key("\u05E5", moreKey("\u05E5\u05F3"))) + .build(); + + private static class HebrewSymbols extends RtlSymbols { + public HebrewSymbols(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + // U+00B1: "±" PLUS-MINUS SIGN + // U+FB29: "﬩" HEBREW LETTER ALTERNATIVE PLUS SIGN + .setMoreKeysOf("+", "\u00B1", "\uFB29") + // U+2605: "★" BLACK STAR + .setMoreKeysOf("*", "\u2605") + .build(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Hindi.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Hindi.java new file mode 100644 index 000000000..25021e72d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Hindi.java @@ -0,0 +1,332 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import static org.kelar.inputmethod.keyboard.layout.DevanagariLetterConstants.*; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Hindi keyboard. + */ +public final class Hindi extends LayoutBase { + private static final String LAYOUT_NAME = "hindi"; + + public Hindi(final LayoutCustomizer customizer) { + super(customizer, HindiSymbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+094C: "ौ" DEVANAGARI VOWEL SIGN AU + // U+094C/U+0902: "ौं" DEVANAGARI VOWEL SIGN AU/DEVANAGARI SIGN ANUSVARA + // U+0967: "१" DEVANAGARI DIGIT ONE + key(VOWEL_SIGN_AU, "\u094C", joinMoreKeys( + moreKey(VOWEL_SIGN_AU + "\u0902", "\u094C\u0902"), + "\u0967", "1")), + // U+0948: "ै" DEVANAGARI VOWEL SIGN AI + // U+0948/U+0902: "ैं" DEVANAGARI VOWEL SIGN AI/DEVANAGARI SIGN ANUSVARA + // U+0968: "२" DEVANAGARI DIGIT TWO + key(VOWEL_SIGN_AI, "\u0948", joinMoreKeys( + moreKey(VOWEL_SIGN_AI + "\u0902", "\u0948\u0902"), + "\u0968", "2")), + // U+093E: "ा" DEVANAGARI VOWEL SIGN AA + // U+093E/U+0902: "ां" DEVANAGARI VOWEL SIGN AA/DEVANAGARI SIGN ANUSVARA + // U+093E/U+0901: "ाँ" DEVANAGARI VOWEL SIGN AA/DEVANAGARI SIGN CANDRABINDU + // U+0969: "३" DEVANAGARI DIGIT THREE + key(VOWEL_SIGN_AA, "\u093E", joinMoreKeys( + moreKey(VOWEL_SIGN_AA + "\u0902", "\u093E\u0902"), + moreKey(VOWEL_SIGN_AA + "\u0901", "\u093E\u0901"), + "\u0969", "3")), + // U+0940: "ी" DEVANAGARI VOWEL SIGN II + // U+0940/U+0902: "ीं" DEVANAGARI VOWEL SIGN II/DEVANAGARI SIGN ANUSVARA + // U+096A: "४" DEVANAGARI DIGIT FOUR + key(VOWEL_SIGN_II, "\u0940", joinMoreKeys( + moreKey(VOWEL_SIGN_II + "\u0902", "\u0940\u0902"), + "\u096A", "4")), + // U+0942: "ू" DEVANAGARI VOWEL SIGN UU + // U+0942/U+0902: "ूं" DEVANAGARI VOWEL SIGN UU/DEVANAGARI SIGN ANUSVARA + // U+0942/U+0901: "ूँ" DEVANAGARI VOWEL SIGN UU/DEVANAGARI SIGN CANDRABINDU + // U+096B: "५" DEVANAGARI DIGIT FIVE + key(VOWEL_SIGN_UU, "\u0942", joinMoreKeys( + moreKey(VOWEL_SIGN_UU + "\u0902", "\u0942\u0902"), + moreKey(VOWEL_SIGN_UU + "\u0901", "\u0942\u0901"), + "\u096B", "5")), + // U+092C: "ब" DEVANAGARI LETTER BA + // U+092C/U+0952: "ब॒" DEVANAGARI LETTER BA/DEVANAGARI STRESS SIGN ANUDATTA + // U+096C: "६" DEVANAGARI DIGIT SIX + key("\u092C", joinMoreKeys("\u092C\u0952", "\u096C", "6")), + // U+0939: "ह" DEVANAGARI LETTER HA + // U+096D: "७" DEVANAGARI DIGIT SEVEN + key("\u0939", joinMoreKeys("\u096D", "7")), + // U+0917: "ग" DEVANAGARI LETTER GA + // U+091C/U+094D/U+091E: + // "ज्ञ" DEVANAGARI LETTER JA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER NYA + // U+0917/U+093C: "ग़" DEVANAGARI LETTER GA/DEVANAGARI SIGN NUKTA + // U+0917/U+0952: "ग॒" DEVANAGARI LETTER GA/DEVANAGARI STRESS SIGN ANUDATTA + // U+096E: "८" DEVANAGARI DIGIT EIGHT + key("\u0917", joinMoreKeys("\u091C\u094D\u091E", "\u0917\u093C", "\u0917\u0952", + "\u096E", "8")), + // U+0926: "द" DEVANAGARI LETTER DA + // U+096F: "९" DEVANAGARI DIGIT NINE + key("\u0926", joinMoreKeys("\u096F", "9")), + // U+091C: "ज" DEVANAGARI LETTER JA + // U+091C/U+0952: "ज॒" DEVANAGARI LETTER JA/DEVANAGARI STRESS SIGN ANUDATTA + // U+091C/U+094D/U+091E: + // "ज्ञ" DEVANAGARI LETTER JA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER NYA + // U+091C/U+093C: "ज़" DEVANAGARI LETTER JA/DEVANAGARI SIGN NUKTA + // U+0966: "०" DEVANAGARI DIGIT ZERO + key("\u091C", joinMoreKeys("\u091C\u0952", "\u091C\u094D\u091E", "\u091C\u093C", + "\u0966", "0")), + // U+0921: "ड" DEVANAGARI LETTER DDA + // U+0921/U+0952: "ड॒" DEVANAGARI LETTER DDA/DEVANAGARI STRESS SIGN ANUDATTA + // U+0921/U+093C: "ड़" DEVANAGARI LETTER DDA/DEVANAGARI SIGN NUKTA + key("\u0921", joinMoreKeys("\u0921\u0952", "\u0921\u093C"))) + .setKeysOfRow(2, + // U+094B: "ो" DEVANAGARI VOWEL SIGN O + // U+094B/U+0902: "қं" DEVANAGARI VOWEL SIGN O/DEVANAGARI SIGN ANUSVARA + // U+0949: "ॉ" DEVANAGARI VOWEL SIGN CANDRA O + // U+094A: "ॊ" DEVANAGARI VOWEL SIGN SHORT O + key(VOWEL_SIGN_O, "\u094B", joinMoreKeys( + moreKey(VOWEL_SIGN_O + "\u0902", "\u094B\u0902"), + moreKey(VOWEL_SIGN_CANDRA_O, "\u0949"), + moreKey(VOWEL_SIGN_SHORT_O, "\u094A"))), + // U+0947: "े" DEVANAGARI VOWEL SIGN E + // U+0947/U+0902: "ें" DEVANAGARI VOWEL SIGN E/DEVANAGARI SIGN ANUSVARA + key(VOWEL_SIGN_E, "\u0947", + moreKey(VOWEL_SIGN_E + "\u0902", "\u0947\u0902")), + // U+094D: "्" DEVANAGARI SIGN VIRAMA + key(SIGN_VIRAMA, "\u094D"), + // U+093F: "ि" DEVANAGARI VOWEL SIGN I + // U+093F/U+0902: "िं" DEVANAGARI VOWEL SIGN I/DEVANAGARI SIGN ANUSVARA + key(VOWEL_SIGN_I, "\u093F", + moreKey("\u093F" + SIGN_ANUSVARA, "\u093F\u0902")), + // U+0941: "ु" DEVANAGARI VOWEL SIGN U + // U+0941/U+0902: "ुं" DEVANAGARI VOWEL SIGN U/DEVANAGARI SIGN ANUSVARA + // U+0941/U+0901: "ुँ" DEVANAGARI VOWEL SIGN U/DEVANAGARI SIGN CANDRABINDU + key(VOWEL_SIGN_U, "\u0941", joinMoreKeys( + moreKey(VOWEL_SIGN_U + "\u0902", "\u0941\u0902"), + moreKey(VOWEL_SIGN_U + "\u0901", "\u0941\u0901"))), + // U+092A: "प" DEVANAGARI LETTER PA + "\u092A", + // U+0930: "र" DEVANAGARI LETTER RA + // U+090B: "ऋ" DEVANAGARI LETTER VOCALIC R + // U+0930/U+093C: "ऱ" DEVANAGARI LETTER RA/DEVANAGARI SIGN NUKTA + // U+0960: "ॠ" DEVANAGARI LETTER VOCALIC RR + key("\u0930", joinMoreKeys("\u090B", "\u0930\u093C", "\u0960")), + // U+0915: "क" DEVANAGARI LETTER KA + // U+0915/U+093C: "क़" DEVANAGARI LETTER KA/DEVANAGARI SIGN NUKTA + key("\u0915", moreKey("\u0915\u093C")), + // U+0924: "त" DEVANAGARI LETTER TA + // U+0924/U+094D/U+0930: + // "त्र" DEVANAGARI LETTER TA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + key("\u0924", moreKey("\u0924\u094D\u0930")), + // U+091A: "च" DEVANAGARI LETTER CA + // U+091F: "ट" DEVANAGARI LETTER TTA + "\u091A","\u091F") + .setKeysOfRow(3, + // U+0949: "ॉ" DEVANAGARI VOWEL SIGN CANDRA O + key(VOWEL_SIGN_CANDRA_O, "\u0949"), + // U+0902: "ं" DEVANAGARI SIGN ANUSVARA + key(SIGN_ANUSVARA, "\u0902"), + // U+092E: "म" DEVANAGARI LETTER MA + // U+0950: "ॐ" DEVANAGARI OM + key("\u092E", moreKey("\u0950")), + // U+0928: "न" DEVANAGARI LETTER NA + // U+091E: "ञ" DEVANAGARI LETTER NYA + // U+0919: "ङ" DEVANAGARI LETTER NGA + // U+0928/U+093C: "ऩ" DEVANAGARI LETTER NA/DEVANAGARI SIGN NUKTA + key("\u0928", joinMoreKeys("\u091E", "\u0919", "\u0928\u093C")), + // U+0935: "व" DEVANAGARI LETTER VA + "\u0935", + // U+0932: "ल" DEVANAGARI LETTER LA + // U+090C: "ऌ" DEVANAGARI LETTER VOCALIC L + // U+0961: "ॡ" DEVANAGARI LETTER VOCALIC LL + key("\u0932", joinMoreKeys("\u090C", "\u0961")), + // U+0938: "स" DEVANAGARI LETTER SA + "\u0938", + // U+092F: "य" DEVANAGARI LETTER YA + // U+095F: "य़" DEVANAGARI LETTER YYA + key("\u092F", moreKey("\u095F")), + // U+093C: "़" DEVANAGARI SIGN NUKTA + // U+097D: "ॽ" DEVANAGARI LETTER GLOTTAL STOP + // U+0970: "॰" DEVANAGARI ABBREVIATION SIGN + // U+093D: "ऽ" DEVANAGARI SIGN AVAGRAHA + key(SIGN_NUKTA, "\u093C", joinMoreKeys( + moreKey(LETTER_GLOTTAL_STOP, "\u097D"), + moreKey(ABBREVIATION_SIGN, "\u0970"), + moreKey(SIGN_AVAGRAHA, "\u093D")))) + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0914: "औ" DEVANAGARI LETTER AU + // U+0912/U+0902: "ऒं" DEVANAGARI LETTER SHORT O//DEVANAGARI SIGN ANUSVARA + key("\u0914", moreKey("\u0912\u0902")), + // U+0910: "ऐ" DEVANAGARI LETTER AI + // U+0910/U+0902: "ऐं" DEVANAGARI LETTER AI/DEVANAGARI SIGN ANUSVARA + key("\u0910", moreKey("\u0910\u0902")), + // U+0906: "आ" DEVANAGARI LETTER AA + // U+0906/U+0902: "आं" DEVANAGARI LETTER AA/DEVANAGARI SIGN ANUSVARA + // U+0906/U+0901: "आँ" DEVANAGARI LETTER AA/DEVANAGARI SIGN CANDRABINDU + key("\u0906", joinMoreKeys("\u0906\u0902", "\u0906\u0901")), + // U+0908: "ई" DEVANAGARI LETTER II + // U+0908/U+0902: "ईं" DEVANAGARI LETTER II/DEVANAGARI SIGN ANUSVARA + key("\u0908", moreKey("\u0908\u0902")), + // U+090A: "ऊ" DEVANAGARI LETTER UU + // U+090A/U+0902: "ऊं" DEVANAGARI LETTER UU/DEVANAGARI SIGN ANUSVARA + // U+090A/U+0901: "ऊँ" DEVANAGARI LETTER UU/DEVANAGARI SIGN CANDRABINDU + key("\u090A", joinMoreKeys("\u090A\u0902", "\u090A\u0901")), + // U+092D: "भ" DEVANAGARI LETTER BHA + // U+0903: "ः" DEVANAGARI SIGN VISARGA + // U+0918: "घ" DEVANAGARI LETTER GHA + "\u092D", key(SIGN_VISARGA, "\u0903"), "\u0918", + // U+0927: "ध" DEVANAGARI LETTER DHA + // U+0915/U+094D/U+0937: + // "क्ष" DEVANAGARI LETTER KA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER SSA + // U+0936/U+094D/U+0930: + // "श्र" DEVANAGARI LETTER SHA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + key("\u0927", joinMoreKeys("\u0915\u094D\u0937", "\u0936\u094D\u0930")), + // U+091D: "झ" DEVANAGARI LETTER JHA + // U+0922: "ढ" DEVANAGARI LETTER DDHA + "\u091D", "\u0922") + .setKeysOfRow(2, + // U+0913: "ओ" DEVANAGARI LETTER O + // U+0913/U+0902: "ओं" DEVANAGARI LETTER O/DEVANAGARI SIGN ANUSVARA + // U+0911: "ऑ" DEVANAGARI LETTER CANDRA O + // U+0912: "ऒ" DEVANAGARI LETTER SHORT O + key("\u0913", joinMoreKeys("\u0913\u0902", "\u0911", "\u0912")), + // U+090F: "ए" DEVANAGARI LETTER E + // U+090F/U+0902: "एं" DEVANAGARI LETTER E/DEVANAGARI SIGN ANUSVARA + // U+090F/U+0901: "एँ" DEVANAGARI LETTER E/DEVANAGARI SIGN CANDRABINDU + // U+090D: "ऍ" DEVANAGARI LETTER CANDRA E + // U+090E: "ऎ" DEVANAGARI LETTER SHORT E + key("\u090F", joinMoreKeys("\u090F\u0902", "\u090F\u0901", "\u090D", "\u090E")), + // U+0905: "अ" DEVANAGARI LETTER A + // U+0905/U+0902: "अं" DEVANAGARI LETTER A/DEVANAGARI SIGN ANUSVARA + // U+0905/U+0901: "अँ" DEVANAGARI LETTER A/DEVANAGARI SIGN CANDRABINDU + key("\u0905", joinMoreKeys("\u0905\u0902", "\u0905\u0901")), + // U+0907: "इ" DEVANAGARI LETTER I + // U+0907/U+0902: "इं" DEVANAGARI LETTER I/DEVANAGARI SIGN ANUSVARA + // U+0907/U+0901: "इं" DEVANAGARI LETTER I/DEVANAGARI SIGN CANDRABINDU + key("\u0907", joinMoreKeys("\u0907\u0902", "\u0907\u0901")), + // U+0909: "उ" DEVANAGARI LETTER U + // U+0909/U+0902: "उं" DEVANAGARI LETTER U/DEVANAGARI SIGN ANUSVARA + // U+0909/U+0901: "उँ" DEVANAGARI LETTER U/DEVANAGARI SIGN CANDRABINDU + key("\u0909", joinMoreKeys("\u0909\u0902", "\u0909\u0901")), + // U+092B: "फ" DEVANAGARI LETTER PHA + // U+092B/U+093C: "फ़" DEVANAGARI LETTER PHA/DEVANAGARI SIGN NUKTA + key("\u092B", moreKey("\u092B\u093C")), + // U+0931: "ऱ" DEVANAGARI LETTER RRA + // U+094D/U+0930: "्र" DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + // U+0930/U+094D: "र्" DEVANAGARI LETTER RA/DEVANAGARI SIGN VIRAMA + key("\u0931", joinMoreKeys("\u094D\u0930", "\u0930\u094D")), + // U+0916: "ख" DEVANAGARI LETTER KHA + // U+0916/U+093C: "ख़" DEVANAGARI LETTER KHA/DEVANAGARI SIGN NUKTA + key("\u0916", moreKey("\u0916\u093C")), + // U+0925: "थ" DEVANAGARI LETTER THA + // U+091B: "छ" DEVANAGARI LETTER CHA + // U+0920: "ठ" DEVANAGARI LETTER TTHA + "\u0925", "\u091B", "\u0920") + .setKeysOfRow(3, + // U+0911: "ऑ" DEVANAGARI LETTER CANDRA O + "\u0911", + // U+0901: "ँ" DEVANAGARI SIGN CANDRABINDU + // U+0945: "ॅ" DEVANAGARI VOWEL SIGN CANDRA E + key(SIGN_CANDRABINDU, "\u0901", moreKey(VOWEL_SIGN_CANDRA_E, "\u0945")), + // U+0923: "ण" DEVANAGARI LETTER NNA + // U+0929: "ऩ" DEVANAGARI LETTER NNNA + "\u0923", "\u0929", + // U+0933: "ळ" DEVANAGARI LETTER LLA + // U+0934: "ऴ" DEVANAGARI LETTER LLLA + key("\u0933", moreKey("\u0934")), + // U+0936: "श" DEVANAGARI LETTER SHA + // U+0937: "ष" DEVANAGARI LETTER SSA + "\u0936", "\u0937", + // U+0943: "ृ" DEVANAGARI VOWEL SIGN VOCALIC R + // U+0944: "ॄ" DEVANAGARI VOWEL SIGN VOCALIC RR + key(VOWEL_SIGN_VOCALIC_R, "\u0943", moreKey(VOWEL_SIGN_VOCALIC_RR, "\u0944")), + // U+091E: "ञ" DEVANAGARI LETTER NYA + "\u091E") + .build(); + + static class HindiSymbols extends Symbols { + public HindiSymbols(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + // U+0967: "१" DEVANAGARI DIGIT ONE + // U+00B9: "¹" SUPERSCRIPT ONE + // U+00BD: "½" VULGAR FRACTION ONE HALF + // U+2153: "⅓" VULGAR FRACTION ONE THIRD + // U+00BC: "¼" VULGAR FRACTION ONE QUARTER + // U+215B: "⅛" VULGAR FRACTION ONE EIGHTH + .replaceKeyOfLabel("1", key("\u0967", + joinMoreKeys("1", "\u00B9", "\u00BD", "\u2153", "\u00BC", "\u215B"))) + // U+0968: "२" DEVANAGARI DIGIT TWO + // U+00B2: "²" SUPERSCRIPT TWO + // U+2154: "⅔" VULGAR FRACTION TWO THIRDS + .replaceKeyOfLabel("2", key("\u0968", joinMoreKeys("2", "\u00B2", "\u2154"))) + // U+0969: "३" DEVANAGARI DIGIT THREE + // U+00B3: "³" SUPERSCRIPT THREE + // U+00BE: "¾" VULGAR FRACTION THREE QUARTERS + // U+215C: "⅜" VULGAR FRACTION THREE EIGHTHS + .replaceKeyOfLabel("3", key("\u0969", + joinMoreKeys("3", "\u00B3", "\u00BE","\u215C"))) + // U+096A: "४" DEVANAGARI DIGIT FOUR + // U+2074: "⁴" SUPERSCRIPT FOUR + .replaceKeyOfLabel("4", key("\u096A", joinMoreKeys("4", "\u2074"))) + // U+096B: "५" DEVANAGARI DIGIT FIVE + // U+215D: "⅝" VULGAR FRACTION FIVE EIGHTHS + .replaceKeyOfLabel("5", key("\u096B", joinMoreKeys("5", "\u215D"))) + // U+096C: "६" DEVANAGARI DIGIT SIX + .replaceKeyOfLabel("6", key("\u096C", moreKey("6"))) + // U+096D: "७" DEVANAGARI DIGIT SEVEN + // U+215E: "⅞" VULGAR FRACTION SEVEN EIGHTHS + .replaceKeyOfLabel("7", key("\u096D", joinMoreKeys("7", "\u215E"))) + // U+096E: "८" DEVANAGARI DIGIT EIGHT + .replaceKeyOfLabel("8", key("\u096E", moreKey("8"))) + // U+096F: "९" DEVANAGARI DIGIT NINE + .replaceKeyOfLabel("9", key("\u096F", moreKey("9"))) + // U+0966: "०" DEVANAGARI DIGIT ZERO + // U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N + // U+2205: "∅" EMPTY SET + .replaceKeyOfLabel("0", key("\u0966", joinMoreKeys("0", "\u207F", "\u2205"))) + .build(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/HindiCompact.java b/tests/src/org/kelar/inputmethod/keyboard/layout/HindiCompact.java new file mode 100644 index 000000000..253447dfe --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/HindiCompact.java @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import static org.kelar.inputmethod.keyboard.layout.DevanagariLetterConstants.*; + +import org.kelar.inputmethod.keyboard.layout.Hindi.HindiSymbols; +import org.kelar.inputmethod.keyboard.layout.customizer.HindiCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * The Hindi Compact keyboard. + */ +public final class HindiCompact extends LayoutBase { + private static final String LAYOUT_NAME = "hindi_compact"; + + public HindiCompact(final Locale locale) { + super(new HindiCompactCustomizer(locale), HindiSymbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class HindiCompactCustomizer extends HindiCustomizer { + HindiCompactCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0914: "औ" DEVANAGARI LETTER AU + // U+094C: "ौ" DEVANAGARI VOWEL SIGN AU + // U+0967: "१" DEVANAGARI DIGIT ONE + key("\u0914", joinMoreKeys(moreKey(VOWEL_SIGN_AU, "\u094C"), "\u0967", "1")), + // U+0910: "ऐ" DEVANAGARI LETTER AI + // U+0948: "ै" DEVANAGARI VOWEL SIGN AI + // U+0968: "२" DEVANAGARI DIGIT TWO + key("\u0910", joinMoreKeys(moreKey(VOWEL_SIGN_AI, "\u0948"), "\u0968", "2")), + // U+0906: "आ" DEVANAGARI LETTER AA + // U+093E: "ा" DEVANAGARI VOWEL SIGN AA + // U+0969: "३" DEVANAGARI DIGIT THREE + key("\u0906", joinMoreKeys(moreKey(VOWEL_SIGN_AA, "\u093E"), "\u0969", "3")), + // U+0908: "ई" DEVANAGARI LETTER II + // U+0940: "ी" DEVANAGARI VOWEL SIGN II + // U+096A: "४" DEVANAGARI DIGIT FOUR + key("\u0908", joinMoreKeys(moreKey(VOWEL_SIGN_II, "\u0940"), "\u096A", "4")), + // U+090A: "ऊ" DEVANAGARI LETTER UU + // U+0942: "ू" DEVANAGARI VOWEL SIGN UU + // U+096B: "५" DEVANAGARI DIGIT FIVE + key("\u090A", joinMoreKeys(moreKey(VOWEL_SIGN_UU, "\u0942"), "\u096B", "5")), + // U+092C: "ब" DEVANAGARI LETTER BA + // U+092D: "भ" DEVANAGARI LETTER BHA + // U+096C: "६" DEVANAGARI DIGIT SIX + key("\u092C", joinMoreKeys("\u092D", "\u096C", "6")), + // U+0939: "ह" DEVANAGARI LETTER HA + // U+096D: "७" DEVANAGARI DIGIT SEVEN + key("\u0939", joinMoreKeys("\u096D", "7")), + // U+0917: "ग" DEVANAGARI LETTER GA + // U+0918: "घ" DEVANAGARI LETTER GHA + // U+096E: "८" DEVANAGARI DIGIT EIGHT + key("\u0917", joinMoreKeys("\u0918", "\u096E", "8")), + // U+0926: "द" DEVANAGARI LETTER DA + // U+0927: "ध" DEVANAGARI LETTER DHA + // U+096F: "९" DEVANAGARI DIGIT NINE + key("\u0926", joinMoreKeys("\u0927", "\u096F", "9")), + // U+091C: "ज" DEVANAGARI LETTER JA + // U+091D: "झ" DEVANAGARI LETTER JHA + // U+091C/U+094D/U+091E: + // "ज्ञ" DEVANAGARI LETTER JA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER NYA + // U+0966: "०" DEVANAGARI DIGIT ZERO + key("\u091C", joinMoreKeys("\u091D", "\u091C\u094D\u091E", "\u0966", "0")), + // U+0921: "ड" DEVANAGARI LETTER DDA + // U+0922: "ढ" DEVANAGARI LETTER DDHA + key("\u0921", moreKey("\u0922"))) + .setKeysOfRow(2, + // U+0913: "ओ" DEVANAGARI LETTER O + // U+094B: "ो" DEVANAGARI VOWEL SIGN O + key("\u0913", moreKey(VOWEL_SIGN_O, "\u094B")), + // U+090F: "ए" DEVANAGARI LETTER E + // U+0947: "े" DEVANAGARI VOWEL SIGN E + key("\u090F", moreKey(VOWEL_SIGN_E, "\u0947")), + // U+0905: "अ" DEVANAGARI LETTER A + // U+094D: "्" DEVANAGARI SIGN VIRAMA + key("\u0905", moreKey(SIGN_VIRAMA, "\u094D")), + // U+0907: "इ" DEVANAGARI LETTER I + // U+093F: "ि" DEVANAGARI VOWEL SIGN I + key("\u0907", moreKey(VOWEL_SIGN_I, "\u093F")), + // U+0909: "उ" DEVANAGARI LETTER U + // U+0941: "ु" DEVANAGARI VOWEL SIGN U + key("\u0909", moreKey(VOWEL_SIGN_U, "\u0941")), + // U+092A: "प" DEVANAGARI LETTER PA + // U+092B: "फ" DEVANAGARI LETTER PHA + key("\u092A", moreKey("\u092B")), + // U+0930: "र" DEVANAGARI LETTER RA + // U+090B: "ऋ" DEVANAGARI LETTER VOCALIC R + // U+0943: "ृ" DEVANAGARI VOWEL SIGN VOCALIC R + key("\u0930", joinMoreKeys("\u090B", moreKey(VOWEL_SIGN_VOCALIC_R, "\u0943"))), + // U+0915: "क" DEVANAGARI LETTER KA + // U+0916: "ख" DEVANAGARI LETTER KHA + key("\u0915", moreKey("\u0916")), + // U+0924: "त" DEVANAGARI LETTER TA + // U+0925: "थ" DEVANAGARI LETTER THA + // U+0924/U+094D/U+0930: + // "त्र" DEVANAGARI LETTER TA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + key("\u0924", joinMoreKeys("\u0925", "\u0924\u094D\u0930")), + // U+091A: "च" DEVANAGARI LETTER CA + // U+091B: "छ" DEVANAGARI LETTER CHA + key("\u091A", moreKey("\u091B")), + // U+091F: "ट" DEVANAGARI LETTER TTA + // U+0920: "ठ" DEVANAGARI LETTER TTHA + key("\u091F", moreKey("\u0920"))) + .setKeysOfRow(3, + // U+0911: "ऑ" DEVANAGARI LETTER CANDRA O + // U+0949: "ॉ" DEVANAGARI VOWEL SIGN CANDRA O + key("\u0911", moreKey(VOWEL_SIGN_CANDRA_O, "\u0949")), + // U+094D: "्" DEVANAGARI SIGN VIRAMA + // U+0945: "ॅ" DEVANAGARI VOWEL SIGN CANDRA E + // U+090D: "ऍ" DEVANAGARI LETTER CANDRA E + key(SIGN_VIRAMA, "\u094D", joinMoreKeys( + moreKey(VOWEL_SIGN_CANDRA_E, "\u0945"), "\u090D")), + // U+0902: "ं" DEVANAGARI SIGN ANUSVARA + // U+0903: "ः" DEVANAGARI SIGN VISARGA + // U+0901: "ँ" DEVANAGARI SIGN CANDRABINDU + // U+093C: "़" DEVANAGARI SIGN NUKTA + key(SIGN_ANUSVARA, "\u0902", joinMoreKeys( + moreKey(SIGN_VISARGA, "\u0903"), + moreKey(SIGN_CANDRABINDU, "\u0901"), + moreKey(SIGN_NUKTA, "\u093C"))), + // U+092E: "म" DEVANAGARI LETTER MA + // U+0950: "ॐ" DEVANAGARI OM + key("\u092E", moreKey("\u0950")), + // U+0928: "न" DEVANAGARI LETTER NA + // U+0923: "ण" DEVANAGARI LETTER NNA + // U+091E: "ञ" DEVANAGARI LETTER NYA + // U+0919: "ङ" DEVANAGARI LETTER NGA + key("\u0928", joinMoreKeys("\u0923", "\u091E", "\u0919")), + // U+0935: "व" DEVANAGARI LETTER VA + // U+0932: "ल" DEVANAGARI LETTER LA + "\u0935", "\u0932", + // U+0938: "स" DEVANAGARI LETTER SA + // U+0936: "श" DEVANAGARI LETTER SHA + // U+0937: "ष" DEVANAGARI LETTER SSA + // U+0936/U+094D/U+0930: + // "श्र" DEVANAGARI LETTER SHA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + key("\u0938", joinMoreKeys("\u0936", "\u0937", "\u0936\u094D\u0930")), + // U+092F: "य" DEVANAGARI LETTER YA + // U+0915/U+094D/U+0937: + // "क्ष" DEVANAGARI LETTER KA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER SSA + "\u092F", "\u0915\u094D\u0937") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Kannada.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Kannada.java new file mode 100644 index 000000000..b7e843314 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Kannada.java @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Kannada keyboard. + */ +public final class Kannada extends LayoutBase { + private static final String LAYOUT_NAME = "kannada"; + + public Kannada(final Locale locale) { + super(new KannadaCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class KannadaCustomizer extends LayoutCustomizer { + KannadaCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return KANNADA_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + @Override + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY, key(ZWNJ_KEY, ZWJ_KEY)); + } + + // U+0C85: "ಅ" KANNADA LETTER A + // U+0C86: "ಆ" KANNADA LETTER AA + // U+0C87: "ಇ" KANNADA LETTER I + private static final ExpectedKey KANNADA_ALPHABET_KEY = key( + "\u0C85\u0C86\u0C87", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0CCC: "ೌ" KANNADA VOWEL SIGN AU + // U+0C94: "ಔ" KANNADA LETTER AU + // U+0CE7: "೧" KANNADA DIGIT ONE + key("\u0CCC", joinMoreKeys("\u0C94", "\u0CE7", "1")), + // U+0CC8: "ೈ" KANNADA VOWEL SIGN AI + // U+0C90: "ಐ" KANNADA LETTER AI + // U+0CE8: "೨" KANNADA DIGIT TWO + key("\u0CC8", joinMoreKeys("\u0C90", "\u0CE8", "2")), + // U+0CBE: "ಾ" KANNADA VOWEL SIGN AA + // U+0C86: "ಆ" KANNADA LETTER AA + // U+0CE9: "೩" KANNADA DIGIT THREE + key("\u0CBE", joinMoreKeys("\u0C86", "\u0CE9", "3")), + // U+0CC0: "ೀ" KANNADA VOWEL SIGN II + // U+0C88: "ಈ" KANNADA LETTER II + // U+0CEA: "೪" KANNADA DIGIT FOUR + key("\u0CC0", joinMoreKeys("\u0C88", "\u0CEA", "4")), + // U+0CC2: "ೂ" KANNADA VOWEL SIGN UU + // U+0C8A: "ಊ" KANNADA LETTER UU + // U+0CEB: "೫" KANNADA DIGIT FIVE + key("\u0CC2", joinMoreKeys("\u0C8A", "\u0CEB", "5")), + // U+0CAC: "ಬ" KANNADA LETTER BA + // U+0CAD: "ಭ" KANNADA LETTER BHA + // U+0CEC: "೬" KANNADA DIGIT SIX + key("\u0CAC", joinMoreKeys("\u0CAD", "\u0CEC", "6")), + // U+0CB9: "ಹ" KANNADA LETTER HA + // U+0C99: "ಙ" KANNADA LETTER NGA + // U+0CED: "೭" KANNADA DIGIT SEVEN + key("\u0CB9", joinMoreKeys("\u0C99", "\u0CED", "7")), + // U+0C97: "ಗ" KANNADA LETTER GA + // U+0C98: "ಘ" KANNADA LETTER GHA + // U+0CEE: "೮" KANNADA DIGIT EIGHT + key("\u0C97", joinMoreKeys("\u0C98", "\u0CEE", "8")), + // U+0CA6: "ದ" KANNADA LETTER DA + // U+0CA7: "ಧ" KANNADA LETTER DHA + // U+0CEF: "೯" KANNADA DIGIT NINE + key("\u0CA6", joinMoreKeys("\u0CA7", "\u0CEF", "9")), + // U+0C9C: "ಜ" KANNADA LETTER JA + // U+0C9D: "ಝ" KANNADA LETTER JHA + // U+0CE6: "೦" KANNADA DIGIT ZERO + key("\u0C9C", joinMoreKeys("\u0C9D", "\u0CE6", "0")), + // U+0CA1: "ಡ" KANNADA LETTER DDA + // U+0CA2: "ಢ" KANNADA LETTER DDHA + key("\u0CA1", moreKey("\u0CA2"))) + .setKeysOfRow(2, + // U+0CCB: "ೋ" KANNADA VOWEL SIGN OO + // U+0C93: "ಓ" KANNADA LETTER OO + key("\u0CCB", moreKey("\u0C93")), + // U+0CC7: "ೇ" KANNADA VOWEL SIGN EE + // U+0C8F: "ಏ" KANNADA LETTER EE + key("\u0CC7", moreKey("\u0C8F")), + // U+0CCD: "್" KANNADA SIGN VIRAMA + // U+0C85: "ಅ" KANNADA LETTER A + key("\u0CCD", moreKey("\u0C85")), + // U+0CBF: "ಿ" KANNADA VOWEL SIGN I + // U+0C87: "ಇ" KANNADA LETTER I + key("\u0CBF", moreKey("\u0C87")), + // U+0CC1: "ು" KANNADA VOWEL SIGN U + // U+0C89: "ಉ" KANNADA LETTER U + key("\u0CC1", moreKey("\u0C89")), + // U+0CAA: "ಪ" KANNADA LETTER PA + // U+0CAB: "ಫ" KANNADA LETTER PHA + key("\u0CAA", moreKey("\u0CAB")), + // U+0CB0: "ರ" KANNADA LETTER RA + // U+0CB1: "ಱ" KANNADA LETTER RRA + // U+0CC3: "ೃ" KANNADA VOWEL SIGN VOCALIC R + key("\u0CB0", joinMoreKeys("\u0CB1", "\u0CC3")), + // U+0C95: "ಕ" KANNADA LETTER KA + // U+0C96: "ಖ" KANNADA LETTER KHA + key("\u0C95", moreKey("\u0C96")), + // U+0CA4: "ತ" KANNADA LETTER TA + // U+0CA5: "ಥ" KANNADA LETTER THA + key("\u0CA4", moreKey("\u0CA5")), + // U+0C9A: "ಚ" KANNADA LETTER CA + // U+0C9B: "ಛ" KANNADA LETTER CHA + key("\u0C9A", moreKey("\u0C9B")), + // U+0C9F: "ಟ" KANNADA LETTER TTA + // U+0CA0: "ಠ" KANNADA LETTER TTHA + key("\u0C9F", moreKey("\u0CA0"))) + .setKeysOfRow(3, + // U+0CC6: "ೆ" KANNADA VOWEL SIGN E + // U+0C92: "ಒ" KANNADA LETTER O + key("\u0CC6", moreKey("\u0C92")), + // U+0C82: "ಂ" KANNADA SIGN ANUSVARA + // U+0C8E: "ಎ" KANNADA LETTER E + key("\u0C82", moreKey("\u0C8E")), + // U+0CAE: "ಮ" KANNADA LETTER MA + "\u0CAE", + // U+0CA8: "ನ" KANNADA LETTER NA + // U+0CA3: "ಣ" KANNADA LETTER NNA + key("\u0CA8", moreKey("\u0CA3")), + // U+0CB5: "ವ" KANNADA LETTER VA + "\u0CB5", + // U+0CB2: "ಲ" KANNADA LETTER LA + // U+0CB3: "ಳ" KANNADA LETTER LLA + key("\u0CB2", moreKey("\u0CB3")), + // U+0CB8: "ಸ" KANNADA LETTER SA + // U+0CB6: "ಶ" KANNADA LETTER SHA + key("\u0CB8", moreKey("\u0CB6")), + // U+0C8B: "ಋ" KANNADA LETTER VOCALIC R + // U+0CCD/U+0CB0: "್ರ" KANNADA SIGN VIRAMA/KANNADA LETTER RA + key("\u0C8B", moreKey("\u0CCD\u0CB0")), + // U+0CB7: "ಷ" KANNADA LETTER SSA + // U+0C95/U+0CCD/U+0CB7: + // "ಕ್ಷ" KANNADA LETTER RA/KANNADA SIGN VIRAMA/KANNADA LETTER SSA + key("\u0CB7", moreKey("\u0C95\u0CCD\u0CB7")), + // U+0CAF: "ಯ" KANNADA LETTER YA + // U+0C9C/U+0CCD/U+0C9E: + // "ಜ್ಞ" KANNADA LETTER JA/KANNADA SIGN VIRAMA/KANNADA LETTER NYA + key("\u0CAF", moreKey("\u0C9C\u0CCD\u0C9E"))) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Khmer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Khmer.java new file mode 100644 index 000000000..aff10226c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Khmer.java @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Khmer alphabet keyboard. + */ +public final class Khmer extends LayoutBase { + private static final String LAYOUT_NAME = "khmer"; + + public Khmer(final Locale locale) { + super(new KhmerCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class KhmerCustomizer extends LayoutCustomizer { + KhmerCustomizer(final Locale locale) { super(locale); } + + @Override + public int getNumberOfRows() { return 5; } + + @Override + public ExpectedKey getAlphabetKey() { return KHMER_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_DOLLAR_WITH_RIEL; } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { return EMPTY_KEYS; } + + // U+1780: "ក" KHMER LETTER KA + // U+1781: "ខ" KHMER LETTER KHA + // U+1782: "គ" KHMER LETTER KO + private static final ExpectedKey KHMER_ALPHABET_KEY = key( + "\u1780\u1781\u1782", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+17DB: "៛" KHMER CURRENCY SYMBOL RIEL + private static final ExpectedKey CURRENCY_DOLLAR_WITH_RIEL = key(Symbols.DOLLAR_SIGN, + moreKey("\u17DB"), Symbols.CENT_SIGN, Symbols.POUND_SIGN, Symbols.EURO_SIGN, + Symbols.YEN_SIGN, Symbols.PESO_SIGN); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + if (isPhone) { + return ALPHABET_COMMON; + } + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + builder.addKeysOnTheRightOfRow(4, (Object[])EXCLAMATION_AND_QUESTION_MARKS); + return builder.build(); + } + + @Override + public ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, + final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+17E1: "១" KHMER DIGIT ONE + // U+17F1: "៱" KHMER SYMBOL LEK ATTAK MUOY + key("\u17E1", joinMoreKeys("1", "\u17F1")), + // U+17E2: "២" KHMER DIGIT TWO + // U+17F2: "៲" KHMER SYMBOL LEK ATTAK PII + key("\u17E2", joinMoreKeys("2", "\u17F2")), + // U+17E3: "៣" KHMER DIGIT THREE + // U+17F3: "៳" KHMER SYMBOL LEK ATTAK BEI + key("\u17E3", joinMoreKeys("3", "\u17F3")), + // U+17E4: "៤" KHMER DIGIT FOUR + // U+17F4: "៴" KHMER SYMBOL LEK ATTAK BUON + key("\u17E4", joinMoreKeys("4", "\u17F4")), + // U+17E5: "៥" KHMER DIGIT FIVE + // U+17F5: "៵" KHMER SYMBOL LEK ATTAK PRAM + key("\u17E5", joinMoreKeys("5", "\u17F5")), + // U+17E6: "៦" KHMER DIGIT SIX + // U+17F6: "៶" KHMER SYMBOL LEK ATTAK PRAM-MUOY + key("\u17E6", joinMoreKeys("6", "\u17F6")), + // U+17E7: "៧" KHMER DIGIT SEVEN + // U+17F7: "៷" KHMER SYMBOL LEK ATTAK PRAM-PII + key("\u17E7", joinMoreKeys("7", "\u17F7")), + // U+17E8: "៨" KHMER DIGIT EIGHT + // U+17F8: "៸" KHMER SYMBOL LEK ATTAK PRAM-BEI + key("\u17E8", joinMoreKeys("8", "\u17F8")), + // U+17E9: "៩" KHMER DIGIT NINE + // U+17F9: "៹" KHMER SYMBOL LEK ATTAK PRAM-BUON + key("\u17E9", joinMoreKeys("9", "\u17F9")), + // U+17E0: "០" KHMER DIGIT ZERO + // U+17F0: "៰" KHMER SYMBOL LEK ATTAK SON + key("\u17E0", joinMoreKeys("0", "\u17F0")), + // U+17A5: "ឥ" KHMER INDEPENDENT VOWEL QI + // U+17A6: "ឦ" KHMER INDEPENDENT VOWEL QII + key("\u17A5", moreKey("\u17A6")), + // U+17B2: "ឲ" KHMER INDEPENDENT VOWEL QOO TYPE TWO + // U+17B1: "ឱ" KHMER INDEPENDENT VOWEL QOO TYPE ONE + key("\u17B2", moreKey("\u17B1"))) + .setKeysOfRow(2, + // U+1786: "ឆ" KHMER LETTER CHA + // U+17B9: "ឹ" KHMER VOWEL SIGN Y + // U+17C1: "េ" KHMER VOWEL SIGN E + // U+179A: "រ" KHMER LETTER RO + // U+178F: "ត" KHMER LETTER TA + // U+1799: "យ" KHMER LETTER YO + // U+17BB: "ុ" KHMER VOWEL SIGN U + // U+17B7: "ិ" KHMER VOWEL SIGN I + // U+17C4: "ោ" KHMER VOWEL SIGN OO + // U+1795: "ផ" KHMER LETTER PHA + // U+17C0: "ៀ" KHMER VOWEL SIGN IE + "\u1786", "\u17B9", "\u17C1", "\u179A", "\u178F", "\u1799", "\u17BB", "\u17B7", + "\u17C4", "\u1795", "\u17C0", + // U+17AA: "ឪ" KHMER INDEPENDENT VOWEL QUUV + // U+17A7: "ឧ" KHMER INDEPENDENT VOWEL QU + // U+17B1: "ឱ" KHMER INDEPENDENT VOWEL QOO TYPE ONE + // U+17B3: "ឳ" KHMER INDEPENDENT VOWEL QAU + // U+17A9: "ឩ" KHMER INDEPENDENT VOWEL QUU + // U+17A8: "ឨ" KHMER INDEPENDENT VOWEL QUK + key("\u17AA", joinMoreKeys("\u17A7", "\u17B1", "\u17B3", "\u17A9", "\u17A8"))) + .setKeysOfRow(3, + // U+17B6: "ា" KHMER VOWEL SIGN AA + // U+179F: "ស" KHMER LETTER SA + // U+178A: "ដ" KHMER LETTER DA + // U+1790: "ថ" KHMER LETTER THA + // U+1784: "ង" KHMER LETTER NGO + // U+17A0: "ហ" KHMER LETTER HA + // U+17D2: "្" KHMER SIGN COENG + // U+1780: "ក" KHMER LETTER KA + // U+179B: "ល" KHMER LETTER LO + // U+17BE: "ើ" KHMER VOWEL SIGN OE + // U+17CB: "់" KHMER SIGN BANTOC + "\u17B6", "\u179F", "\u178A", "\u1790", "\u1784", "\u17A0", "\u17D2", "\u1780", + "\u179B", "\u17BE", "\u17CB", + // U+17AE: "ឮ" KHMER INDEPENDENT VOWEL LYY + // U+17AD: "ឭ" KHMER INDEPENDENT VOWEL LY + // U+17B0: "ឰ" KHMER INDEPENDENT VOWEL QAI + key("\u17AE", joinMoreKeys("\u17AD", "\u17B0"))) + .setKeysOfRow(4, + // U+178B: "ឋ" KHMER LETTER TTHA + // U+1781: "ខ" KHMER LETTER KHA + // U+1785: "ច" KHMER LETTER CA + // U+179C: "វ" KHMER LETTER VO + // U+1794: "ប" KHMER LETTER BA + // U+1793: "ន" KHMER LETTER NO + // U+1798: "ម" KHMER LETTER MO + // U+17BB/U+17C6: "ុំ" KHMER VOWEL SIGN U/KHMER SIGN NIKAHIT + // U+17D4: "។" KHMER SIGN KHAN + // U+17CA: "៊" KHMER SIGN TRIISAP + "\u178B", "\u1781", "\u1785", "\u179C", "\u1794", "\u1793", "\u1798", + "\u17BB\u17C6", "\u17D4", "\u17CA") + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("!", ZWJ_KEY), + // U+17D7: "ៗ" KHMER SIGN LEK TOO + key("\u17D7", ZWNJ_KEY), + // U+17D1: "៑" KHMER SIGN VIRIAM + key("\"", moreKey("\u17D1")), + // U+17DB: "៛" KHMER CURRENCY SYMBOL RIEL + key("\u17DB", joinMoreKeys(Symbols.DOLLAR_SIGN, Symbols.EURO_SIGN)), + // U+17D6: "៖" KHMER SIGN CAMNUC PII KUUH + key("%", moreKey("\u17D6")), + // U+17CD: "៍" KHMER SIGN TOANDAKHIAT + // U+17D9: "៙" KHMER SIGN PHNAEK MUAN + key("\u17CD", moreKey("\u17D9")), + // U+17D0: "័" KHMER SIGN SAMYOK SANNYA + // U+17DA: "៚" KHMER SIGN KOOMUUT + key("\u17D0", moreKey("\u17DA")), + // U+17CF: "៏" KHMER SIGN AHSDA + key("\u17CF", moreKey("*")), + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + key("(", joinMoreKeys("{", "\u00AB")), + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + key(")", joinMoreKeys("}", "\u00BB")), + // U+17CC: "៌" KHMER SIGN ROBAT + // U+00D7: "×" MULTIPLICATION SIGN + key("\u17CC", moreKey("\u00D7")), + // U+17CE: "៎" KHMER SIGN KAKABAT + "\u17CE") + .setKeysOfRow(2, + // U+1788: "ឈ" KHMER LETTER CHO + // U+17DC: "ៜ" KHMER SIGN AVAKRAHASANYA + key("\u1788", moreKey("\u17DC")), + // U+17BA: "ឺ" KHMER VOWEL SIGN YY + // U+17DD: "៝" KHMER SIGN ATTHACAN + key("\u17BA", moreKey("\u17DD")), + // U+17C2: "ែ" KHMER VOWEL SIGN AE + "\u17C2", + // U+17AC: "ឬ" KHMER INDEPENDENT VOWEL RYY + // U+17AB: "ឫ" KHMER INDEPENDENT VOWEL RY + key("\u17AC", moreKey("\u17AB")), + // U+1791: "ទ" KHMER LETTER TO + // U+17BD: "ួ" KHMER VOWEL SIGN UA + // U+17BC: "ូ" KHMER VOWEL SIGN UU + // U+17B8: "ី" KHMER VOWEL SIGN II + // U+17C5: "ៅ" KHMER VOWEL SIGN AU + // U+1797: "ភ" KHMER LETTER PHO + // U+17BF: "ឿ" KHMER VOWEL SIGN YA + // U+17B0: "ឰ" KHMER INDEPENDENT VOWEL QAI + "\u1791", "\u17BD", "\u17BC", "\u17B8", "\u17C5", "\u1797", "\u17BF", "\u17B0") + .setKeysOfRow(3, + // U+17B6/U+17C6: "ាំ" KHMER VOWEL SIGN AA/KHMER SIGN NIKAHIT + // U+17C3: "ៃ" KHMER VOWEL SIGN AI + // U+178C: "ឌ" KHMER LETTER DO + // U+1792: "ធ" KHMER LETTER THO + // U+17A2: "អ" KHMER LETTER QAE + "\u17B6\u17C6", "\u17C3", "\u178C", "\u1792", "\u17A2", + // U+17C7: "ះ" KHMER SIGN REAHMUK + // U+17C8: "ៈ" KHMER SIGN YUUKALEAPINTU + key("\u17C7", moreKey("\u17C8")), + // U+1789: "ញ" KHMER LETTER NYO + "\u1789", + // U+1782: "គ" KHMER LETTER KO + // U+179D: "ឝ" KHMER LETTER SHA + key("\u1782", moreKey("\u179D")), + // U+17A1: "ឡ" KHMER LETTER LA + // U+17C4/U+17C7: "ោះ" KHMER VOWEL SIGN OO/KHMER SIGN REAHMUK + // U+17C9: "៉" KHMER SIGN MUUSIKATOAN + // U+17AF: "ឯ" KHMER INDEPENDENT VOWEL QE + "\u17A1", "\u17C4\u17C7", "\u17C9", "\u17AF") + .setKeysOfRow(4, + // U+178D: "ឍ" KHMER LETTER TTHO + // U+1783: "ឃ" KHMER LETTER KHO + // U+1787: "ជ" KHMER LETTER CO + // U+17C1/U+17C7: "េះ" KHMER VOWEL SIGN E/KHMER SIGN REAHMUK + "\u178D", "\u1783", "\u1787", "\u17C1\u17C7", + // U+1796: "ព" KHMER LETTER PO + // U+179E: "ឞ" KHMER LETTER SSO + key("\u1796", moreKey("\u179E")), + // U+178E: "ណ" KHMER LETTER NNO + // U+17C6: "ំ" KHMER SIGN NIKAHIT + // U+17BB/U+17C7: "ុះ" KHMER VOWEL SIGN U/KHMER SIGN REAHMUK + // U+17D5: "៕" KHMER SIGN BARIYOOSAN + "\u178E", "\u17C6", "\u17BB\u17C7", "\u17D5", "?") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Lao.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Lao.java new file mode 100644 index 000000000..d3c3d0ccc --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Lao.java @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Khmer alphabet keyboard. + */ +public final class Lao extends LayoutBase { + private static final String LAYOUT_NAME = "lao"; + + public Lao(final Locale locale) { + super(new LaoCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class LaoCustomizer extends LayoutCustomizer { + LaoCustomizer(final Locale locale) { super(locale); } + + @Override + public int getNumberOfRows() { return 5; } + + @Override + public ExpectedKey getAlphabetKey() { return LAO_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_KIP; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { return EMPTY_KEYS; } + + // U+0E81: "ກ" LAO LETTER KO + // U+0E82: "ຂ" LAO LETTER KHO SUNG + // U+0E84: "ຄ" LAO LETTER KHO TAM + private static final ExpectedKey LAO_ALPHABET_KEY = key( + "\u0E81\u0E82\u0E84", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+20AD: "₭" KIP SIGN + private static final ExpectedKey CURRENCY_KIP = key("\u20AD", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + if (isPhone) { + return ALPHABET_COMMON; + } + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + builder.addKeysOnTheRightOfRow(4, (Object[])EXCLAMATION_AND_QUESTION_MARKS); + return builder.build(); + } + + @Override + public ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, + final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0EA2: "ຢ" LAO LETTER YO + // U+0ED1: "໑" LAO DIGIT ONE + key("\u0EA2", joinMoreKeys("1", "\u0ED1")), + // U+0E9F: "ຟ" LAO LETTER FO SUNG + // U+0ED2: "໒" LAO DIGIT TWO + key("\u0E9F", joinMoreKeys("2", "\u0ED2")), + // U+0EC2: "ໂ" LAO VOWEL SIGN O + // U+0ED3: "໓" LAO DIGIT THREE + key("\u0EC2", joinMoreKeys("3", "\u0ED3")), + // U+0E96: "ຖ" LAO LETTER THO SUNG + // U+0ED4: "໔" LAO DIGIT FOUR + key("\u0E96", joinMoreKeys("4", "\u0ED4")), + // U+0EB8: "ຸ" LAO VOWEL SIGN U + // U+0EB9: "ູ" LAO VOWEL SIGN UU + "\u0EB8", "\u0EB9", + // U+0E84: "ຄ" LAO LETTER KHO TAM + // U+0ED5: "໕" LAO DIGIT FIVE + key("\u0E84", joinMoreKeys("5", "\u0ED5")), + // U+0E95: "ຕ" LAO LETTER TO + // U+0ED6: "໖" LAO DIGIT SIX + key("\u0E95", joinMoreKeys("6", "\u0ED6")), + // U+0E88: "ຈ" LAO LETTER CO + // U+0ED7: "໗" LAO DIGIT SEVEN + key("\u0E88", joinMoreKeys("7", "\u0ED7")), + // U+0E82: "ຂ" LAO LETTER KHO SUNG + // U+0ED8: "໘" LAO DIGIT EIGHT + key("\u0E82", joinMoreKeys("8", "\u0ED8")), + // U+0E8A: "ຊ" LAO LETTER SO TAM + // U+0ED9: "໙" LAO DIGIT NINE + key("\u0E8A", joinMoreKeys("9", "\u0ED9")), + // U+0ECD: "ໍ" LAO NIGGAHITA + "\u0ECD") + .setKeysOfRow(2, + // U+0EBB: "ົ" LAO VOWEL SIGN MAI KON + "\u0EBB", + // U+0EC4: "ໄ" LAO VOWEL SIGN AI + // U+0ED0: "໐" LAO DIGIT ZERO + key("\u0EC4", joinMoreKeys("0", "\u0ED0")), + // U+0EB3: "ຳ" LAO VOWEL SIGN AM + // U+0E9E: "ພ" LAO LETTER PHO TAM + // U+0EB0: "ະ" LAO VOWEL SIGN A + // U+0EB4: "ິ" LAO VOWEL SIGN I + // U+0EB5: "ີ" LAO VOWEL SIGN II + // U+0EAE: "ຮ" LAO LETTER HO TAM + // U+0E99: "ນ" LAO LETTER NO + // U+0E8D: "ຍ" LAO LETTER NYO + // U+0E9A: "ບ" LAO LETTER BO + // U+0EA5: "ລ" LAO LETTER LO LOOT + "\u0EB3", "\u0E9E", "\u0EB0", "\u0EB4", "\u0EB5", "\u0EAE", "\u0E99", "\u0E8D", + "\u0E9A", "\u0EA5") + .setKeysOfRow(3, + // U+0EB1: "ັ" LAO VOWEL SIGN MAI KAN + // U+0EAB: "ຫ" LAO LETTER HO SUNG + // U+0E81: "ກ" LAO LETTER KO + // U+0E94: "ດ" LAO LETTER DO + // U+0EC0: "ເ" LAO VOWEL SIGN E + // U+0EC9: "້" LAO TONE MAI THO + // U+0EC8: "່" LAO TONE MAI EK + // U+0EB2: "າ" LAO VOWEL SIGN AA + // U+0EAA: "ສ" LAO LETTER SO SUNG + // U+0EA7: "ວ" LAO LETTER WO + // U+0E87: "ງ" LAO LETTER NGO + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + "\u0EB1", "\u0EAB", "\u0E81", "\u0E94", "\u0EC0", "\u0EC9", "\u0EC8", "\u0EB2", + "\u0EAA", "\u0EA7", "\u0E87", "\u201C") + .setKeysOfRow(4, + // U+0E9C: "ຜ" LAO LETTER PHO SUNG + // U+0E9B: "ປ" LAO LETTER PO + // U+0EC1: "ແ" LAO VOWEL SIGN EI + // U+0EAD: "ອ" LAO LETTER O + // U+0EB6: "ຶ" LAO VOWEL SIGN Y + // U+0EB7: "ື" LAO VOWEL SIGN YY + // U+0E97: "ທ" LAO LETTER THO TAM + // U+0EA1: "ມ" LAO LETTER MO + // U+0EC3: "ໃ" LAO VOWEL SIGN AY + // U+0E9D: "ຝ" LAO LETTER FO TAM + "\u0E9C", "\u0E9B", "\u0EC1", "\u0EAD", "\u0EB6", "\u0EB7", "\u0E97", "\u0EA1", + "\u0EC3", "\u0E9D") + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0ED1: "໑" LAO DIGIT ONE + // U+0ED2: "໒" LAO DIGIT TWO + // U+0ED3: "໓" LAO DIGIT THREE + // U+0ED4: "໔" LAO DIGIT FOUR + // U+0ECC: "໌" LAO CANCELLATION MARK + // U+0EBC: "ຼ" LAO SEMIVOWEL SIGN LO + // U+0ED5: "໕" LAO DIGIT FIVE + // U+0ED6: "໖" LAO DIGIT SIX + // U+0ED7: "໗" LAO DIGIT SEVEN + // U+0ED8: "໘" LAO DIGIT EIGHT + // U+0ED9: "໙" LAO DIGIT NINE + // U+0ECD/U+0EC8: "ໍ່" LAO NIGGAHITA/LAO TONE MAI EK + "\u0ED1", "\u0ED2", "\u0ED3", "\u0ED4", "\u0ECC", "\u0EBC", "\u0ED5", "\u0ED6", + "\u0ED7", "\u0ED8", "\u0ED9", "\u0ECD\u0EC8") + .setKeysOfRow(2, + // U+0EBB/U+0EC9: "" LAO VOWEL SIGN MAI KON/LAO TONE MAI THO + // U+0ED0: "໐" LAO DIGIT ZERO + // U+0EB3/U+0EC9: "ຳ້" LAO VOWEL SIGN AM/LAO TONE MAI THO + // U+0EB4/U+0EC9: "ິ້" LAO VOWEL SIGN I/LAO TONE MAI THO + // U+0EB5/U+0EC9: "ີ້" LAO VOWEL SIGN II/LAO TONE MAI THO + // U+0EA3: "ຣ" LAO LETTER LO LING + // U+0EDC: "ໜ" LAO HO NO + // U+0EBD: "ຽ" LAO SEMIVOWEL SIGN NYO + // U+0EAB/U+0EBC: "" LAO LETTER HO SUNG/LAO SEMIVOWEL SIGN LO + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + "\u0EBB\u0EC9", "\u0ED0", "\u0EB3\u0EC9", "_", "+", "\u0EB4\u0EC9", + "\u0EB5\u0EC9", "\u0EA3", "\u0EDC", "\u0EBD", "\u0EAB\u0EBC", "\u201D") + .setKeysOfRow(3, + // U+0EB1/U+0EC9: "ັ້" LAO VOWEL SIGN MAI KAN/LAO TONE MAI THO + // U+0ECA: "໊" LAO TONE MAI TI + // U+0ECB: "໋" LAO TONE MAI CATAWA + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + "\u0EB1\u0EC9", ";", ".", ",", ":", "\u0ECA", "\u0ECB", "!", "?", "%", "=", + "\u201C") + .setKeysOfRow(4, + // U+20AD: "₭" KIP SIGN + // U+0EAF: "ຯ" LAO ELLIPSIS + // U+0EB6/U+0EC9: "ຶ້" LAO VOWEL SIGN Y/LAO TONE MAI THO + // U+0EB7/U+0EC9: "ື້" LAO VOWEL SIGN YY/LAO TONE MAI THO + // U+0EC6: "ໆ" LAO KO LA + // U+0EDD: "ໝ" LAO HO MO + "\u20AD", "(", "\u0EAF", "@", "\u0EB6\u0EC9", "\u0EB7\u0EC9", "\u0EC6", + "\u0EDD", "$", ")") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/LayoutBase.java b/tests/src/org/kelar/inputmethod/keyboard/layout/LayoutBase.java new file mode 100644 index 000000000..620e0a442 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/LayoutBase.java @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.AbstractLayoutBase; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * The base class of keyboard layout. + */ +public abstract class LayoutBase extends AbstractLayoutBase { + private final LayoutCustomizer mCustomizer; + private final Symbols mSymbols; + private final SymbolsShifted mSymbolsShifted; + + LayoutBase(final LayoutCustomizer customizer, final Class<? extends Symbols> symbolsClass, + final Class<? extends SymbolsShifted> symbolsShiftedClass) { + mCustomizer = customizer; + try { + mSymbols = symbolsClass.getDeclaredConstructor(LayoutCustomizer.class) + .newInstance(customizer); + mSymbolsShifted = symbolsShiftedClass.getDeclaredConstructor(LayoutCustomizer.class) + .newInstance(customizer); + } catch (final Exception e) { + throw new RuntimeException("Unknown Symbols/SymbolsShifted class", e); + } + } + + /** + * The layout name. + * @return the name of this layout. + */ + public abstract String getName(); + + /** + * The locale of this layout. + * @return the locale of this layout. + */ + public final Locale getLocale() { return mCustomizer.getLocale(); } + + /** + * The layout customizer for this layout. + * @return the layout customizer; + */ + public final LayoutCustomizer getCustomizer() { return mCustomizer; } + + /** + * Helper method to create alphabet layout adding special function keys. + * @param builder the {@link ExpectedKeyboardBuilder} object that contains common keyboard + * layout + * @param isPhone true if requesting phone's layout. + * @return the {@link ExpectedKeyboardBuilder} object that is customized and have special keys. + */ + ExpectedKeyboardBuilder convertCommonLayoutToKeyboard(final ExpectedKeyboardBuilder builder, + final boolean isPhone) { + final LayoutCustomizer customizer = getCustomizer(); + final int numberOfRows = customizer.getNumberOfRows(); + builder.setKeysOfRow(numberOfRows, (Object[])customizer.getSpaceKeys(isPhone)); + builder.addKeysOnTheLeftOfRow( + numberOfRows, (Object[])customizer.getKeysLeftToSpacebar(isPhone)); + builder.addKeysOnTheRightOfRow( + numberOfRows, (Object[])customizer.getKeysRightToSpacebar(isPhone)); + if (isPhone) { + builder.addKeysOnTheRightOfRow(numberOfRows - 1, DELETE_KEY) + .addKeysOnTheLeftOfRow(numberOfRows, customizer.getSymbolsKey()) + .addKeysOnTheRightOfRow(numberOfRows, customizer.getEnterKey(isPhone)); + } else { + builder.addKeysOnTheRightOfRow(1, DELETE_KEY) + .addKeysOnTheRightOfRow(numberOfRows - 2, customizer.getEnterKey(isPhone)) + .addKeysOnTheLeftOfRow(numberOfRows, customizer.getSymbolsKey()) + .addKeysOnTheRightOfRow(numberOfRows, customizer.getEmojiKey(isPhone)); + } + builder.addKeysOnTheLeftOfRow( + numberOfRows - 1, (Object[])customizer.getLeftShiftKeys(isPhone)); + builder.addKeysOnTheRightOfRow( + numberOfRows - 1, (Object[])customizer.getRightShiftKeys(isPhone)); + return builder; + } + + /** + * Get common alphabet layout. This layout doesn't contain any special keys. + * + * A keyboard layout is an array of rows, and a row consists of an array of + * {@link ExpectedKey}s. Each row may have different number of {@link ExpectedKey}s. + * + * @param isPhone true if requesting phone's layout. + * @return the common alphabet keyboard layout. + */ + abstract ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone); + + /** + * Get common alphabet shifted layout. This layout doesn't contain any special keys. + * + * A keyboard layout is an array of rows, and a row consists of an array of + * {@link ExpectedKey}s. Each row may have different number of {@link ExpectedKey}s. + * + * @param isPhone true if requesting phone's layout. + * @param elementId the element id of the requesting shifted mode. + * @return the common alphabet shifted keyboard layout. + */ + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( + getCommonAlphabetLayout(isPhone)); + getCustomizer().setAccentedLetters(builder, elementId); + builder.toUpperCase(getLocale()); + return builder.build(); + } + + /** + * Get the complete expected keyboard layout. + * + * A keyboard layout is an array of rows, and a row consists of an array of + * {@link ExpectedKey}s. Each row may have different number of {@link ExpectedKey}s. + * + * @param isPhone true if requesting phone's layout. + * @param elementId the element id of the requesting keyboard mode. + * @return the keyboard layout of the <code>elementId</code>. + */ + public ExpectedKey[][] getLayout(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_SYMBOLS) { + return mSymbols.getLayout(isPhone); + } + if (elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) { + return mSymbolsShifted.getLayout(isPhone); + } + final ExpectedKeyboardBuilder builder; + if (elementId == KeyboardId.ELEMENT_ALPHABET) { + builder = new ExpectedKeyboardBuilder(getCommonAlphabetLayout(isPhone)); + getCustomizer().setAccentedLetters(builder, elementId); + } else { + final ExpectedKey[][] commonLayout = getCommonAlphabetShiftLayout(isPhone, elementId); + if (commonLayout == null) { + return null; + } + builder = new ExpectedKeyboardBuilder(commonLayout); + } + convertCommonLayoutToKeyboard(builder, isPhone); + if (elementId != KeyboardId.ELEMENT_ALPHABET) { + builder.replaceKeysOfAll(SHIFT_KEY, SHIFTED_SHIFT_KEY); + } + return builder.build(); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Malayalam.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Malayalam.java new file mode 100644 index 000000000..714955f30 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Malayalam.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Malayalam keyboard. + */ +public final class Malayalam extends LayoutBase { + private static final String LAYOUT_NAME = "malayalam"; + + public Malayalam(final Locale locale) { + super(new MalayalamCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class MalayalamCustomizer extends LayoutCustomizer { + MalayalamCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return MALAYALAM_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + // U+0D05: "അ" MALAYALAM LETTER A + private static final ExpectedKey MALAYALAM_ALPHABET_KEY = key( + "\u0D05", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0D4D: "്" MALAYALAM SIGN VIRAMA + // U+0D05: "അ" MALAYALAM LETTER A + key("\u0D4D", joinMoreKeys("\u0D05", "1")), + // U+0D3E: "ാ" MALAYALAM VOWEL SIGN AA + // U+0D06: "ആ" MALAYALAM LETTER AA + key("\u0D3E", joinMoreKeys("\u0D06", "2")), + // U+0D3F: "ി" MALAYALAM VOWEL SIGN I + // U+0D07: "ഇ" MALAYALAM LETTER I + key("\u0D3F", joinMoreKeys("\u0D07", "3")), + // U+0D40: "ീ" MALAYALAM VOWEL SIGN II + // U+0D08: "ഈ" MALAYALAM LETTER II + key("\u0D40", joinMoreKeys("\u0D08", "4")), + // U+0D41: "ു" MALAYALAM VOWEL SIGN U + // U+0D09: "ഉ" MALAYALAM LETTER U + key("\u0D41", joinMoreKeys("\u0D09", "5")), + // U+0D42: "ൂ" MALAYALAM VOWEL SIGN UU + // U+0D0A: "ഊ" MALAYALAM LETTER UU + key("\u0D42", joinMoreKeys("\u0D0A", "6")), + // U+0D43: "ൃ" MALAYALAM VOWEL SIGN VOCALIC R + // U+0D0B: "ഋ" MALAYALAM LETTER VOCALIC R + key("\u0D43", joinMoreKeys("\u0D0B", "7")), + // U+0D46: "െ" MALAYALAM VOWEL SIGN E + // U+0D0E: "എ" MALAYALAM LETTER E + // U+0D10: "ഐ" MALAYALAM LETTER AI + // U+0D48: "ൈ" MALAYALAM VOWEL SIGN AI + key("\u0D46", joinMoreKeys("\u0D0E", "\u0D10", "\u0D48", "8")), + // U+0D47: "േ" MALAYALAM VOWEL SIGN EE + // U+0D0F: "ഏ" MALAYALAM LETTER EE + key("\u0D47", joinMoreKeys("\u0D0F", "9")), + // U+0D4A: "ൊ" MALAYALAM VOWEL SIGN O + // U+0D12: "ഒ" MALAYALAM LETTER O + key("\u0D4A", joinMoreKeys("\u0D12", "0")), + // U+0D4B: "ോ" MALAYALAM VOWEL SIGN OO + // U+0D13: "ഓ" MALAYALAM LETTER OO + // U+0D14: "ഔ" MALAYALAM LETTER AU + // U+0D57: "ൗ" MALAYALAM AU LENGTH MARK + key("\u0D4B", joinMoreKeys("\u0D13", "\u0D14", "\u0D57"))) + .setKeysOfRow(2, + // U+0D15: "ക" MALAYALAM LETTER KA + // U+0D16: "ഖ" MALAYALAM LETTER KHA + key("\u0D15", moreKey("\u0D16")), + // U+0D17: "ഗ" MALAYALAM LETTER GA + // U+0D18: "ഘ" MALAYALAM LETTER GHA + key("\u0D17", moreKey("\u0D18")), + // U+0D19: "ങ" MALAYALAM LETTER NGA + // U+0D1E: "ഞ" MALAYALAM LETTER NYA + key("\u0D19", moreKey("\u0D1E")), + // U+0D1A: "ച" MALAYALAM LETTER CA + // U+0D1B: "ഛ" MALAYALAM LETTER CHA + key("\u0D1A", moreKey("\u0D1B")), + // U+0D1C: "ജ" MALAYALAM LETTER JA + // U+0D1D: "ഝ" MALAYALAM LETTER JHA + key("\u0D1C", moreKey("\u0D1D")), + // U+0D1F: "ട" MALAYALAM LETTER TTA + // U+0D20: "ഠ" MALAYALAM LETTER TTHA + key("\u0D1F", moreKey("\u0D20")), + // U+0D21: "ഡ" MALAYALAM LETTER DDA + // U+0D22: "ഢ" MALAYALAM LETTER DDHA + key("\u0D21", moreKey("\u0D22")), + // U+0D23: "ണ" MALAYALAM LETTER NNA + // U+0D7A: "ൺ" MALAYALAM LETTER CHILLU NN + key("\u0D23", moreKey("\u0D7A")), + // U+0D24: "ത" MALAYALAM LETTER TA + // U+0D25: "ഥ" MALAYALAM LETTER THA + key("\u0D24", moreKey("\u0D25")), + // U+0D26: "ദ" MALAYALAM LETTER DA + // U+0D27: "ധ" MALAYALAM LETTER DHA + key("\u0D26", moreKey("\u0D27")), + // U+0D28: "ഗന" MALAYALAM LETTER NA + // U+0D7B: "ൻ" MALAYALAM LETTER CHILLU N + key("\u0D28", moreKey("\u0D7B"))) + .setKeysOfRow(3, + // U+0D2A: "പ" MALAYALAM LETTER PA + // U+0D2B: "ഫ" MALAYALAM LETTER PHA + key("\u0D2A", moreKey("\u0D2B")), + // U+0D2C: "ബ" MALAYALAM LETTER BA + // U+0D2D: "ഭ" MALAYALAM LETTER BHA + key("\u0D2C", moreKey("\u0D2D")), + // U+0D2E: "മ" MALAYALAM LETTER MA + // U+0D02: "ം" MALAYALAM SIGN ANUSVARA + key("\u0D2E", moreKey("\u0D02")), + // U+0D2F: "യ" MALAYALAM LETTER YA + // U+0D4D/U+0D2F: "്യ" MALAYALAM SIGN VIRAMA/MALAYALAM LETTER YA + key("\u0D2F", moreKey("\u0D4D\u0D2F")), + // U+0D30: "ര" MALAYALAM LETTER RA + // U+0D4D/U+0D30: "്ര" MALAYALAM SIGN VIRAMA/MALAYALAM LETTER RA + // U+0D7C: "ർ" MALAYALAM LETTER CHILLU RR + // U+0D31: "റ" MALAYALAM LETTER RRA + key("\u0D30", joinMoreKeys("\u0D4D\u0D30", "\u0D7C", "\u0D31")), + // U+0D32: "ല" MALAYALAM LETTER LA + // U+0D7D: "ൽ" MALAYALAM LETTER CHILLU L + key("\u0D32", moreKey("\u0D7D")), + // U+0D35: "വ" MALAYALAM LETTER VA + // U+0D4D/U+0D35: "്വ" MALAYALAM SIGN VIRAMA/MALAYALAM LETTER VA + key("\u0D35", moreKey("\u0D4D\u0D35")), + // U+0D36: "ശ" MALAYALAM LETTER SHA + // U+0D37: "ഷ" MALAYALAM LETTER SSA + // U+0D38: "സ" MALAYALAM LETTER SA + key("\u0D36", joinMoreKeys("\u0D37", "\u0D38")), + // U+0D39: "ഹ" MALAYALAM LETTER HA + // U+0D03: "ഃ" MALAYALAM SIGN VISARGA + key("\u0D39", moreKey("\u0D03")), + // U+0D33: "ള" MALAYALAM LETTER LLA + // U+0D7E: "ൾ" MALAYALAM LETTER CHILLU LL + // U+0D34: "ഴ" MALAYALAM LETTER LLLA + key("\u0D33", joinMoreKeys("\u0D7E", "\u0D34"))) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Marathi.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Marathi.java new file mode 100644 index 000000000..85b2c2501 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Marathi.java @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import static org.kelar.inputmethod.keyboard.layout.DevanagariLetterConstants.*; + +import org.kelar.inputmethod.keyboard.layout.Hindi.HindiSymbols; +import org.kelar.inputmethod.keyboard.layout.customizer.DevanagariCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * The Marathi keyboard. + */ +public final class Marathi extends LayoutBase { + private static final String LAYOUT_NAME = "marathi"; + + public Marathi(final Locale locale) { + super(new MarathiCustomizer(locale), HindiSymbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class MarathiCustomizer extends DevanagariCustomizer { + MarathiCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+094C: "ौ" DEVANAGARI VOWEL SIGN AU + // U+0914: "औ" DEVANAGARI LETTER AU + // U+0967: "१" DEVANAGARI DIGIT ONE + key(VOWEL_SIGN_AU, "\u094C", joinMoreKeys("\u0914", "\u0967", "1")), + // U+0948: "ै" DEVANAGARI VOWEL SIGN AI + // U+0910: "ऐ" DEVANAGARI LETTER AI + // U+0968: "२" DEVANAGARI DIGIT TWO + key(VOWEL_SIGN_AI, "\u0948", joinMoreKeys("\u0910", "\u0968", "2")), + // U+093E: "ा" DEVANAGARI VOWEL SIGN AA + // U+0906: "आ" DEVANAGARI LETTER AA + // U+0969: "३" DEVANAGARI DIGIT THREE + key(VOWEL_SIGN_AA, "\u093E", joinMoreKeys("\u0906", "\u0969", "3")), + // U+0940: "ी" DEVANAGARI VOWEL SIGN II + // U+0908: "ई" DEVANAGARI LETTER II + // U+096A: "४" DEVANAGARI DIGIT FOUR + key(VOWEL_SIGN_II, "\u0940", joinMoreKeys("\u0908", "\u096A", "4")), + // U+0942: "ू" DEVANAGARI VOWEL SIGN UU + // U+090A: "ऊ" DEVANAGARI LETTER UU + // U+096B: "५" DEVANAGARI DIGIT FIVE + key(VOWEL_SIGN_UU, "\u0942", joinMoreKeys("\u090A", "\u096B", "5")), + // U+092C: "ब" DEVANAGARI LETTER BA + // U+092D: "भ" DEVANAGARI LETTER BHA + // U+096C: "६" DEVANAGARI DIGIT SIX + key("\u092C", joinMoreKeys("\u092D", "\u096C", "6")), + // U+0939: "ह" DEVANAGARI LETTER HA + // U+096D: "७" DEVANAGARI DIGIT SEVEN + key("\u0939", joinMoreKeys("\u096D", "7")), + // U+0917: "ग" DEVANAGARI LETTER GA + // U+0918: "घ" DEVANAGARI LETTER GHA + // U+096E: "८" DEVANAGARI DIGIT EIGHT + key("\u0917", joinMoreKeys("\u0918", "\u096E", "8")), + // U+0926: "द" DEVANAGARI LETTER DA + // U+0927: "ध" DEVANAGARI LETTER DHA + // U+096F: "९" DEVANAGARI DIGIT NINE + key("\u0926", joinMoreKeys("\u0927", "\u096F", "9")), + // U+091C: "ज" DEVANAGARI LETTER JA + // U+091D: "झ" DEVANAGARI LETTER JHA + // U+091C/U+094D/U+091E: + // "ज्ञ" DEVANAGARI LETTER JA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER NYA + // U+0966: "०" DEVANAGARI DIGIT ZERO + key("\u091C", joinMoreKeys("\u091D", "\u091C\u094D\u091E", "\u0966", "0")), + // U+0921: "ड" DEVANAGARI LETTER DDA + // U+0922: "ढ" DEVANAGARI LETTER DDHA + key("\u0921", moreKey("\u0922"))) + .setKeysOfRow(2, + // U+094B: "ो" DEVANAGARI VOWEL SIGN O + // U+0913: "ओ" DEVANAGARI LETTER O + key(VOWEL_SIGN_O, "\u094B", moreKey("\u0913")), + // U+0947: "े" DEVANAGARI VOWEL SIGN E + // U+090F: "ए" DEVANAGARI LETTER SHORT E + key(VOWEL_SIGN_E, "\u0947", moreKey("\u090F")), + // U+094D: "्" DEVANAGARI SIGN VIRAMA + // U+0905: "अ" DEVANAGARI LETTER A + key(SIGN_VIRAMA, "\u094D", moreKey("\u0905")), + // U+093F: "ि" DEVANAGARI VOWEL SIGN I + // U+0907: "इ" DEVANAGARI LETTER I + key(VOWEL_SIGN_I, "\u093F", moreKey("\u0907")), + // U+0941: "ु" DEVANAGARI VOWEL SIGN U + // U+0909: "उ" DEVANAGARI LETTER U + key(VOWEL_SIGN_U, "\u0941", moreKey("\u0909")), + // U+092A: "प" DEVANAGARI LETTER PA + // U+092B: "फ" DEVANAGARI LETTER PHA + key("\u092A", moreKey("\u092B")), + // U+0930: "र" DEVANAGARI LETTER RA + // U+0931: "ऱ" DEVANAGARI LETTER RRA + // U+090B: "ऋ" DEVANAGARI LETTER VOCALIC R + // U+0943: "ृ" DEVANAGARI VOWEL SIGN VOCALIC R + key("\u0930", joinMoreKeys( + "\u0931", "\u090B", moreKey(VOWEL_SIGN_VOCALIC_R, "\u0943"))), + // U+0915: "क" DEVANAGARI LETTER KA + // U+0916: "ख" DEVANAGARI LETTER KHA + key("\u0915", moreKey("\u0916")), + // U+0924: "त" DEVANAGARI LETTER TA + // U+0925: "थ" DEVANAGARI LETTER THA + // U+0924/U+094D/U+0930: + // "त्र" DEVANAGARI LETTER TA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + key("\u0924", joinMoreKeys("\u0925", "\u0924\u094D\u0930")), + // U+091A: "च" DEVANAGARI LETTER CA + // U+091B: "छ" DEVANAGARI LETTER CHA + key("\u091A", moreKey("\u091B")), + // U+091F: "ट" DEVANAGARI LETTER TTA + // U+0920: "ठ" DEVANAGARI LETTER TTHA + key("\u091F", moreKey("\u0920"))) + .setKeysOfRow(3, + // U+0949: "ॉ" DEVANAGARI VOWEL SIGN CANDRA O + // U+0911: "ऑ" DEVANAGARI LETTER CANDRA O + key(VOWEL_SIGN_CANDRA_O, "\u0949", moreKey("\u0911")), + // U+0945: "ॅ" DEVANAGARI VOWEL SIGN CANDRA E + // U+090D: "ऍ" DEVANAGARI LETTER CANDRA E + key(VOWEL_SIGN_CANDRA_E, "\u0945", moreKey("\u090D")), + // U+0902: "ं" DEVANAGARI SIGN ANUSVARA + // U+0903: "ः" DEVANAGARI SIGN VISARGA + // U+0901: "ँ" DEVANAGARI SIGN CANDRABINDU + key(SIGN_ANUSVARA, "\u0902", joinMoreKeys( + moreKey(SIGN_VISARGA, "\u0903"), moreKey(SIGN_CANDRABINDU, "\u0901"))), + // U+092E: "म" DEVANAGARI LETTER MA + "\u092E", + // U+0928: "न" DEVANAGARI LETTER NA + // U+0923: "ण" DEVANAGARI LETTER NNA + // U+091E: "ञ" DEVANAGARI LETTER NYA + // U+0919: "ङ" DEVANAGARI LETTER NGA + key("\u0928", joinMoreKeys("\u0923", "\u091E", "\u0919")), + // U+0935: "व" DEVANAGARI LETTER VA + "\u0935", + // U+0932: "ल" DEVANAGARI LETTER LA + // U+0933: "ळ" DEVANAGARI LETTER LLA + key("\u0932", moreKey("\u0933")), + // U+0938: "स" DEVANAGARI LETTER SA + // U+0936: "श" DEVANAGARI LETTER SHA + // U+0937: "ष" DEVANAGARI LETTER SSA + // U+0936/U+094D/U+0930: + // "श्र" DEVANAGARI LETTER SHA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + key("\u0938", joinMoreKeys("\u0936", "\u0937", "\u0936\u094D\u0930")), + // U+092F: "य" DEVANAGARI LETTER YA + "\u092F", + // U+0915/U+094D/U+0937: + // "क्ष" DEVANAGARI LETTER KA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER SSA + "\u0915\u094D\u0937") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Mongolian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Mongolian.java new file mode 100644 index 000000000..e616cc931 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Mongolian.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public final class Mongolian extends LayoutBase { + private static final String LAYOUT_NAME = "mongolian"; + + public Mongolian(final Locale locale) { + super(new MongolianCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class MongolianCustomizer extends EastSlavicCustomizer { + MongolianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_TUGRIK; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + // U+20AE: "₮" TUGRIK SIGN + private static final ExpectedKey CURRENCY_TUGRIK = key("\u20AE", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0444: "ф" CYRILLIC SMALL LETTER EF + key("\u0444", moreKey("1")), + // U+0446: "ц" CYRILLIC SMALL LETTER TSE + key("\u0446", moreKey("2")), + // U+0443: "у" CYRILLIC SMALL LETTER U + key("\u0443", moreKey("3")), + // U+0436: "ж" CYRILLIC SMALL LETTER ZHE + key("\u0436", moreKey("4")), + // U+044D: "э" CYRILLIC SMALL LETTER E + key("\u044D", moreKey("5")), + // U+043D: "н" CYRILLIC SMALL LETTER EN + key("\u043D", moreKey("6")), + // U+0433: "г" CYRILLIC SMALL LETTER GHE + key("\u0433", moreKey("7")), + // U+0448: "ш" CYRILLIC SMALL LETTER SHA + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + key("\u0448", joinMoreKeys("8", "\u0449")), + // U+04AF: "ү" CYRILLIC SMALL LETTER STRAIGHT U + key("\u04AF", moreKey("9")), + // U+0437: "з" CYRILLIC SMALL LETTER ZE + key("\u0437", moreKey("0")), + // U+043A: "к" CYRILLIC SMALL LETTER KA + "\u043A") + .setKeysOfRow(2, + // U+0439: "й" CYRILLIC SMALL LETTER SHORT I + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + // U+0431: "б" CYRILLIC SMALL LETTER BE + // U+04E9: "ө" CYRILLIC SMALL LETTER BARRED O + // U+0430: "а" CYRILLIC SMALL LETTER A + // U+0445: "х" CYRILLIC SMALL LETTER HA + // U+0440: "р" CYRILLIC SMALL LETTER ER + // U+043E: "о" CYRILLIC SMALL LETTER O + // U+043B: "л" CYRILLIC SMALL LETTER EL + // U+0434: "д" CYRILLIC SMALL LETTER DE + // U+043F: "п" CYRILLIC SMALL LETTER PE + "\u0439", "\u044B", "\u0431", "\u04E9", "\u0430", "\u0445", "\u0440", "\u043E", + "\u043B", "\u0434", "\u043F") + .setKeysOfRow(3, + // U+044F: "я" CYRILLIC SMALL LETTER YA + // U+0447: "ч" CYRILLIC SMALL LETTER CHE + "\u044F", "\u0447", + // U+0451: "ё" CYRILLIC SMALL LETTER IO + // U+0435: "е" CYRILLIC SMALL LETTER IE + key("\u0451", moreKey("\u0435")), + // U+0441: "с" CYRILLIC SMALL LETTER ES + // U+043C: "м" CYRILLIC SMALL LETTER EM + // U+0438: "и" CYRILLIC SMALL LETTER I + // U+0442: "т" CYRILLIC SMALL LETTER TE + "\u0441", "\u043C", "\u0438", "\u0442", + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + key("\u044C", moreKey("\u044A")), + // U+0432: "в" CYRILLIC SMALL LETTER VE + // U+044E: "ю" CYRILLIC SMALL LETTER YU + key("\u0432", moreKey("\u044E"))) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/NepaliRomanized.java b/tests/src/org/kelar/inputmethod/keyboard/layout/NepaliRomanized.java new file mode 100644 index 000000000..ed4719a24 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/NepaliRomanized.java @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import static org.kelar.inputmethod.keyboard.layout.DevanagariLetterConstants.*; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.Hindi.HindiSymbols; +import org.kelar.inputmethod.keyboard.layout.customizer.NepaliCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * The nepali_romanized layout + */ +public final class NepaliRomanized extends LayoutBase { + private static final String LAYOUT_NAME = "nepali_romanized"; + + public NepaliRomanized(final Locale locale) { + super(new NepaliCustomizer(locale), HindiSymbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+091F: "ट" DEVANAGARI LETTER TTA + // U+0967: "१" DEVANAGARI DIGIT ONE + // U+093C: "़" DEVANAGARI SIGN NUKTA + key("\u091F", joinMoreKeys("\u0967", "1", key(SIGN_NUKTA, "\u093C"))), + // U+094C: "ौ" DEVANAGARI VOWEL SIGN AU + // U+0968: "२" DEVANAGARI DIGIT TWO + key(VOWEL_SIGN_AU, "\u094C", joinMoreKeys("\u0968", "2")), + // U+0947: "े" DEVANAGARI VOWEL SIGN E + // U+0969: "३" DEVANAGARI DIGIT THREE + key(VOWEL_SIGN_E, "\u0947", joinMoreKeys("\u0969", "3")), + // U+0930: "र" DEVANAGARI LETTER RA + // U+096A: "४" DEVANAGARI DIGIT FOUR + key("\u0930", joinMoreKeys("\u096A", "4")), + // U+0924: "त" DEVANAGARI LETTER TA + // U+096B: "५" DEVANAGARI DIGIT FIVE + key("\u0924", joinMoreKeys("\u096B", "5")), + // U+092F: "य" DEVANAGARI LETTER YA + // U+096C: "६" DEVANAGARI DIGIT SIX + key("\u092F", joinMoreKeys("\u096C", "6")), + // U+0941: "ु" DEVANAGARI VOWEL SIGN U + // U+096D: "७" DEVANAGARI DIGIT SEVEN + key(VOWEL_SIGN_U, "\u0941", joinMoreKeys("\u096D", "7")), + // U+093F: "ि" DEVANAGARI VOWEL SIGN I + // U+096E: "८" DEVANAGARI DIGIT EIGHT + key(VOWEL_SIGN_I, "\u093F", joinMoreKeys("\u096E", "8")), + // U+094B: "ो" DEVANAGARI VOWEL SIGN O + // U+096F: "९" DEVANAGARI DIGIT NINE + key(VOWEL_SIGN_O, "\u094B", joinMoreKeys("\u096F", "9")), + // U+092A: "प" DEVANAGARI LETTER PA + // U+0966: "०" DEVANAGARI DIGIT ZERO + key("\u092A", joinMoreKeys("\u0966", "0")), + // U+0907: "इ" DEVANAGARI LETTER I + "\u0907") + .setKeysOfRow(2, + // U+093E: "ा" DEVANAGARI VOWEL SIGN AA + key(VOWEL_SIGN_AA, "\u093E"), + // U+0938: "स" DEVANAGARI LETTER SA + // U+0926: "द" DEVANAGARI LETTER DA + // U+0909: "उ" DEVANAGARI LETTER U + // U+0917: "ग" DEVANAGARI LETTER GA + // U+0939: "ह" DEVANAGARI LETTER HA + // U+091C: "ज" DEVANAGARI LETTER JA + // U+0915: "क" DEVANAGARI LETTER KA + // U+0932: "ल" DEVANAGARI LETTER LA + // U+090F: "ए" DEVANAGARI LETTER E + // U+0950: "ॐ" DEVANAGARI OM + "\u0938", "\u0926", "\u0909", "\u0917", "\u0939", "\u091C", "\u0915", "\u0932", + "\u090F", "\u0950") + .setKeysOfRow(3, + // U+0937: "ष" DEVANAGARI LETTER SSA + // U+0921: "ड" DEVANAGARI LETTER DDA + // U+091A: "च" DEVANAGARI LETTER CA + // U+0935: "व" DEVANAGARI LETTER VA + // U+092C: "ब" DEVANAGARI LETTER BHA + // U+0928: "न" DEVANAGARI LETTER NA + // U+092E: "म" DEVANAGARI LETTER MA + "\u0937", "\u0921", "\u091A", "\u0935", "\u092C", "\u0928", "\u092E", + // U+094D: "्" DEVANAGARI SIGN VIRAMA + // U+093D: "ऽ" DEVANAGARI SIGN AVAGRAHA + key(SIGN_VIRAMA, "\u094D", moreKey("\u093D"))) + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0920: "ठ" DEVANAGARI LETTER TTHA + // U+0914: "औ" DEVANAGARI LETTER AU + "\u0920", "\u0914", + // U+0948: "ै" DEVANAGARI VOWEL SIGN AI + key(VOWEL_SIGN_AI, "\u0948"), + // U+0943: "ृ" DEVANAGARI VOWEL SIGN VOCALIC R + key(VOWEL_SIGN_VOCALIC_R, "\u0943"), + // U+0925: "थ" DEVANAGARI LETTER THA + // U+091E: "ञ" DEVANAGARI LETTER NYA + "\u0925", "\u091E", + // U+0942: "ू" DEVANAGARI VOWEL SIGN UU + key(VOWEL_SIGN_UU, "\u0942"), + // U+0940: "ी" DEVANAGARI VOWEL SIGN II + key(VOWEL_SIGN_II, "\u0940"), + // U+0913: "ओ" DEVANAGARI LETTER O + // U+092B: "फ" DEVANAGARI LETTER PHA + // U+0908: "ई" DEVANAGARI LETTER II + "\u0913", "\u092B", "\u0908") + .setKeysOfRow(2, + // U+0906: "आ" DEVANAGARI LETTER AA + // U+0936: "श" DEVANAGARI LETTER SHA + // U+0927: "ध" DEVANAGARI LETTER DHA + // U+090A: "ऊ" DEVANAGARI LETTER UU + // U+0918: "घ" DEVANAGARI LETTER GHA + // U+0905: "अ" DEVANAGARI LETTER A + // U+091D: "झ" DEVANAGARI LETTER JHA + // U+0916: "ख" DEVANAGARI LETTER KHA + // U+0965: "॥" DEVANAGARI DOUBLE DANDA + // U+0910: "ऐ" DEVANAGARI LETTER AI + // U+0903: "ः" DEVANAGARI SIGN VISARGA + "\u0906", "\u0936", "\u0927", "\u090A", "\u0918", "\u0905", "\u091D", "\u0916", + "\u0965", "\u0910", key(SIGN_VISARGA, "\u0903")) + .setKeysOfRow(3, + // U+090B: "ऋ" DEVANAGARI LETTER VOCALIC R + // U+0922: "ढ" DEVANAGARI LETTER DDHA + // U+091B: "छ" DEVANAGARI LETTER CHA + "\u090B", "\u0922", "\u091B", + // U+0901: "ँ" DEVANAGARI SIGN CANDRABINDU + key(SIGN_CANDRABINDU, "\u0901"), + // U+092D: "भ" DEVANAGARI LETTER BHA + // U+0923: "ण" DEVANAGARI LETTER NNA + "\u092D", "\u0923", + // U+0902: "ं" DEVANAGARI SIGN ANUSVARA + key(SIGN_ANUSVARA, "\u0902"), + // U+0919: "ङ" DEVANAGARI LETTER NGA + "\u0919") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/NepaliTraditional.java b/tests/src/org/kelar/inputmethod/keyboard/layout/NepaliTraditional.java new file mode 100644 index 000000000..c6282460e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/NepaliTraditional.java @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import static org.kelar.inputmethod.keyboard.layout.DevanagariLetterConstants.*; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.Hindi.HindiSymbols; +import org.kelar.inputmethod.keyboard.layout.customizer.NepaliCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * The nepali_traditional keyboard. + */ +public final class NepaliTraditional extends LayoutBase { + private static final String LAYOUT_NAME = "nepali_traditional"; + + public NepaliTraditional(final Locale locale) { + super(new NepaliTraditionalCustomizer(locale), HindiSymbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class NepaliTraditionalCustomizer extends NepaliCustomizer { + NepaliTraditionalCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+091F: "ट" DEVANAGARI LETTER TTA + // U+0967: "१" DEVANAGARI DIGIT ONE + key("\u091F", joinMoreKeys("\u0967", "1")), + // U+0927: "ध" DEVANAGARI LETTER DHA + // U+0968: "२" DEVANAGARI DIGIT TWO + key("\u0927", joinMoreKeys("\u0968", "2")), + // U+092D: "भ" DEVANAGARI LETTER BHA + // U+0969: "३" DEVANAGARI DIGIT THREE + key("\u092D", joinMoreKeys("\u0969", "3")), + // U+091A: "च" DEVANAGARI LETTER CA + // U+096A: "४" DEVANAGARI DIGIT FOUR + key("\u091A", joinMoreKeys("\u096A", "4")), + // U+0924: "त" DEVANAGARI LETTER TA + // U+096B: "५" DEVANAGARI DIGIT FIVE + key("\u0924", joinMoreKeys("\u096B", "5")), + // U+0925: "थ" DEVANAGARI LETTER THA + // U+096C: "६" DEVANAGARI DIGIT SIX + key("\u0925", joinMoreKeys("\u096C", "6")), + // U+0917: "ग" DEVANAGARI LETTER G + // U+096D: "७" DEVANAGARI DIGIT SEVEN + key("\u0917", joinMoreKeys("\u096D", "7")), + // U+0937: "ष" DEVANAGARI LETTER SSA + // U+096E: "८" DEVANAGARI DIGIT EIGHT + key("\u0937", joinMoreKeys("\u096E", "8")), + // U+092F: "य" DEVANAGARI LETTER YA + // U+096F: "९" DEVANAGARI DIGIT NINE + key("\u092F", joinMoreKeys("\u096F", "9")), + // U+0909: "उ" DEVANAGARI LETTER U + // U+0966: "०" DEVANAGARI DIGIT ZERO + key("\u0909", joinMoreKeys("\u0966", "0")), + // U+0907: "इ" DEVANAGARI LETTER I + // U+0914: "औ" DEVANAGARI LETTER AU + key("\u0907", moreKey("\u0914"))) + .setKeysOfRow(2, + // U+092C: "ब" DEVANAGARI LETTER BA + // U+0915: "क" DEVANAGARI LETTER KA + // U+092E: "म" DEVANAGARI LETTER MA + "\u092C", "\u0915", "\u092E", + // U+093E: "ा" DEVANAGARI VOWEL SIGN AA + key(VOWEL_SIGN_AA, "\u093E"), + // U+0928: "न" DEVANAGARI LETTER NA + // U+091C: "ज" DEVANAGARI LETTER JA + // U+0935: "व" DEVANAGARI LETTER VA + // U+092A: "प" DEVANAGARI LETTER PA + "\u0928", "\u091C", "\u0935", "\u092A", + // U+093F: "ि" DEVANAGARI VOWEL SIGN I + key(VOWEL_SIGN_I, "\u093F"), + // U+0938: "स" DEVANAGARI LETTER SA + "\u0938", + // U+0941: "ु" DEVANAGARI VOWEL SIGN U + key(VOWEL_SIGN_U, "\u0941")) + .setKeysOfRow(3, + // U+0936: "श" DEVANAGARI LETTER SHA + // U+0939: "ह" DEVANAGARI LETTER HA + // U+0905: "अ" DEVANAGARI LETTER A + // U+0916: "ख" DEVANAGARI LETTER KHA + // U+0926: "द" DEVANAGARI LETTER DA + // U+0932: "ल" DEVANAGARI LETTER LA + "\u0936", "\u0939", "\u0905", "\u0916", "\u0926", "\u0932", + // U+0947: "े" DEVANAGARI VOWEL SIGN E + // U+0903: "ः" DEVANAGARI SIGN VISARGA + // U+093D: "ऽ" DEVANAGARI SIGN AVAGRAHA + key(VOWEL_SIGN_E, "\u0947", joinMoreKeys( + moreKey(SIGN_VISARGA, "\u0903"), "\u093D")), + // U+094D: "्" DEVANAGARI SIGN VIRAMA + key(SIGN_VIRAMA, "\u094D"), + // U+0930: "र" DEVANAGARI LETTER RA + // U+0930/U+0941: "रु" DEVANAGARI LETTER RA/DEVANAGARI VOWEL SIGN U + key("\u0930", moreKey("\u0930\u0941"))) + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0924/U+094D/U+0924: + // "त्त" DEVANAGARI LETTER TA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER TA + // U+091E: "ञ" DEVANAGARI LETTER NYA + // U+091C/U+094D/U+091E: "ज्ञ" DEVANAGARI LETTER JA/DEVANAGARI SIGN + // VIRAMA/DEVANAGARI LETTER NYA + // U+0965: "॥" DEVANAGARI DOUBLE DANDA + key("\u0924\u094D\u0924", + joinMoreKeys("\u091E", "\u091C\u094D\u091E", "\u0965")), + // U+0921/U+094D/U+0922: + // "ड्ढ" DEVANAGARI LETTER DDA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER DDHA + // U+0908: "ई" DEVANAGARI LETTER II + key("\u0921\u094D\u0922", moreKey("\u0908")), + // U+0910: "ऐ" DEVANAGARI LETTER AI + // U+0918: "घ" DEVANAGARI LETTER GHA + key("\u0910", moreKey("\u0918")), + // U+0926/U+094D/U+0935: + // "द्व" DEVANAGARI LETTER DA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER VA + // U+0926/U+094D/U+0927: + // "द्ध" DEVANAGARI LETTER DA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER DHA + key("\u0926\u094D\u0935", moreKey("\u0926\u094D\u0927")), + // U+091F/U+094D/U+091F: + // "ट्ट" DEVANAGARI LETTER TTA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER TTA + // U+091B: "छ" DEVANAGARI LETTER CHA + key("\u091F\u094D\u091F", moreKey("\u091B")), + // U+0920/U+094D/U+0920: + // "ठ्ठ" DEVANAGARI LETTER TTHA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER TTHA + // U+091F: "ट" DEVANAGARI LETTER TTA + key("\u0920\u094D\u0920", moreKey("\u091F")), + // U+090A: "ऊ" DEVANAGARI LETTER UU + // U+0920: "ठ" DEVANAGARI LETTER TTHA + key("\u090A", moreKey("\u0920")), + // U+0915/U+094D/U+0937: + // "क्ष" DEVANAGARI LETTER KA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER SSA + // U+0921: "ड" DEVANAGARI LETTER DDA + key("\u0915\u094D\u0937", moreKey("\u0921")), + // U+0907: "इ" DEVANAGARI LETTER I + // U+0922: "ढ" DEVANAGARI LETTER DDHA + key("\u0907", moreKey("\u0922")), + // U+090F: "ए" DEVANAGARI LETTER E + // U+0923: "ण" DEVANAGARI LETTER NNA + key("\u090F", moreKey("\u0923")), + // U+0943: "ृ" DEVANAGARI VOWEL SIGN VOCALIC R + // U+0913: "ओ" DEVANAGARI LETTER O + key(VOWEL_SIGN_VOCALIC_R, "\u0943", moreKey("\u0913"))) + .setKeysOfRow(2, + // U+0906: "आ" DEVANAGARI LETTER AA + // U+0919/U+094D: "ङ्" DEVANAGARI LETTER NGA/DEVANAGARI SIGN VIRAMA + // U+0921/U+094D/U+0921: + // "ड्ड" DEVANAGARI LETTER DDA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER DDA + "\u0906", "\u0919\u094D", "\u0921\u094D\u0921", + // U+0901: "ँ" DEVANAGARI SIGN CANDRABINDU + key(SIGN_CANDRABINDU, "\u0901"), + // U+0926/U+094D/U+0926: + // "द्द" DEVANAGARI LETTER DA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER DA + // U+091D: "झ" DEVANAGARI LETTER JHA + "\u0926\u094D\u0926", "\u091D", + // U+094B: "ो" DEVANAGARI VOWEL SIGN O + key(VOWEL_SIGN_O, "\u094B"), + // U+092B: "फ" DEVANAGARI LETTER PHA + "\u092B", + // U+0940: "ी" DEVANAGARI VOWEL SIGN II + key(VOWEL_SIGN_II, "\u0940"), + // U+091F/U+094D/U+0920: + // "ट्ठ" DEVANAGARI LETTER TTA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER TTHA + "\u091F\u094D\u0920", + // U+0942: "ू" DEVANAGARI VOWEL SIGN UU + key(VOWEL_SIGN_UU, "\u0942")) + .setKeysOfRow(3, + // U+0915/U+094D: "क्" DEVANAGARI LETTER KA/DEVANAGARI SIGN VIRAMA + // U+0939/U+094D/U+092E: + // "ह्म" DEVANAGARI LETTER HA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER MA + // U+090B: "ऋ" DEVANAGARI LETTER VOCALIC R + // U+0950: "ॐ" DEVANAGARI OM + "\u0915\u094D", "\u0939\u094D\u092E", "\u090B", "\u0950", + // U+094C: "ौ" DEVANAGARI VOWEL SIGN AU + key(VOWEL_SIGN_AU, "\u094C"), + // U+0926/U+094D/U+092F: + // "द्य" DEVANAGARI LETTER DA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER YA + "\u0926\u094D\u092F", + // U+0902: "ं" DEVANAGARI SIGN ANUSVARA + key(SIGN_ANUSVARA, "\u0902"), + // U+0919: "ङ" DEVANAGARI LETTER NGA + "\u0919", + // U+0948: "ै" DEVANAGARI VOWEL SIGN AI + // U+0936/U+094D/U+0930: + // "श्र" DEVANAGARI LETTER SHA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + key(VOWEL_SIGN_AI, "\u0948", moreKey("\u0936\u094D\u0930"))) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Nordic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Nordic.java new file mode 100644 index 000000000..303c55bee --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Nordic.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Nordic alphabet keyboard. + */ +public final class Nordic extends LayoutBase { + private static final String LAYOUT_NAME = "nordic"; + + public Nordic(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW1_11 = "ROW1_11"; + public static final String ROW2_10 = "ROW2_10"; + public static final String ROW2_11 = "ROW2_11"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("y", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0")), + ROW1_11) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW2_10, ROW2_11) + .setKeysOfRow(3, "z", "x", "c", "v", "b", "n", "m") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/PcQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/PcQwerty.java new file mode 100644 index 000000000..1fdd28e16 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/PcQwerty.java @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The PC QWERTY alphabet keyboard. + */ +public final class PcQwerty extends LayoutBase { + private static final String LAYOUT_NAME = "pcqwerty"; + + public PcQwerty(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + final LayoutCustomizer customizer = getCustomizer(); + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + customizer.setAccentedLetters(builder); + builder.replaceKeyOfLabel(ROW1_1, key("`", moreKey("~"))) + .replaceKeyOfLabel(ROW2_11, key("[", moreKey("{"))) + .replaceKeyOfLabel(ROW2_12, key("]", moreKey("}"))) + .replaceKeyOfLabel(ROW2_13, key("\\", moreKey("|"))) + .replaceKeyOfLabel(ROW3_10, key(";", moreKey(":"))) + .replaceKeyOfLabel(ROW3_11, key("'", joinMoreKeys(additionalMoreKey("\""), + customizer.getDoubleQuoteMoreKeys(), + customizer.getSingleQuoteMoreKeys()))) + .setAdditionalMoreKeysPositionOf("'", 4) + .replaceKeyOfLabel(ROW4_8, key(",", moreKey("<"))) + .replaceKeyOfLabel(ROW4_9, key(".", moreKey(">"))) + // U+00BF: "¿" INVERTED QUESTION MARK + .replaceKeyOfLabel(ROW4_10, key("/", joinMoreKeys("?", "\u00BF"))); + if (isPhone) { + // U+221E: "∞" INFINITY + // U+2260: "≠" NOT EQUAL TO + // U+2248: "≈" ALMOST EQUAL TO + builder.replaceKeyOfLabel(ROW1_13, key("=", + joinMoreKeys("\u221E", "\u2260", "\u2248", "+"))); + } else { + // U+221E: "∞" INFINITY + // U+2260: "≠" NOT EQUAL TO + // U+2248: "≈" ALMOST EQUAL TO + builder.replaceKeyOfLabel(ROW1_13, key("=", + joinMoreKeys("+", "\u221E", "\u2260", "\u2248"))); + } + return builder.build(); + } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { + final ExpectedKeyboardBuilder builder; + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED + || elementId == KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED) { + builder = new ExpectedKeyboardBuilder(getCommonAlphabetLayout(isPhone)); + } else { + builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + final LayoutCustomizer customizer = getCustomizer(); + customizer.setAccentedLetters(builder); + builder.setKeysOfRow(1, + "~", + // U+00A1: "¡" INVERTED EXCLAMATION MARK + key("!", moreKey("\u00A1")), + "@", "#", + customizer.getCurrencyKey(), + // U+2030: "‰" PER MILLE SIGN + key("%", moreKey("\u2030")), + "^", "&", + // U+2020: "†" DAGGER + // U+2021: "‡" DOUBLE DAGGER + // U+2605: "★" BLACK STAR + key("*", joinMoreKeys("\u2020", "\u2021", "\u2605")), + "(", ")", "_", + // U+00B1: "±" PLUS-MINUS SIGN + // U+00D7: "×" MULTIPLICATION SIGN + // U+00F7: "÷" DIVISION SIGN + // U+221A: "√" SQUARE ROOT + key("+", joinMoreKeys("\u00B1", "\u00D7", "\u00F7", "\u221A"))) + .replaceKeyOfLabel(ROW2_11, key("{")) + .replaceKeyOfLabel(ROW2_12, key("}")) + .replaceKeyOfLabel(ROW2_13, key("|")) + .replaceKeyOfLabel(ROW3_10, key(":")) + .replaceKeyOfLabel(ROW3_11, key("\"", joinMoreKeys( + customizer.getDoubleQuoteMoreKeys(), + customizer.getSingleQuoteMoreKeys()))) + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+2264: "≤" LESS-THAN OR EQUAL TO + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + .replaceKeyOfLabel(ROW4_8, key("<", joinMoreKeys("\u2039", "\u2264", "\u00AB"))) + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // U+2265: "≥" GREATER-THAN EQUAL TO + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + .replaceKeyOfLabel(ROW4_9, key(">", joinMoreKeys("\u203A", "\u2265", "\u00BB"))) + // U+00BF: "¿" INVERTED QUESTION MARK + .replaceKeyOfLabel(ROW4_10, key("?", moreKey("\u00BF"))); + } + builder.toUpperCase(getLocale()); + return builder.build(); + } + + // Helper method to create alphabet layout by adding special function keys. + @Override + ExpectedKeyboardBuilder convertCommonLayoutToKeyboard(final ExpectedKeyboardBuilder builder, + final boolean isPhone) { + final LayoutCustomizer customizer = getCustomizer(); + builder.setKeysOfRow(5, (Object[])customizer.getSpaceKeys(isPhone)); + builder.addKeysOnTheLeftOfRow(5, (Object[])customizer.getKeysLeftToSpacebar(isPhone)); + builder.addKeysOnTheRightOfRow(5, (Object[])customizer.getKeysRightToSpacebar(isPhone)); + if (isPhone) { + builder.addKeysOnTheRightOfRow(3, DELETE_KEY); + } else { + builder.addKeysOnTheRightOfRow(1, DELETE_KEY) + .addKeysOnTheLeftOfRow(2, TAB_KEY) + .addKeysOnTheRightOfRow(3, ENTER_KEY); + } + builder.addKeysOnTheLeftOfRow(4, (Object[])customizer.getLeftShiftKeys(isPhone)) + .addKeysOnTheRightOfRow(4, (Object[])customizer.getRightShiftKeys(isPhone)); + return builder; + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_SYMBOLS + || elementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED) { + return null; + } + return super.getLayout(isPhone, elementId); + } + + private static final String ROW1_1 = "ROW1_1"; + private static final String ROW1_13 = "ROW1_13"; + private static final String ROW2_11 = "ROW2_11"; + private static final String ROW2_12 = "ROW2_12"; + private static final String ROW2_13 = "ROW2_13"; + private static final String ROW3_10 = "ROW3_10"; + private static final String ROW3_11 = "ROW3_11"; + private static final String ROW4_8 = "ROW4_8"; + private static final String ROW4_9 = "ROW4_9"; + private static final String ROW4_10 = "ROW4_10"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + ROW1_1, + // U+00A1: "¡" INVERTED EXCLAMATION MARK + // U+00B9: "¹" SUPERSCRIPT ONE + // U+00BD: "½" VULGAR FRACTION ONE HALF + // U+2153: "⅓" VULGAR FRACTION ONE THIRD + // U+00BC: "¼" VULGAR FRACTION ONE QUARTER + // U+215B: "⅛" VULGAR FRACTION ONE EIGHTH + key("1", joinMoreKeys( + "!", "\u00A1", "\u00B9", "\u00BD", "\u2153", "\u00BC", "\u215B")), + // U+00B2: "²" SUPERSCRIPT TWO + // U+2154: "⅔" VULGAR FRACTION TWO THIRDS + key("2", joinMoreKeys("@", "\u00B2", "\u2154")), + // U+00B3: "³" SUPERSCRIPT THREE + // U+00BE: "¾" VULGAR FRACTION THREE QUARTERS + // U+215C: "⅜" VULGAR FRACTION THREE EIGHTHS + key("3", joinMoreKeys("#", "\u00B3", "\u00BE", "\u215C")), + // U+2074: "⁴" SUPERSCRIPT FOUR + key("4", joinMoreKeys("$", "\u2074")), + // U+215D: "⅝" VULGAR FRACTION FIVE EIGHTHS + key("5", joinMoreKeys("%", "\u215D")), + key("6", moreKey("^")), + // U+215E: "⅞" VULGAR FRACTION SEVEN EIGHTHS + key("7", joinMoreKeys("&", "\u215E")), + key("8", moreKey("*")), + key("9", moreKey("(")), + // U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N + // U+2205: "∅" EMPTY SET + key("0", joinMoreKeys(")", "\u207F", "\u2205")), + // U+2013: "–" EN DASH + // U+2014: "—" EM DASH + // U+00B7: "·" MIDDLE DOT + key("-", joinMoreKeys("_", "\u2013", "\u2014", "\u00B7")), + ROW1_13) + .setKeysOfRow(2, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", + ROW2_11, ROW2_12, ROW2_13) + .setKeysOfRow(3, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW3_10, ROW3_11) + .setKeysOfRow(4, "z", "x", "c", "v", "b", "n", "m", ROW4_8, ROW4_9, ROW4_10) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Qwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Qwerty.java new file mode 100644 index 000000000..fc535e032 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Qwerty.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The QWERTY alphabet keyboard. + */ +public final class Qwerty extends LayoutBase { + private static final String LAYOUT_NAME = "qwerty"; + + public Qwerty(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("y", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0"))) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l") + .setKeysOfRow(3, "z", "x", "c", "v", "b", "n", "m") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Qwertz.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Qwertz.java new file mode 100644 index 000000000..74f3d0c77 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Qwertz.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +public final class Qwertz extends LayoutBase { + private static final String LAYOUT_NAME = "qwertz"; + + public Qwertz(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("z", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0"))) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l") + .setKeysOfRow(3, "y", "x", "c", "v", "b", "n", "m") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/SerbianQwertz.java b/tests/src/org/kelar/inputmethod/keyboard/layout/SerbianQwertz.java new file mode 100644 index 000000000..f2a00fc81 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/SerbianQwertz.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +public final class SerbianQwertz extends LayoutBase { + private static final String LAYOUT_NAME = "serbian_qwertz"; + + public SerbianQwertz(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW1_11 = "ROW1_11"; + public static final String ROW2_10 = "ROW2_10"; + public static final String ROW2_11 = "ROW2_11"; + public static final String ROW3_8 = "ROW3_8"; + public static final String ROW3_9 = "ROW3_9"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("z", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0")), + ROW1_11) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW2_10, ROW2_11) + .setKeysOfRow(3, "y", "x", "c", "v", "b", "n", "m", ROW3_8, ROW3_9) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Sinhala.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Sinhala.java new file mode 100644 index 000000000..433c0ea93 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Sinhala.java @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Sinhala keyboard. + */ +public final class Sinhala extends LayoutBase { + private static final String LAYOUT_NAME = "sinhala"; + + public Sinhala(final Locale locale) { + super(new SinhalaCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class SinhalaCustomizer extends LayoutCustomizer { + SinhalaCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return SINHALA_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + // U+0D85: "අ" SINHALA LETTER AYANNA + // U+0D86: "ආ" SINHALA LETTER AAYANNA + private static final ExpectedKey SINHALA_ALPHABET_KEY = key( + "\u0D85,\u0D86", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+0DBB/U+0DD4: "රු" SINHALA LETTER RAYANNA/SINHALA VOWEL SIGN KETTI PAA-PILLA + private static final ExpectedKey CURRENCY_RUPEE = key("\u0DBB\u0DD4", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return ALPHABET_COMMON; + } + return ALPHABET_SHIFTED_COMMON; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0DD4: "ු" SINHALA VOWEL SIGN KETTI PAA-PILLA + key("\u0DD4", moreKey("1")), + // U+0D85: "අ" SINHALA LETTER AYANNA + key("\u0D85", moreKey("2")), + // U+0DD0: "ැ" SINHALA VOWEL SIGN KETTI AEDA-PILLA + key("\u0DD0", moreKey("3")), + // U+0DBB: "ර" SINHALA LETTER RAYANNA + key("\u0DBB", moreKey("4")), + // U+0D91: "එ" SINHALA LETTER EYANNA + key("\u0D91", moreKey("5")), + // U+0DC4: "හ" SINHALA LETTER HAYANNA + key("\u0DC4", moreKey("6")), + // U+0DB8: "ම" SINHALA LETTER MAYANNA + key("\u0DB8", moreKey("7")), + // U+0DC3: "ස" SINHALA LETTER DANTAJA SAYANNA + key("\u0DC3", moreKey("8")), + // U+0DAF: "ද" SINHALA LETTER ALPAPRAANA DAYANNA + // U+0DB3: "ඳ" SINHALA LETTER SANYAKA DAYANNA + key("\u0DAF", joinMoreKeys("9", "\u0DB3")), + // U+0DA0: "ච" SINHALA LETTER ALPAPRAANA CAYANNA + key("\u0DA0", moreKey("0")), + // U+0DA4: "ඤ" SINHALA LETTER TAALUJA NAASIKYAYA + // U+0DF4: "෴" SINHALA PUNCTUATION KUNDDALIYA + key("\u0DA4", moreKey("\u0DF4"))) + .setKeysOfRow(2, + // U+0DCA: "්" SINHALA SIGN AL-LAKUNA + // U+0DD2: "ි" SINHALA VOWEL SIGN KETTI IS-PILLA + // U+0DCF: "ා" SINHALA VOWEL SIGN AELA-PILLA + // U+0DD9: "ෙ" SINHALA VOWEL SIGN KOMBUVA + // U+0DA7: "ට" SINHALA LETTER ALPAPRAANA TTAYANNA + // U+0DBA: "ය" SINHALA LETTER YAYANNA + // U+0DC0: "ව" SINHALA LETTER VAYANNA + // U+0DB1: "න" SINHALA LETTER DANTAJA NAYANNA + // U+0D9A: "ක" SINHALA LETTER ALPAPRAANA KAYANNA + // U+0DAD: "ත" SINHALA LETTER ALPAPRAANA TAYANNA + // U+0D8F: "ඏ" SINHALA LETTER ILUYANNA + "\u0DCA", "\u0DD2", "\u0DCF", "\u0DD9", "\u0DA7", "\u0DBA", "\u0DC0", "\u0DB1", + "\u0D9A", "\u0DAD", "\u0D8F") + .setKeysOfRow(3, + // U+0D82: "ං" SINHALA SIGN ANUSVARAYA + // U+0D83: "ඃ" SINHALA SIGN VISARGAYA + key("\u0D82", moreKey("\u0D83")), + // U+0DA2: "ජ" SINHALA LETTER ALPAPRAANA JAYANNA + // U+0DA6: "ඦ" SINHALA LETTER SANYAKA JAYANNA + key("\u0DA2", moreKey("\u0DA6")), + // U+0DA9: "ඩ" SINHALA LETTER ALPAPRAANA DDAYANNA + // U+0DAC: "ඬ" SINHALA LETTER SANYAKA DDAYANNA + key("\u0DA9", moreKey("\u0DAC")), + // U+0D89: "ඉ" SINHALA LETTER IYANNA + // U+0DB6: "බ" SINHALA LETTER ALPAPRAANA BAYANNA + // U+0DB4: "ප" SINHALA LETTER ALPAPRAANA PAYANNA + // U+0DBD: "ල" SINHALA LETTER DANTAJA LAYANNA + "\u0D89", "\u0DB6", "\u0DB4", "\u0DBD", + // U+0D9C: "ග" SINHALA LETTER ALPAPRAANA GAYANNA + // U+0D9F: "ඟ" SINHALA LETTER SANYAKA GAYANNA + key("\u0D9C", moreKey("\u0D9F")), + // U+0DF3: "ෳ" SINHALA VOWEL SIGN DIGA GAYANUKITTA + "\u0DF3") + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0DD6: "ූ" SINHALA VOWEL SIGN DIGA PAA-PILLA + // U+0D8B: "උ" SINHALA LETTER UYANNA + // U+0DD1: "ෑ" SINHALA VOWEL SIGN DIGA AEDA-PILLA + // U+0D8D: "ඍ" SINHALA LETTER IRUYANNA + // U+0D94: "ඔ" SINHALA LETTER OYANNA + // U+0DC1: "ශ" SINHALA LETTER TAALUJA SAYANNA + // U+0DB9: "ඹ" SINHALA LETTER AMBA BAYANNA + // U+0DC2: "ෂ" SINHALA LETTER MUURDHAJA SAYANNA + // U+0DB0: "ධ" SINHALA LETTER MAHAAPRAANA DAYANNA + // U+0DA1: "ඡ" SINHALA LETTER MAHAAPRAANA CAYANNA + "\u0DD6", "\u0D8B", "\u0DD1", "\u0D8D", "\u0D94", "\u0DC1", "\u0DB9", "\u0DC2", + "\u0DB0", "\u0DA1", + // U+0DA5: "ඥ" SINHALA LETTER TAALUJA SANYOOGA NAAKSIKYAYA + // U+0DF4: "෴" SINHALA PUNCTUATION KUNDDALIYA + key("\u0DA5", moreKey("\u0DF4"))) + .setKeysOfRow(2, + // U+0DDF: "ෟ" SINHALA VOWEL SIGN GAYANUKITTA + // U+0DD3: "ී" SINHALA VOWEL SIGN DIGA IS-PILLA + // U+0DD8: "ෘ" SINHALA VOWEL SIGN GAETTA-PILLA + // U+0DC6: "ෆ" SINHALA LETTER FAYANNA + // U+0DA8: "ඨ" SINHALA LETTER MAHAAPRAANA TTAYANNA + // U+0DCA/U+200D/U+0DBA: + // "්ය" SINHALA SIGN AL-LAKUNA/ZERO WIDTH JOINER/SINHALA LETTER YAYANNA + // U+0DC5/U+0DD4: + // "ළු" SINHALA LETTER MUURDHAJA LAYANNA/SINHALA VOWEL SIGN KETTI PAA-PILLA + // U+0DAB: "ණ" SINHALA LETTER MUURDHAJA NAYANNA + // U+0D9B: "ඛ" SINHALA LETTER MAHAAPRAANA KAYANNA + // U+0DAE: "ථ" SINHALA LETTER MAHAAPRAANA TAYANNA + // U+0DCA/U+200D/U+0DBB: + // "්ර" SINHALA SIGN AL-LAKUNA/ZERO WIDTH JOINER/SINHALA LETTER RAYANNA + "\u0DDF", "\u0DD3", "\u0DD8", "\u0DC6", "\u0DA8", "\u0DCA\u200D\u0DBA", + "\u0DC5\u0DD4", "\u0DAB", "\u0D9B", "\u0DAE", "\u0DCA\u200D\u0DBB") + .setKeysOfRow(3, + // U+0D9E: "ඞ" SINHALA LETTER KANTAJA NAASIKYAYA + // U+0DA3: "ඣ" SINHALA LETTER MAHAAPRAANA JAYANNA + // U+0DAA: "ඪ" SINHALA LETTER MAHAAPRAANA DDAYANNA + // U+0D8A: "ඊ" SINHALA LETTER IIYANNA + // U+0DB7: "භ" SINHALA LETTER MAHAAPRAANA BAYANNA + // U+0DB5: "ඵ" SINHALA LETTER MAHAAPRAANA PAYANNA + // U+0DC5: "ළ" SINHALA LETTER MUURDHAJA LAYANNA + // U+0D9D: "ඝ" SINHALA LETTER MAHAAPRAANA GAYANNA + // U+0DBB/U+0DCA/U+200D: + // "ර්" SINHALA LETTER RAYANNA/SINHALA SIGN AL-LAKUNA/ZERO WIDTH JOINER + "\u0d9E", "\u0DA3", "\u0DAA", "\u0D8A", "\u0DB7", "\u0DB5", "\u0DC5", "\u0D9D", + "\u0DBB\u0DCA\u200D") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/SouthSlavic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/SouthSlavic.java new file mode 100644 index 000000000..503af359c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/SouthSlavic.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +public final class SouthSlavic extends LayoutBase { + private static final String LAYOUT_NAME = "south_slavic"; + + public SouthSlavic(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW1_6 = "ROW1_6"; + public static final String ROW2_11 = "ROW2_11"; + public static final String ROW3_1 = "ROW3_1"; + public static final String ROW3_8 = "ROW3_8"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0459: "љ" CYRILLIC SMALL LETTER LJE + key("\u0459", additionalMoreKey("1")), + // U+045A: "њ" CYRILLIC SMALL LETTER NJE + key("\u045A", additionalMoreKey("2")), + // U+0435: "е" CYRILLIC SMALL LETTER IE + key("\u0435", additionalMoreKey("3")), + // U+0440: "р" CYRILLIC SMALL LETTER ER + key("\u0440", additionalMoreKey("4")), + // U+0442: "т" CYRILLIC SMALL LETTER TE + key("\u0442", additionalMoreKey("5")), + key(ROW1_6, additionalMoreKey("6")), + // U+0443: "у" CYRILLIC SMALL LETTER U + key("\u0443", additionalMoreKey("7")), + // U+0438: "и" CYRILLIC SMALL LETTER I + key("\u0438", additionalMoreKey("8")), + // U+043E: "о" CYRILLIC SMALL LETTER O + key("\u043E", additionalMoreKey("9")), + // U+043F: "п" CYRILLIC SMALL LETTER PE + key("\u043F", additionalMoreKey("0")), + // U+0448: "ш" CYRILLIC SMALL LETTER SHA + "\u0448") + .setKeysOfRow(2, + // U+0430: "а" CYRILLIC SMALL LETTER A + // U+0441: "с" CYRILLIC SMALL LETTER ES + // U+0434: "д" CYRILLIC SMALL LETTER DE + // U+0444: "ф" CYRILLIC SMALL LETTER EF + // U+0433: "г" CYRILLIC SMALL LETTER GHE + // U+0445: "х" CYRILLIC SMALL LETTER HA + // U+0458: "ј" CYRILLIC SMALL LETTER JE + // U+043A: "к" CYRILLIC SMALL LETTER KA + // U+043B: "л" CYRILLIC SMALL LETTER EL + // U+0447: "ч" CYRILLIC SMALL LETTER CHE + "\u0430", "\u0441", "\u0434", "\u0444", "\u0433", "\u0445", "\u0458", "\u043A", + "\u043B", "\u0447", ROW2_11) + .setKeysOfRow(3, + // U+045F: "џ" CYRILLIC SMALL LETTER DZHE + // U+0446: "ц" CYRILLIC SMALL LETTER TSE + // U+0432: "в" CYRILLIC SMALL LETTER VE + // U+0431: "б" CYRILLIC SMALL LETTER BE + // U+043D: "н" CYRILLIC SMALL LETTER EN + // U+043C: "м" CYRILLIC SMALL LETTER EM + // U+0436: "ж" CYRILLIC SMALL LETTER ZHE + ROW3_1, "\u045F", "\u0446", "\u0432", "\u0431", "\u043D", "\u043C", ROW3_8, + "\u0436") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Spanish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Spanish.java new file mode 100644 index 000000000..a5ac6bd71 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Spanish.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +public final class Spanish extends LayoutBase { + private static final String LAYOUT_NAME = "spanish"; + + public Spanish(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW2_10 = "ROW2_10"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("y", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0"))) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW2_10) + .setKeysOfRow(3, "z", "x", "c", "v", "b", "n", "m") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Swiss.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Swiss.java new file mode 100644 index 000000000..6ab08d0b3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Swiss.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +public final class Swiss extends LayoutBase { + private static final String LAYOUT_NAME = "swiss"; + + public Swiss(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW1_11 = "ROW1_11"; + public static final String ROW2_10 = "ROW2_10"; + public static final String ROW2_11 = "ROW2_11"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("z", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0")), + ROW1_11) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW2_10, ROW2_11) + .setKeysOfRow(3, "y", "x", "c", "v", "b", "n", "m") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Symbols.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Symbols.java new file mode 100644 index 000000000..e9d934283 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Symbols.java @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.AbstractLayoutBase; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The symbols keyboard layout. + */ +public class Symbols extends AbstractLayoutBase { + private final LayoutCustomizer mCustomizer; + + public Symbols(final LayoutCustomizer customizer) { + mCustomizer = customizer; + } + + public ExpectedKey[][] getLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(SYMBOLS_COMMON); + final LayoutCustomizer customizer = mCustomizer; + builder.replaceKeyOfLabel(CURRENCY, customizer.getCurrencyKey()); + builder.replaceKeyOfLabel(DOUBLE_QUOTE, key("\"", joinMoreKeys( + customizer.getDoubleQuoteMoreKeys(), customizer.getDoubleAngleQuoteKeys()))); + builder.replaceKeyOfLabel(SINGLE_QUOTE, key("'", joinMoreKeys( + customizer.getSingleQuoteMoreKeys(), customizer.getSingleAngleQuoteKeys()))); + if (isPhone) { + builder.addKeysOnTheLeftOfRow(3, customizer.getSymbolsShiftKey(isPhone)) + .addKeysOnTheRightOfRow(3, DELETE_KEY) + .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey()) + .addKeysOnTheRightOfRow(4, customizer.getEnterKey(isPhone)); + } else { + // Tablet symbols keyboard has extra two keys at the left edge of the 3rd row. + builder.addKeysOnTheLeftOfRow(3, (Object[])joinKeys("\\", "=")); + builder.addKeysOnTheRightOfRow(1, DELETE_KEY) + .addKeysOnTheRightOfRow(2, customizer.getEnterKey(isPhone)) + .addKeysOnTheLeftOfRow(3, customizer.getSymbolsShiftKey(isPhone)) + .addKeysOnTheRightOfRow(3, customizer.getSymbolsShiftKey(isPhone)) + .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey()) + .addKeysOnTheRightOfRow(4, customizer.getEmojiKey(isPhone)); + } + return builder.build(); + } + + // Variations of the "currency" key on the 2nd row. + public static final String CURRENCY = "CURRENCY"; + // U+00A2: "¢" CENT SIGN + // U+00A3: "£" POUND SIGN + // U+00A5: "¥" YEN SIGN + // U+20AC: "€" EURO SIGN + // U+20B1: "₱" PESO SIGN + public static final ExpectedKey DOLLAR_SIGN = key("$"); + public static final ExpectedKey CENT_SIGN = key("\u00A2"); + public static final ExpectedKey POUND_SIGN = key("\u00A3"); + public static final ExpectedKey YEN_SIGN = key("\u00A5"); + public static final ExpectedKey EURO_SIGN = key("\u20AC"); + public static final ExpectedKey PESO_SIGN = key("\u20B1"); + public static final ExpectedKey CURRENCY_DOLLAR = key("$", + CENT_SIGN, POUND_SIGN, EURO_SIGN, YEN_SIGN, PESO_SIGN); + public static final ExpectedKey CURRENCY_EURO = key("\u20AC", + CENT_SIGN, POUND_SIGN, DOLLAR_SIGN, YEN_SIGN, PESO_SIGN); + public static final ExpectedKey[] CURRENCY_GENERIC_MORE_KEYS = joinMoreKeys( + Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN, Symbols.EURO_SIGN, Symbols.POUND_SIGN, + Symbols.YEN_SIGN, Symbols.PESO_SIGN); + + // Variations of the "double quote" key's "more keys" on the 3rd row. + public static final String DOUBLE_QUOTE = "DOUBLE_QUOTE"; + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK + private static final ExpectedKey DQUOTE_LEFT = key("\u201C"); + private static final ExpectedKey DQUOTE_RIGHT = key("\u201D"); + private static final ExpectedKey DQUOTE_LOW9 = key("\u201E"); + public static ExpectedKey[] DOUBLE_QUOTES_9LR = { DQUOTE_LOW9, DQUOTE_LEFT, DQUOTE_RIGHT }; + public static ExpectedKey[] DOUBLE_QUOTES_R9L = { DQUOTE_RIGHT, DQUOTE_LOW9, DQUOTE_LEFT }; + public static ExpectedKey[] DOUBLE_QUOTES_L9R = { DQUOTE_LEFT, DQUOTE_LOW9, DQUOTE_RIGHT }; + public static ExpectedKey[] DOUBLE_QUOTES_LR9 = { DQUOTE_LEFT, DQUOTE_RIGHT, DQUOTE_LOW9 }; + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + private static final ExpectedKey DAQUOTE_LEFT = key("\u00AB"); + private static final ExpectedKey DAQUOTE_RIGHT = key("\u00BB"); + public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_LR = { DAQUOTE_LEFT, DAQUOTE_RIGHT }; + public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_RL = { DAQUOTE_RIGHT, DAQUOTE_LEFT }; + + // Variations of the "single quote" key's "more keys" on the 3rd row. + public static final String SINGLE_QUOTE = "SINGLE_QUOTE"; + // U+2018: "‘" LEFT SINGLE QUOTATION MARK + // U+2019: "’" RIGHT SINGLE QUOTATION MARK + // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK + private static final ExpectedKey SQUOTE_LEFT = key("\u2018"); + private static final ExpectedKey SQUOTE_RIGHT = key("\u2019"); + private static final ExpectedKey SQUOTE_LOW9 = key("\u201A"); + public static ExpectedKey[] SINGLE_QUOTES_9LR = { SQUOTE_LOW9, SQUOTE_LEFT, SQUOTE_RIGHT }; + public static ExpectedKey[] SINGLE_QUOTES_R9L = { SQUOTE_RIGHT, SQUOTE_LOW9, SQUOTE_LEFT }; + public static ExpectedKey[] SINGLE_QUOTES_L9R = { SQUOTE_LEFT, SQUOTE_LOW9, SQUOTE_RIGHT }; + public static ExpectedKey[] SINGLE_QUOTES_LR9 = { SQUOTE_LEFT, SQUOTE_RIGHT, SQUOTE_LOW9 }; + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + private static final ExpectedKey SAQUOTE_LEFT = key("\u2039"); + private static final ExpectedKey SAQUOTE_RIGHT = key("\u203A"); + public static ExpectedKey[] SINGLE_ANGLE_QUOTES_LR = { SAQUOTE_LEFT, SAQUOTE_RIGHT }; + public static ExpectedKey[] SINGLE_ANGLE_QUOTES_RL = { SAQUOTE_RIGHT, SAQUOTE_LEFT }; + + // Common symbols keyboard layout. + private static final ExpectedKey[][] SYMBOLS_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+00B9: "¹" SUPERSCRIPT ONE + // U+00BD: "½" VULGAR FRACTION ONE HALF + // U+2153: "⅓" VULGAR FRACTION ONE THIRD + // U+00BC: "¼" VULGAR FRACTION ONE QUARTER + // U+215B: "⅛" VULGAR FRACTION ONE EIGHTH + key("1", joinMoreKeys("\u00B9", "\u00BD", "\u2153", "\u00BC", "\u215B")), + // U+00B2: "²" SUPERSCRIPT TWO + // U+2154: "⅔" VULGAR FRACTION TWO THIRDS + key("2", joinMoreKeys("\u00B2", "\u2154")), + // U+00B3: "³" SUPERSCRIPT THREE + // U+00BE: "¾" VULGAR FRACTION THREE QUARTERS + // U+215C: "⅜" VULGAR FRACTION THREE EIGHTHS + key("3", joinMoreKeys("\u00B3", "\u00BE", "\u215C")), + // U+2074: "⁴" SUPERSCRIPT FOUR + key("4", moreKey("\u2074")), + // U+215D: "⅝" VULGAR FRACTION FIVE EIGHTHS + key("5", moreKey("\u215D")), + "6", + // U+215E: "⅞" VULGAR FRACTION SEVEN EIGHTHS + key("7", moreKey("\u215E")), + "8", "9", + // U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N + // U+2205: "∅" EMPTY SET + key("0", joinMoreKeys("\u207F", "\u2205"))) + .setKeysOfRow(2, + key("@"), key("#"), key(CURRENCY), + // U+2030: "‰" PER MILLE SIGN + key("%", moreKey("\u2030")), + "&", + // U+2013: "–" EN DASH + // U+2014: "—" EM DASH + // U+00B7: "·" MIDDLE DOT + key("-", joinMoreKeys("_", "\u2013", "\u2014", "\u00B7")), + // U+00B1: "±" PLUS-MINUS SIGN + key("+", moreKey("\u00B1")), + key("(", joinMoreKeys("<", "{", "[")), + key(")", joinMoreKeys(">", "}", "]"))) + .setKeysOfRow(3, + // U+2020: "†" DAGGER + // U+2021: "‡" DOUBLE DAGGER + // U+2605: "★" BLACK STAR + key("*", joinMoreKeys("\u2020", "\u2021", "\u2605")), + key(DOUBLE_QUOTE), key(SINGLE_QUOTE), key(":"), key(";"), + // U+00A1: "¡" INVERTED EXCLAMATION MARK + key("!", moreKey("\u00A1")), + // U+00BF: "¿" INVERTED QUESTION MARK + key("?", moreKey("\u00BF"))) + .setKeysOfRow(4, + key(","), key("_"), SPACE_KEY, key("/"), + // U+2026: "…" HORIZONTAL ELLIPSIS + key(".", moreKey("\u2026"))) + .build(); + + public static class RtlSymbols extends Symbols { + public RtlSymbols(final LayoutCustomizer customizer) { + super(customizer); + } + + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + private static final ExpectedKey DAQUOTE_LEFT_RTL = key("\u00AB", "\u00BB"); + private static final ExpectedKey DAQUOTE_RIGHT_RTL = key("\u00BB", "\u00AB"); + public static ExpectedKey[] DOUBLE_ANGLE_QUOTES_LR_RTL = { + DAQUOTE_LEFT_RTL, DAQUOTE_RIGHT_RTL + }; + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + private static final ExpectedKey SAQUOTE_LEFT_RTL = key("\u2039", "\u203A"); + private static final ExpectedKey SAQUOTE_RIGHT_RTL = key("\u203A", "\u2039"); + public static ExpectedKey[] SINGLE_ANGLE_QUOTES_LR_RTL = { + SAQUOTE_LEFT_RTL, SAQUOTE_RIGHT_RTL + }; + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + .replaceKeyOfLabel("(", key("(", ")", + moreKey("<", ">"), moreKey("{", "}"), moreKey("[", "]"))) + .replaceKeyOfLabel(")", key(")", "(", + moreKey(">", "<"), moreKey("}", "{"), moreKey("]", "["))) + .build(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/SymbolsShifted.java b/tests/src/org/kelar/inputmethod/keyboard/layout/SymbolsShifted.java new file mode 100644 index 000000000..f106ffb7f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/SymbolsShifted.java @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.keyboard.layout.expected.AbstractLayoutBase; + +/** + * The symbols shifted keyboard layout. + */ +public class SymbolsShifted extends AbstractLayoutBase { + private final LayoutCustomizer mCustomizer; + + public SymbolsShifted(final LayoutCustomizer customizer) { + mCustomizer = customizer; + } + + public ExpectedKey[][] getLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(SYMBOLS_SHIFTED_COMMON); + final LayoutCustomizer customizer = mCustomizer; + builder.replaceKeyOfLabel(OTHER_CURRENCIES, (Object[])customizer.getOtherCurrencyKeys()); + if (isPhone) { + builder.addKeysOnTheLeftOfRow(3, customizer.getBackToSymbolsKey()) + .addKeysOnTheRightOfRow(3, DELETE_KEY) + .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey()) + .addKeysOnTheRightOfRow(4, customizer.getEnterKey(isPhone)); + } else { + // Tablet symbols shifted keyboard has extra two keys at the right edge of the 3rd row. + // U+00BF: "¿" INVERTED QUESTION MARK + // U+00A1: "¡" INVERTED EXCLAMATION MARK + builder.addKeysOnTheRightOfRow(3, (Object[])joinKeys("\u00A1", "\u00BF")); + builder.addKeysOnTheRightOfRow(1, DELETE_KEY) + .addKeysOnTheRightOfRow(2, customizer.getEnterKey(isPhone)) + .addKeysOnTheLeftOfRow(3, customizer.getBackToSymbolsKey()) + .addKeysOnTheRightOfRow(3, customizer.getBackToSymbolsKey()) + .addKeysOnTheLeftOfRow(4, customizer.getAlphabetKey()) + .addKeysOnTheRightOfRow(4, customizer.getEmojiKey(isPhone)); + } + return builder.build(); + } + + // Variations of the "other currencies" keys on the 2rd row. + public static final String OTHER_CURRENCIES = "OTHER_CURRENCY"; + public static final ExpectedKey[] CURRENCIES_OTHER_THAN_DOLLAR = { + Symbols.POUND_SIGN, Symbols.CENT_SIGN, Symbols.EURO_SIGN, Symbols.YEN_SIGN + }; + public static final ExpectedKey[] CURRENCIES_OTHER_THAN_EURO = { + Symbols.POUND_SIGN, Symbols.YEN_SIGN, key(Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN), + Symbols.CENT_SIGN + }; + public static final ExpectedKey[] CURRENCIES_OTHER_GENERIC = { + Symbols.POUND_SIGN, Symbols.EURO_SIGN, key(Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN), + Symbols.CENT_SIGN + }; + + // Common symbols shifted keyboard layout. + private static final ExpectedKey[][] SYMBOLS_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0060: "`" GRAVE ACCENT + "~", "\u0060", "|", + // U+2022: "•" BULLET + // U+266A: "♪" EIGHTH NOTE + // U+2665: "♥" BLACK HEART SUIT + // U+2660: "♠" BLACK SPADE SUIT + // U+2666: "♦" BLACK DIAMOND SUIT + // U+2663: "♣" BLACK CLUB SUIT + key("\u2022", joinMoreKeys("\u266A", "\u2665", "\u2660", "\u2666", "\u2663")), + // U+221A: "√" SQUARE ROOT + "\u221A", + // U+03C0: "π" GREEK SMALL LETTER PI + // U+03A0: "Π" GREEK CAPITAL LETTER PI + key("\u03C0", moreKey("\u03A0")), + // U+00F7: "÷" DIVISION SIGN + // U+00D7: "×" MULTIPLICATION SIGN + "\u00F7", "\u00D7", + // U+00B6: "¶" PILCROW SIGN + // U+00A7: "§" SECTION SIGN + key("\u00B6", moreKey("\u00A7")), + // U+2206: "∆" INCREMENT + "\u2206") + .setKeysOfRow(2, + OTHER_CURRENCIES, + // U+2191: "↑" UPWARDS ARROW + // U+2193: "↓" DOWNWARDS ARROW + // U+2190: "←" LEFTWARDS ARROW + // U+2192: "→" RIGHTWARDS ARROW + key("^", joinMoreKeys("\u2191", "\u2193", "\u2190", "\u2192")), + // U+00B0: "°" DEGREE SIGN + // U+2032: "′" PRIME + // U+2033: "″" DOUBLE PRIME + key("\u00B0", joinMoreKeys("\u2032", "\u2033")), + // U+2260: "≠" NOT EQUAL TO + // U+2248: "≈" ALMOST EQUAL TO + // U+221E: "∞" INFINITY + key("=", joinMoreKeys("\u2260", "\u2248", "\u221E")), + "{", "}") + .setKeysOfRow(3, + // U+00A9: "©" COPYRIGHT SIGN + // U+00AE: "®" REGISTERED SIGN + // U+2122: "™" TRADE MARK SIGN + // U+2105: "℅" CARE OF + "\\", "\u00A9", "\u00AE", "\u2122", "\u2105", "[", "]") + .setKeysOfRow(4, + ",", + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+2264: "≤" LESS-THAN OR EQUAL TO + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + key("<", joinMoreKeys("\u2039", "\u2264", "\u00AB")), + SPACE_KEY, + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // U+2265: "≥" GREATER-THAN EQUAL TO + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + key(">", joinMoreKeys("\u203A", "\u2265", "\u00BB")), + // U+2026: "…" HORIZONTAL ELLIPSIS + key(".", moreKey("\u2026"))) + .build(); + + public static class RtlSymbolsShifted extends SymbolsShifted { + public RtlSymbolsShifted(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + public ExpectedKey[][] getLayout(final boolean isPhone) { + return new ExpectedKeyboardBuilder(super.getLayout(isPhone)) + .replaceKeyOfLabel("{", key("{", "}")) + .replaceKeyOfLabel("}", key("}", "{")) + .replaceKeyOfLabel("[", key("[", "]")) + .replaceKeyOfLabel("]", key("]", "[")) + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+2264: "≤" LESS-THAN OR EQUAL TO + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + .replaceKeyOfLabel("<", key("<", ">", + moreKey("\u2039", "\u203A"), moreKey("\u2264", "\u2265"), + moreKey("\u00AB", "\u00BB"))) + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // U+2265: "≥" GREATER-THAN EQUAL TO + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + .replaceKeyOfLabel(">", key(">", "<", + moreKey("\u203A", "\u2039"), moreKey("\u2265", "\u2264"), + moreKey("\u00BB", "\u00AB"))) + .build(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Tamil.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Tamil.java new file mode 100644 index 000000000..db6bbde1a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Tamil.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Tamil keyboard. + */ +public final class Tamil extends LayoutBase { + private static final String LAYOUT_NAME = "tamil"; + + public Tamil(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0B94: "ஔ" TAMIL LETTER AU + // U+0BCC: "ௌ" TAMIL VOWEL SIGN AU + key("\u0B94", joinMoreKeys("\u0BCC", "1")), + // U+0B90: "ஐ" TAMIL LETTER AI + // U+0BC8: "ை" TAMIL VOWEL SIGN AI + key("\u0B90", joinMoreKeys("\u0BC8", "2")), + // U+0B86: "ஆ" TAMIL LETTER AA + // U+0BBE: "ா" TAMIL VOWEL SIGN AA + key("\u0B86", joinMoreKeys("\u0BBE", "3")), + // U+0B88: "ஈ" TAMIL LETTER II + // U+0BC0: "ீ" TAMIL VOWEL SIGN II + key("\u0B88", joinMoreKeys("\u0BC0", "4")), + // U+0B8A: "ஊ" TAMIL LETTER UU + // U+0BC2: "ூ" TAMIL VOWEL SIGN UU + key("\u0B8A", joinMoreKeys("\u0BC2","5")), + // U+0BAE: "ம" TAMIL LETTER MA + key("\u0BAE", moreKey("6")), + // U+0BA9: "ன" TAMIL LETTER NNNA + key("\u0BA9", moreKey("7")), + // U+0BA8: "ந" TAMIL LETTER NA + key("\u0BA8", moreKey("8")), + // U+0B99: "ங" TAMIL LETTER NGA + key("\u0B99", moreKey("9")), + // U+0BA3: "ண" TAMIL LETTER NNA + key("\u0BA3", moreKey("0")), + // U+0B9E: "ஞ" TAMIL LETTER NYA + "\u0B9E") + .setKeysOfRow(2, + // U+0B93: "ஓ" TAMIL LETTER OO + // U+0BCB: "ோ" TAMIL VOWEL SIGN OO + // U+0BD0: "ௐ" TAMIL OM + key("\u0B93", joinMoreKeys("\u0BCB", "\u0BD0")), + // U+0B8F: "ஏ" TAMIL LETTER EE + // U+0BC7: "ே" TAMIL VOWEL SIGN EE + key("\u0B8F", moreKey("\u0BC7")), + // U+0B85: "அ" TAMIL LETTER A + // U+0B83: "ஃ" TAMIL SIGN VISARGA + key("\u0B85", moreKey("\u0B83")), + // U+0B87: "இ" TAMIL LETTER I + // U+0BBF: "ி" TAMIL VOWEL SIGN I + key("\u0B87", moreKey("\u0BBF")), + // U+0B89: "உ" TAMIL LETTER U + // U+0BC1: "ு" TAMIL VOWEL SIGN U + key("\u0B89", moreKey("\u0BC1")), + // U+0BB1: "ற" TAMIL LETTER RRA + // U+0BAA: "ப" TAMIL LETTER PA + "\u0BB1", "\u0BAA", + // U+0B95: "க" TAMIL LETTER KA + // U+0BB9: "ஹ" TAMIL LETTER HA + // U+0B95/U+0BCD/U+0BB7: + // "க்ஷ" TAMIL LETTER KA/TAMIL SIGN VIRAMA/TAMIL LETTER SSA + key("\u0B95", joinMoreKeys("\u0BB9", "\u0B95\u0BCD\u0BB7")), + // U+0BA4: "த" TAMIL LETTER TA + "\u0BA4", + // U+0B9A: "ச" TAMIL LETTER CA + // U+0BB8: "ஸ" TAMIL LETTER SA + // U+0BB6/U+0BCD/U+0BB0/U+0BC0: + // "ஶ்ரீ" TAMIL LETTER SHA/TAMIL SIGN VIRAMA/TAMIL LETTER RA + // /TAMIL VOWEL SIGN II + key("\u0B9A", joinMoreKeys("\u0BB8", "\u0BB6\u0BCD\u0BB0\u0BC0")), + // U+0B9F: "ட" TAMIL LETTER TTA + "\u0B9F") + .setKeysOfRow(3, + // U+0B92: "ஒ" TAMIL LETTER O + // U+0BCA: "ொ" TAMIL VOWEL SIGN O + key("\u0B92", moreKey("\u0BCA")), + // U+0B8E: "எ" TAMIL LETTER E + // U+0BC6: "ெ" TAMIL VOWEL SIGN E + key("\u0B8E", moreKey("\u0BC6")), + // U+0BCD: "்" TAMIL SIGN VIRAMA + // U+0BB0: "ர" TAMIL LETTER RA + // U+0BB5: "வ" TAMIL LETTER VA + // U+0BB4: "ழ TAMIL LETTER LLLA + // U+0BB2: "ல" TAMIL LETTER LA + // U+0BB3: "ள" TAMIL LETTER LLA + // U+0BAF: "ய" TAMIL LETTER YA + "\u0BCD", "\u0BB0", "\u0BB5", "\u0BB4", "\u0BB2", "\u0BB3", "\u0BAF", + // U+0BB7: "ஷ" TAMIL LETTER SSA + // U+0B9C: "ஜ" TAMIL LETTER JA + key("\u0BB7", moreKey("\u0B9C"))) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Telugu.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Telugu.java new file mode 100644 index 000000000..370f21eb3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Telugu.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Telugu keyboard. + */ +public final class Telugu extends LayoutBase { + private static final String LAYOUT_NAME = "telugu"; + + public Telugu(final Locale locale) { + super(new TeluguCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class TeluguCustomizer extends LayoutCustomizer { + TeluguCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return TELUGU_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + @Override + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY, key(ZWNJ_KEY, ZWJ_KEY)); + } + + // U+0C05: "అ" TELUGU LETTER A + // U+0C06: "ఆ" TELUGU LETTER AA + // U+0C07: "ఇ" TELUGU LETTER I + private static final ExpectedKey TELUGU_ALPHABET_KEY = key( + "\u0C05\u0C06\u0C07", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(boolean isPhone) { return ALPHABET_COMMON; } + + @Override + ExpectedKey[][] getCommonAlphabetShiftLayout(boolean isPhone, final int elementId) { + return null; + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0C4C: "ౌ" TELUGU VOWEL SIGN AU + // U+0C14: "ఔ" TELUGU LETTER AU + key("\u0C4C", joinMoreKeys("\u0C14", "1")), + // U+0C48: "ై" TELUGU VOWEL SIGN AI + // U+0C10: "ఐ" TELUGU LETTER AI + key("\u0C48", joinMoreKeys("\u0C10", "2")), + // U+0C3E: "ా" TELUGU VOWEL SIGN AA + // U+0C06: "ఆ" TELUGU LETTER AA + key("\u0C3E", joinMoreKeys("\u0C06", "3")), + // U+0C40: "ీ" TELUGU VOWEL SIGN II + // U+0C08: "ఈ" TELUGU LETTER II + key("\u0C40", joinMoreKeys("\u0C08", "4")), + // U+0C42: "ూ" TELUGU VOWEL SIGN UU + // U+0C0A: "ఊ" TELUGU LETTER UU + key("\u0C42", joinMoreKeys("\u0C0A", "5")), + // U+0C2C: "బ" TELUGU LETTER BA + // U+0C2D: "భ" TELUGU LETTER BHA + key("\u0C2C", joinMoreKeys("\u0C2D", "6")), + // U+0C39: "హ" TELUGU LETTER HA + // U+0C03: "ః" TELUGU SIGN VISARGA + key("\u0C39", joinMoreKeys("\u0C03", "7")), + // U+0C17: "గ" TELUGU LETTER GA + // U+0C18: "ఘ" TELUGU LETTER GHA + key("\u0C17", joinMoreKeys("\u0C18", "8")), + // U+0C26: "ద" TELUGU LETTER DA + // U+0C27: "ధ" TELUGU LETTER DHA + key("\u0C26", joinMoreKeys("\u0C27", "9")), + // U+0C1C: "జ" TELUGU LETTER JA + // U+0C1D: "ఝ" TELUGU LETTER JHA + key("\u0C1C", joinMoreKeys("\u0C1D", "0")), + // U+0C21: "డ" TELUGU LETTER DDA + // U+0C22: "ఢ" TELUGU LETTER DDHA + key("\u0C21", moreKey("\u0C22"))) + .setKeysOfRow(2, + // U+0C4B: "ో" TELUGU VOWEL SIGN OO + // U+0C13: "ఓ" TELUGU LETTER OO + key("\u0C4B", moreKey("\u0C13")), + // U+0C47: "ే" TELUGU VOWEL SIGN EE + // U+0C0F: "ఏ" TELUGU LETTER EE + key("\u0C47", moreKey("\u0C0F")), + // U+0C4D: "్" TELUGU SIGN VIRAMA + // U+0C05: "అ" TELUGU LETTER A + key("\u0C4D", moreKey("\u0C05")), + // U+0C3F: "ి" TELUGU VOWEL SIGN I + // U+0C07: "ఇ" TELUGU LETTER I + key("\u0C3F", moreKey("\u0C07")), + // U+0C41: "ు" TELUGU VOWEL SIGN U + // U+0C09: "ఉ" TELUGU LETTER U + key("\u0C41", moreKey("\u0C09")), + // U+0C2A: "ప" TELUGU LETTER PA + // U+0C2B: "ఫ" TELUGU LETTER PHA + key("\u0C2A", moreKey("\u0C2B")), + // U+0C30: "ర" TELUGU LETTER RA + // U+0C31: "ఱ" TELUGU LETTER RRA + // U+0C4D/U+0C30: "్ర" TELUGU SIGN VIRAMA/TELUGU LETTER RA + key("\u0C30", joinMoreKeys("\u0C31", "\u0C4D\u0C30")), + // U+0C15: "క" TELUGU LETTER KA + // U+0C16: "ఖ" TELUGU LETTER KHA + key("\u0C15", moreKey("\u0C16")), + // U+0C24: "త" TELUGU LETTER TA + // U+0C25: "థ" TELUGU LETTER THA + key("\u0C24", moreKey("\u0C25")), + // U+0C1A: "చ" TELUGU LETTER CA + // U+0C1B: "ఛ" TELUGU LETTER CHA + key("\u0C1A", moreKey("\u0C1B")), + // U+0C1F: "ట" TELUGU LETTER TTA + // U+0C20: "ఠ" TELUGU LETTER TTHA + key("\u0C1F", moreKey("\u0C20"))) + .setKeysOfRow(3, + // U+0C4A: "ొ" TELUGU VOWEL SIGN O + // U+0C12: "ఒ" TELUGU LETTER O + key("\u0C4A", moreKey("\u0C12")), + // U+0C46: "ె" TELUGU VOWEL SIGN E + // U+0C0E: "ఎ" TELUGU LETTER E + key("\u0C46", moreKey("\u0C0E")), + // U+0C2E: "మ" TELUGU LETTER MA + // U+0C02: "ం" TELUGU SIGN ANUSVARA + // U+0C01: "ఁ" TELUGU SIGN CANDRABINDU + key("\u0C2E", joinMoreKeys("\u0C02", "\u0C01")), + // U+0C28: "న" TELUGU LETTER NA + // U+0C23: "ణ" TELUGU LETTER NNA + // U+0C19: "ఙ" TELUGU LETTER NGA + // U+0C1E: "ఞ" TELUGU LETTER NYA + key("\u0C28", joinMoreKeys("\u0C23", "\u0C19", "\u0C1E")), + // U+0C35: "వ" TELUGU LETTER VA + "\u0C35", + // U+0C32: "ల" TELUGU LETTER LA + // U+0C33: "ళ" TELUGU LETTER LLA + key("\u0C32", moreKey("\u0C33")), + // U+0C38: "స" TELUGU LETTER SA + // U+0C36: "శ" TELUGU LETTER SHA + key("\u0C38", moreKey("\u0C36")), + // U+0C0B: "ఋ" TELUGU LETTER VOCALIC R + // U+0C43: "ృ" TELUGU VOWEL SIGN VOCALIC R + key("\u0C0B", moreKey("\u0C43")), + // U+0C37: "ష" TELUGU LETTER SSA + // U+0C15/U+0C4D/U+0C37: + // "క్ష" TELUGU LETTER KA/TELUGU SIGN VIRAMA/TELUGU LETTER SSA + key("\u0C37", moreKey("\u0C15\u0C4D\u0C37")), + // U+0C2F: "య" TELUGU LETTER YA + // U+0C1C/U+0C4D/U+0C1E: + // "జ్ఞ" TELUGU LETTER JA/TELUGU SIGN VIRAMA/TELUGU LETTER NYA + key("\u0C2F", moreKey("\u0C1C\u0C4D\u0C1E"))) + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Thai.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Thai.java new file mode 100644 index 000000000..f19d44f8f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Thai.java @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +/** + * The Thai alphabet keyboard. + */ +public final class Thai extends LayoutBase { + private static final String LAYOUT_NAME = "thai"; + + public Thai(final Locale locale) { + super(new ThaiCustomizer(locale), Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + private static class ThaiCustomizer extends LayoutCustomizer { + ThaiCustomizer(final Locale locale) { super(locale); } + + @Override + public int getNumberOfRows() { return 5; } + + @Override + public ExpectedKey getAlphabetKey() { return THAI_ALPHABET_KEY; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_BAHT; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { return EMPTY_KEYS; } + + // U+0E01: "ก" THAI CHARACTER KO KAI + // U+0E02: "ข" THAI CHARACTER KHO KHAI + // U+0E04: "ค" THAI CHARACTER KHO KHWAI + private static final ExpectedKey THAI_ALPHABET_KEY = key( + "\u0E01\u0E02\u0E04", Constants.CODE_SWITCH_ALPHA_SYMBOL); + + // U+0E3F: "฿" THAI CURRENCY SYMBOL BAHT + private static final ExpectedKey CURRENCY_BAHT = key("\u0E3F", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(ALPHABET_COMMON); + if (isPhone) { + // U+0E03: "ฃ" THAI CHARACTER KHO KHUAT + builder.addKeysOnTheRightOfRow(3, "\u0E03"); + } else { + // U+0E03: "ฃ" THAI CHARACTER KHO KHUAT + builder.addKeysOnTheRightOfRow(2, "\u0E03") + .addKeysOnTheRightOfRow(4, (Object[])EXCLAMATION_AND_QUESTION_MARKS); + } + return builder.build(); + } + + @Override + public ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, + final int elementId) { + if (elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) { + return getCommonAlphabetLayout(isPhone); + } + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( + ALPHABET_SHIFTED_COMMON); + if (isPhone) { + // U+0E05: "ฅ" THAI CHARACTER KHO KHON + builder.addKeysOnTheRightOfRow(3, "\u0E05"); + } else { + // U+0E05: "ฅ" THAI CHARACTER KHO KHON + builder.addKeysOnTheRightOfRow(2, "\u0E05"); + } + return builder.build(); + } + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0E45: "ๅ" THAI CHARACTER LAKKHANGYAO + "\u0E45", + // U+0E51: "๑" THAI DIGIT ONE + key("/", joinMoreKeys("1", "\u0E51")), + // U+0E52: "๒" THAI DIGIT TWO + key("_", joinMoreKeys("2", "\u0E52")), + // U+0E20: "ภ" THAI CHARACTER PHO SAMPHAO + // U+0E53: "๓" THAI DIGIT THREE + key("\u0E20", joinMoreKeys("3", "\u0E53")), + // U+0E16: "ถ" THAI CHARACTER THO THUNG + // U+0E54: "๔" THAI DIGIT FOUR + key("\u0E16", joinMoreKeys("4", "\u0E54")), + // U+0E38: " ุ" THAI CHARACTER SARA U + key(" \u0E38", "\u0E38"), + // U+0E36: " ึ" THAI CHARACTER SARA UE + key(" \u0E36", "\u0E36"), + // U+0E04: "ค" THAI CHARACTER KHO KHWAI + // U+0E55: "๕" THAI DIGIT FIVE + key("\u0E04", joinMoreKeys("5", "\u0E55")), + // U+0E15: "ต" THAI CHARACTER TO TAO + // U+0E56: "๖" THAI DIGIT SIX + key("\u0E15", joinMoreKeys("6", "\u0E56")), + // U+0E08: "จ" THAI CHARACTER CHO CHAN + // U+0E57: "๗" THAI DIGIT SEVEN + key("\u0E08", joinMoreKeys("7", "\u0E57")), + // U+0E02: "ข" THAI CHARACTER KHO KHAI + // U+0E58: "๘" THAI DIGIT EIGHT + key("\u0E02", joinMoreKeys("8", "\u0E58")), + // U+0E0A: "ช" THAI CHARACTER CHO CHANG + // U+0E59: "๙" THAI DIGIT NINE + key("\u0E0A", joinMoreKeys("9", "\u0E59"))) + .setKeysOfRow(2, + // U+0E46: "ๆ" THAI CHARACTER MAIYAMOK + // U+0E50: "๐" THAI DIGIT ZERO + key("\u0E46", joinMoreKeys("0", "\u0E50")), + // U+0E44: "ไ" THAI CHARACTER SARA AI MAIMALAI + // U+0E33: "ำ" THAI CHARACTER SARA AM + // U+0E1E: "พ" THAI CHARACTER PHO PHAN + // U+0E30: "ะ" THAI CHARACTER SARA A + "\u0E44", "\u0E33", "\u0E1E", "\u0E30", + // U+0E31: " ั" THAI CHARACTER MAI HAN-AKAT + key(" \u0E31", "\u0E31"), + // U+0E35: " ี" HAI CHARACTER SARA II + key(" \u0E35", "\u0E35"), + // U+0E23: "ร" THAI CHARACTER RO RUA + // U+0E19: "น" THAI CHARACTER NO NU + // U+0E22: "ย" THAI CHARACTER YO YAK + // U+0E1A: "บ" THAI CHARACTER BO BAIMAI + // U+0E25: "ล" THAI CHARACTER LO LING + "\u0E23", "\u0E19", "\u0E22", "\u0E1A", "\u0E25") + .setKeysOfRow(3, + // U+0E1F: "ฟ" THAI CHARACTER FO FAN + // U+0E2B: "ห" THAI CHARACTER HO HIP + // U+0E01: "ก" THAI CHARACTER KO KAI + // U+0E14: "ด" THAI CHARACTER DO DEK + // U+0E40: "เ" THAI CHARACTER SARA E + "\u0E1F", "\u0E2B", "\u0E01", "\u0E14", "\u0E40", + // U+0E49: " ้" THAI CHARACTER MAI THO + key(" \u0E49", "\u0E49"), + // U+0E48: " ่" THAI CHARACTER MAI EK + key(" \u0E48", "\u0E48"), + // U+0E32: "า" THAI CHARACTER SARA AA + // U+0E2A: "ส" THAI CHARACTER SO SUA + // U+0E27: "ว" THAI CHARACTER WO WAEN + // U+0E07: "ง" THAI CHARACTER NGO NGU + "\u0E32", "\u0E2A", "\u0E27", "\u0E07") + .setKeysOfRow(4, + // U+0E1C: "ผ" THAI CHARACTER PHO PHUNG + // U+0E1B: "ป" THAI CHARACTER PO PLA + // U+0E41: "แ" THAI CHARACTER SARA AE + // U+0E2D: "อ" THAI CHARACTER O ANG + "\u0E1C", "\u0E1B", "\u0E41", "\u0E2D", + // U+0E34: " ิ" THAI CHARACTER SARA I + key(" \u0E34", "\u0E34"), + // U+0E37: " ื" THAI CHARACTER SARA UEE + key(" \u0E37", "\u0E37"), + // U+0E17: "ท" THAI CHARACTER THO THAHAN + // U+0E21: "ม" THAI CHARACTER MO MA + // U+0E43: "ใ" THAI CHARACTER SARA AI MAIMUAN + // U+0E1D: "ฝ" THAI CHARACTER FO FA + "\u0E17", "\u0E21", "\u0E43", "\u0E1D") + .build(); + + private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + // U+0E51: "๑" THAI DIGIT ONE + // U+0E52: "๒" THAI DIGIT TWO + // U+0E53: "๓" THAI DIGIT THREE + // U+0E54: "๔" THAI DIGIT FOUR + // U+0E39: " ู" THAI CHARACTER SARA UU + "+", "\u0E51", "\u0E52", "\u0E53", "\u0E54", + key(" \u0E39", "\u0E39"), + // U+0E3F: "฿" THAI CURRENCY SYMBOL BAHT + // U+0E55: "๕" THAI DIGIT FIVE + // U+0E56: "๖" THAI DIGIT SIX + // U+0E57: "๗" THAI DIGIT SEVEN + // U+0E58: "๘" THAI DIGIT EIGHT + // U+0E59: "๙" THAI DIGIT NINE + "\u0E3F", "\u0E55", "\u0E56", "\u0E57", "\u0E58", "\u0E59") + .setKeysOfRow(2, + // U+0E50: "๐" THAI DIGIT ZERO + // U+0E0E: "ฎ" THAI CHARACTER DO CHADA + // U+0E11: "ฑ" THAI CHARACTER THO NANGMONTHO + // U+0E18: "ธ" THAI CHARACTER THO THONG + "\u0E50", "\"", "\u0E0E", "\u0E11", "\u0E18", + // U+0E4D: " ํ" THAI CHARACTER THANTHAKHAT + key(" \u0E4D", "\u0E4D"), + // U+0E4A: " ๊" THAI CHARACTER MAI TRI + key(" \u0E4A", "\u0E4A"), + // U+0E13: "ณ" THAI CHARACTER NO NEN + // U+0E2F: "ฯ" THAI CHARACTER PAIYANNOI + // U+0E0D: "ญ" THAI CHARACTER YO YING + // U+0E10: "ฐ" THAI CHARACTER THO THAN + "\u0E13", "\u0E2F", "\u0E0D", "\u0E10", ",") + .setKeysOfRow(3, + // U+0E24: "ฤ" THAI CHARACTER RU + // U+0E06: "ฆ" THAI CHARACTER KHO RAKHANG + // U+0E0F: "ฏ" THAI CHARACTER TO PATAK + // U+0E42: "โ" THAI CHARACTER SARA O + // U+0E0C: "ฌ" THAI CHARACTER CHO CHOE + "\u0E24", "\u0E06", "\u0E0F", "\u0E42", "\u0E0C", + // U+0E47: " ็" THAI CHARACTER MAITAIKHU + key(" \u0E47", "\u0E47"), + // U+0E4B: " ๋" THAI CHARACTER MAI CHATTAWA + key(" \u0E4B", "\u0E4B"), + // U+0E29: "ษ" THAI CHARACTER SO RUSI + // U+0E28: "ศ" THAI CHARACTER SO SALA + // U+0E0B: "ซ" THAI CHARACTER SO SO + "\u0E29", "\u0E28", "\u0E0B", ".") + .setKeysOfRow(4, + // U+0E09: "ฉ" THAI CHARACTER CHO CHING + // U+0E2E: "ฮ" THAI CHARACTER HO NOKHUK + "(", ")", "\u0E09", "\u0E2E", + // U+0E3A: " ฺ" THAI CHARACTER PHINTHU + key(" \u0E3A", "\u0E3A"), + // U+0E4C: " ์" THAI CHARACTER THANTHAKHAT + key(" \u0E4C", "\u0E4C"), + // U+0E12: "ฒ" THAI CHARACTER THO PHUTHAO + // U+0E2C: "ฬ" THAI CHARACTER LO CHULA + // U+0E26: "ฦ" THAI CHARACTER LU + "?", "\u0E12", "\u0E2C", "\u0E26") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/Uzbek.java b/tests/src/org/kelar/inputmethod/keyboard/layout/Uzbek.java new file mode 100644 index 000000000..dcee48857 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/Uzbek.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout; + +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +/** + * The Uzbek alphabet keyboard. + */ +public final class Uzbek extends LayoutBase { + private static final String LAYOUT_NAME = "uzbek"; + + public Uzbek(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW1_11 = "ROW1_11"; + public static final String ROW2_10 = "ROW2_10"; + public static final String ROW2_11 = "ROW2_11"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("y", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0")), + ROW1_11) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW2_10, ROW2_11) + .setKeysOfRow(3, "z", "x", "c", "v", "b", "n", "m") + .build(); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/BengaliCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/BengaliCustomizer.java new file mode 100644 index 000000000..b9faf5ea6 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/BengaliCustomizer.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public class BengaliCustomizer extends LayoutCustomizer { + public BengaliCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return BENGALI_ALPHABET_KEY; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + // U+0995: "क" BENGALI LETTER KA + // U+0996: "ख" BENGALI LETTER KHA + // U+0997: "ग" BENGALI LETTER GA + private static final ExpectedKey BENGALI_ALPHABET_KEY = key( + "\u0995\u0996\u0997", Constants.CODE_SWITCH_ALPHA_SYMBOL); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DanishCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DanishCustomizer.java new file mode 100644 index 000000000..c7ec65fb3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DanishCustomizer.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class DanishCustomizer extends EuroCustomizer { + public DanishCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00E6") + .setMoreKeysOf("\u00E6", "\u00E4") + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00F8") + .setMoreKeysOf("\u00F8", "\u00F6"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E1", "\u00E4", "\u00E0", "\u00E2", "\u00E3", "\u0101"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F3", "\u00F4", "\u00F2", "\u00F5", "\u0153", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + .setMoreKeysOf("e", "\u00E9", "\u00EB") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00FB", "\u00F9", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + .setMoreKeysOf("i", "\u00ED", "\u00EF") + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u00DF", "\u015B", "\u0161") + // U+00F0: "ð" LATIN SMALL LETTER ETH + .setMoreKeysOf("d", "\u00F0") + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u0142") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DevanagariCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DevanagariCustomizer.java new file mode 100644 index 000000000..4308fac31 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DevanagariCustomizer.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public class DevanagariCustomizer extends LayoutCustomizer { + public DevanagariCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return HINDI_ALPHABET_KEY; } + + @Override + public ExpectedKey getSymbolsKey() { return HINDI_SYMBOLS_KEY; } + + @Override + public ExpectedKey getBackToSymbolsKey() { return HINDI_BACK_TO_SYMBOLS_KEY; } + + // U+0915: "क" DEVANAGARI LETTER KA + // U+0916: "ख" DEVANAGARI LETTER KHA + // U+0917: "ग" DEVANAGARI LETTER GA + private static final ExpectedKey HINDI_ALPHABET_KEY = key( + "\u0915\u0916\u0917", Constants.CODE_SWITCH_ALPHA_SYMBOL); + // U+0967: "१" DEVANAGARI DIGIT ONE + // U+0968: "२" DEVANAGARI DIGIT TWO + // U+0969: "३" DEVANAGARI DIGIT THREE + private static final String HINDI_SYMBOLS_LABEL = "?\u0967\u0968\u0969"; + private static final ExpectedKey HINDI_SYMBOLS_KEY = key(HINDI_SYMBOLS_LABEL, + Constants.CODE_SWITCH_ALPHA_SYMBOL); + private static final ExpectedKey HINDI_BACK_TO_SYMBOLS_KEY = key(HINDI_SYMBOLS_LABEL, + Constants.CODE_SHIFT); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DutchCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DutchCustomizer.java new file mode 100644 index 000000000..fc7729562 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DutchCustomizer.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class DutchCustomizer extends EuroCustomizer { + public DutchCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E1", "\u00E4", "\u00E2", "\u00E0", "\u00E6", "\u00E3", "\u00E5", + "\u0101") + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u00EB", "\u00EA", "\u00E8", "\u0119", "\u0117", "\u0113") + // U+0133: "ij" LATIN SMALL LIGATURE IJ + .setMoreKeysOf("y", "\u0133") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00FB", "\u00F9", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+0133: "ij" LATIN SMALL LIGATURE IJ + .setMoreKeysOf("i", + "\u00ED", "\u00EF", "\u00EC", "\u00EE", "\u012F", "\u012B", "\u0133") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F3", "\u00F6", "\u00F4", "\u00F2", "\u00F5", "\u0153", "\u00F8", + "\u014D") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DvorakCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DvorakCustomizer.java new file mode 100644 index 000000000..815e19680 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/DvorakCustomizer.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey; + +import java.util.Locale; + +public class DvorakCustomizer extends LayoutCustomizer { + public DvorakCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return isPhone ? joinKeys(SHIFT_KEY): joinKeys(SHIFT_KEY, key("q")); + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : joinKeys(key("z"), SHIFT_KEY); + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + // U+00A1: "¡" INVERTED EXCLAMATION MARK + return isPhone ? joinKeys(key("q", SETTINGS_KEY)) + : joinKeys(key("!", joinMoreKeys("\u00A1", SETTINGS_KEY))); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + final ExpectedAdditionalMoreKey[] punctuationMoreKeys = + convertToAdditionalMoreKeys(getPunctuationMoreKeys(isPhone)); + // U+00BF: "¿" INVERTED QUESTION MARK + return isPhone + ? joinKeys(key("z", punctuationMoreKeys)) + : joinKeys(key("?", joinMoreKeys(punctuationMoreKeys, "\u00BF"))); + } + + private static ExpectedAdditionalMoreKey[] convertToAdditionalMoreKeys( + final ExpectedKey ... moreKeys) { + final ExpectedAdditionalMoreKey[] additionalMoreKeys = + new ExpectedAdditionalMoreKey[moreKeys.length]; + for (int index = 0; index < moreKeys.length; index++) { + additionalMoreKeys[index] = ExpectedAdditionalMoreKey.newInstance(moreKeys[index]); + } + return additionalMoreKeys; + } + + public static class EnglishDvorakCustomizer extends DvorakCustomizer { + private final EnglishCustomizer mEnglishCustomizer; + + public EnglishDvorakCustomizer(final Locale locale) { + super(locale); + mEnglishCustomizer = new EnglishCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mEnglishCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EastSlavicCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EastSlavicCustomizer.java new file mode 100644 index 000000000..1cf087a09 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EastSlavicCustomizer.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public class EastSlavicCustomizer extends LayoutCustomizer { + public EastSlavicCustomizer(final Locale locale) { super(locale); } + + @Override + public final ExpectedKey getAlphabetKey() { return EAST_SLAVIC_ALPHABET_KEY; } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + // U+0410: "А" CYRILLIC CAPITAL LETTER A + // U+0411: "Б" CYRILLIC CAPITAL LETTER BE + // U+0412: "В" CYRILLIC CAPITAL LETTER VE + private static final ExpectedKey EAST_SLAVIC_ALPHABET_KEY = key( + "\u0410\u0411\u0412", Constants.CODE_SWITCH_ALPHA_SYMBOL); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EnglishCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EnglishCustomizer.java new file mode 100644 index 000000000..75454f2b7 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EnglishCustomizer.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class EnglishCustomizer extends LayoutCustomizer { + public EnglishCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0113") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FB", "\u00FC", "\u00F9", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + .setMoreKeysOf("i", "\u00ED", "\u00EE", "\u00EF", "\u012B", "\u00EC") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + .setMoreKeysOf("o", + "\u00F3", "\u00F4", "\u00F6", "\u00F2", "\u0153", "\u00F8", "\u014D", + "\u00F5") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E0", "\u00E1", "\u00E2", "\u00E4", "\u00E6", "\u00E3", "\u00E5", + "\u0101") + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + .setMoreKeysOf("s", "\u00DF") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + .setMoreKeysOf("c", "\u00E7") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + .setMoreKeysOf("n", "\u00F1"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EstonianEECustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EstonianEECustomizer.java new file mode 100644 index 000000000..91c10405a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EstonianEECustomizer.java @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class EstonianEECustomizer extends EuroCustomizer { + public EstonianEECustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00FC") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F6") + .setMoreKeysOf("\u00F6", "\u00F5") + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E4"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + .setMoreKeysOf("a", "\u0101", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u00E5", + "\u00E6", "\u0105"); + } + + protected void setMoreKeysOfI(final ExpectedKeyboardBuilder builder, final int elementId) { + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + if (elementId == KeyboardId.ELEMENT_ALPHABET) { + builder.setMoreKeysOf("i", + "\u012B", "\u00EC", "\u012F", "\u00ED", "\u00EE", "\u00EF", "\u0131"); + } else { + // The upper-case letter of "ı" in Estonian locale is "I". It should be omitted + // from the more keys of "I". + builder.setMoreKeysOf("i", + "\u012B", "\u00EC", "\u012F", "\u00ED", "\u00EE", "\u00EF"); + } + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .setMoreKeysOf("o", "\u00F5", "\u00F2", "\u00F3", "\u00F4", "\u0153", "\u0151", + "\u00F8"); + } + + protected void setMoreKeysOfU(final ExpectedKeyboardBuilder builder) { + builder + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + .setMoreKeysOf("u", "\u016B", "\u0173", "\u00F9", "\u00FA", "\u00FB", "\u016F", + "\u0171"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder, + final int elementId) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfI(builder, elementId); + setMoreKeysOfO(builder); + setMoreKeysOfU(builder); + return builder + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + .setMoreKeysOf("e", + "\u0113", "\u00E8", "\u0117", "\u00E9", "\u00EA", "\u00EB", "\u0119", + "\u011B") + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + .setMoreKeysOf("r", "\u0157", "\u0159", "\u0155") + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + .setMoreKeysOf("t", "\u0163", "\u0165") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B", "\u015F") + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u010F") + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + .setMoreKeysOf("g", "\u0123", "\u011F") + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + .setMoreKeysOf("k", "\u0137") + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + .setMoreKeysOf("l", "\u013C", "\u0142", "\u013A", "\u013E") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + .setMoreKeysOf("z", "\u017E", "\u017C", "\u017A") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u00E7", "\u0107") + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u0146", "\u00F1", "\u0144"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EuroCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EuroCustomizer.java new file mode 100644 index 000000000..162843a7e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/EuroCustomizer.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * The layout customize class for countries that use Euro. + */ +public class EuroCustomizer extends LayoutCustomizer { + public EuroCustomizer(final Locale locale) { + super(locale); + } + + @Override + public final ExpectedKey getCurrencyKey() { return Symbols.CURRENCY_EURO; } + + @Override + public final ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_THAN_EURO; + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/FinnishCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/FinnishCustomizer.java new file mode 100644 index 000000000..e70251df7 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/FinnishCustomizer.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class FinnishCustomizer extends EuroCustomizer { + public FinnishCustomizer(final Locale locale) { super(locale); } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F6") + .setMoreKeysOf("\u00F6","\u00F8") + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E4") + .setMoreKeysOf("\u00E4", "\u00E6"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E6", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u0101"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u00F4", "\u00F2", "\u00F3", "\u00F5", "\u0153", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + .setMoreKeysOf("u", "\u00FC") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + .setMoreKeysOf("z", "\u017E", "\u017A", "\u017C"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/FrenchCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/FrenchCustomizer.java new file mode 100644 index 000000000..b78ce4fb1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/FrenchCustomizer.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class FrenchCustomizer extends LayoutCustomizer { + public FrenchCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + .setAdditionalMoreKeysPositionOf("a", 3) + .setMoreKeysOf("a", + "\u00E0", "\u00E2", "\u00E6", "\u00E1", "\u00E4", "\u00E3", "\u00E5", + "\u0101", "\u00AA") + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setAdditionalMoreKeysPositionOf("e", 5) + .setMoreKeysOf("e", + "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", "\u0113") + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FF") + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setAdditionalMoreKeysPositionOf("u", 3) + .setMoreKeysOf("u", "\u00F9", "\u00FB", "\u00FC", "\u00FA", "\u016B") + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setAdditionalMoreKeysPositionOf("i", 2) + .setMoreKeysOf("i", "\u00EE", "\u00EF", "\u00EC", "\u00ED", "\u012F", "\u012B") + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + .setAdditionalMoreKeysPositionOf("o", 3) + .setMoreKeysOf("o", + "\u00F4", "\u0153", "\u00F6", "\u00F2", "\u00F3", "\u00F5", "\u00F8", + "\u014D", "\u00BA") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") + .setAdditionalMoreKeysPositionOf("c", 2); + } + + public static final class FrenchEuroCustomizer extends FrenchCustomizer { + private final EuroCustomizer mEuroCustomizer; + + public FrenchEuroCustomizer(final Locale locale) { + super(locale); + mEuroCustomizer = new EuroCustomizer(locale); + } + + @Override + public final ExpectedKey getCurrencyKey() { return mEuroCustomizer.getCurrencyKey(); } + + @Override + public final ExpectedKey[] getOtherCurrencyKeys() { + return mEuroCustomizer.getOtherCurrencyKeys(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/GermanCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/GermanCustomizer.java new file mode 100644 index 000000000..3cc165b39 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/GermanCustomizer.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class GermanCustomizer extends LayoutCustomizer { + public GermanCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + .setMoreKeysOf("e", "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0117") + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B") + .setAdditionalMoreKeysPositionOf("u", 2) + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F6", "\u00F4", "\u00F2", "\u00F3", "\u00F5", "\u0153", "\u00F8", + "\u014D") + .setAdditionalMoreKeysPositionOf("o", 2) + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E4", "\u00E2", "\u00E0", "\u00E1", "\u00E6", "\u00E3", "\u00E5", + "\u0101") + .setAdditionalMoreKeysPositionOf("a", 2) + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u00DF", "\u015B", "\u0161") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } + + public static class GermanEuroCustomizer extends GermanCustomizer { + private final EuroCustomizer mEuroCustomizer; + + public GermanEuroCustomizer(final Locale locale) { + super(locale); + mEuroCustomizer = new EuroCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { return mEuroCustomizer.getCurrencyKey(); } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mEuroCustomizer.getOtherCurrencyKeys(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/HindiCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/HindiCustomizer.java new file mode 100644 index 000000000..6023fe709 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/HindiCustomizer.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +public class HindiCustomizer extends DevanagariCustomizer { + public HindiCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + // U+0964: "।" DEVANAGARI DANDA + final ExpectedKey periodKey = key("\u0964", getPunctuationMoreKeys(isPhone)); + return joinKeys(periodKey); + } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return isPhone ? HINDI_PHONE_PUNCTUATION_MORE_KEYS : HINDI_TABLET_PUNCTUATION_MORE_KEYS; + } + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + + // Punctuation more keys for phone form factor. + private static final ExpectedKey[] HINDI_PHONE_PUNCTUATION_MORE_KEYS = joinKeys( + ",", ".", "?", "!", "#", ")", "(", "/", ";", + "'", "@", ":", "-", "\"", "+", "%", "&"); + // Punctuation more keys for tablet form factor. + private static final ExpectedKey[] HINDI_TABLET_PUNCTUATION_MORE_KEYS = joinKeys( + ",", ".", "'", "#", ")", "(", "/", ";", + "@", ":", "-", "\"", "+", "%", "&"); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/ItalianCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/ItalianCustomizer.java new file mode 100644 index 000000000..6b04af939 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/ItalianCustomizer.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class ItalianCustomizer extends LayoutCustomizer { + public ItalianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E8", "\u00E9", "\u00EA", "\u00EB", "\u0119", "\u0117", "\u0113") + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00F9", "\u00FA", "\u00FB", "\u00FC", "\u016B") + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00EC", "\u00ED", "\u00EE", "\u00EF", "\u012F", "\u012B") + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + .setMoreKeysOf("o", + "\u00F2", "\u00F3", "\u00F4", "\u00F6", "\u00F5", "\u0153", "\u00F8", + "\u014D", "\u00BA") + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + .setMoreKeysOf("a", + "\u00E0", "\u00E1", "\u00E2", "\u00E4", "\u00E6", "\u00E3", "\u00E5", + "\u0101", "\u00AA"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/LayoutCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/LayoutCustomizer.java new file mode 100644 index 000000000..ffac507d1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/LayoutCustomizer.java @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.expected.AbstractLayoutBase; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * This class is used to customize common keyboard layout to language specific layout. + */ +public class LayoutCustomizer extends AbstractLayoutBase { + private final Locale mLocale; + + // Empty keys definition to remove keys by adding this. + protected static final ExpectedKey[] EMPTY_KEYS = joinKeys(); + + public LayoutCustomizer(final Locale locale) { mLocale = locale; } + + public final Locale getLocale() { return mLocale; } + + public int getNumberOfRows() { return 4; } + + /** + * Set accented letters to a specific keyboard element. + * @param builder the {@link ExpectedKeyboardBuilder} object that contains common keyboard + * layout. + * @param elementId the element id of keyboard + * @return the {@link ExpectedKeyboardBuilder} object that contains accented letters as + * "more keys". + */ + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder, + final int elementId) { + // This method can be overridden by an extended class to provide customized expected + // accented letters depending on the shift state of keyboard. + // This is a default behavior to call a shift-state-independent + // {@link #setAccentedLetters(ExpectedKeyboardBuilder)} implementation, so that + // <code>elementId</code> is ignored here. + return setAccentedLetters(builder); + } + + /** + * Set accented letters to common layout. + * @param builder the {@link ExpectedKeyboardBuilder} object that contains common keyboard + * layout. + * @return the {@link ExpectedKeyboardBuilder} object that contains accented letters as + * "more keys". + */ + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder; + } + + /** + * Get the function key to switch to alphabet layout. + * @return the {@link ExpectedKey} of the alphabet key. + */ + public ExpectedKey getAlphabetKey() { return ALPHABET_KEY; } + + /** + * Get the function key to switch to symbols layout. + * @return the {@link ExpectedKey} of the symbols key. + */ + public ExpectedKey getSymbolsKey() { return SYMBOLS_KEY; } + + /** + * Get the function key to switch to symbols shift layout. + * @param isPhone true if requesting phone's key. + * @return the {@link ExpectedKey} of the symbols shift key. + */ + public ExpectedKey getSymbolsShiftKey(boolean isPhone) { + return isPhone ? SYMBOLS_SHIFT_KEY : TABLET_SYMBOLS_SHIFT_KEY; + } + + /** + * Get the function key to switch from symbols shift to symbols layout. + * @return the {@link ExpectedKey} of the back to symbols key. + */ + public ExpectedKey getBackToSymbolsKey() { return BACK_TO_SYMBOLS_KEY; } + + /** + * Get the currency key. + * @return the {@link ExpectedKey} of the currency key. + */ + public ExpectedKey getCurrencyKey() { return Symbols.CURRENCY_DOLLAR; } + + /** + * Get other currencies keys. + * @return the array of {@link ExpectedKey} that represents other currency keys. + */ + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_THAN_DOLLAR; + } + + /** + * Get "more keys" of double quotation mark. + * @return the array of {@link ExpectedKey} of more double quotation marks in natural order. + */ + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_9LR; } + + /** + * Get "more keys" of single quotation mark. + * @return the array of {@link ExpectedKey} of more single quotation marks in natural order. + */ + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_9LR; } + + /** + * Get double angle quotation marks in natural order. + * @return the array of {@link ExpectedKey} of double angle quotation marks in natural + * order. + */ + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_LR; } + + /** + * Get single angle quotation marks in natural order. + * @return the array of {@link ExpectedKey} of single angle quotation marks in natural + * order. + */ + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_LR; } + + /** + * Get the left shift keys. + * @param isPhone true if requesting phone's keys. + * @return the array of {@link ExpectedKey} that should be placed at left edge of the + * keyboard. + */ + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return joinKeys(SHIFT_KEY); + } + + /** + * Get the right shift keys. + * @param isPhone true if requesting phone's keys. + * @return the array of {@link ExpectedKey} that should be placed at right edge of the + * keyboard. + */ + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : joinKeys(EXCLAMATION_AND_QUESTION_MARKS, SHIFT_KEY); + } + + /** + * Get the enter key. + * @param isPhone true if requesting phone's key. + * @return the array of {@link ExpectedKey} that should be placed as an enter key. + */ + public ExpectedKey getEnterKey(final boolean isPhone) { + return isPhone ? key(ENTER_KEY, EMOJI_ACTION_KEY) : ENTER_KEY; + } + + /** + * Get the emoji key. + * @param isPhone true if requesting phone's key. + * @return the array of {@link ExpectedKey} that should be placed as an emoji key. + */ + public ExpectedKey getEmojiKey(final boolean isPhone) { + return EMOJI_NORMAL_KEY; + } + + /** + * Get the space keys. + * @param isPhone true if requesting phone's keys. + * @return the array of {@link ExpectedKey} that should be placed at the center of the + * keyboard. + */ + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY); + } + + /** + * Get the keys left to the spacebar. + * @param isPhone true if requesting phone's keys. + * @return the array of {@link ExpectedKey} that should be placed at left of the spacebar. + */ + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + // U+002C: "," COMMA + return joinKeys(key("\u002C", SETTINGS_KEY)); + } + + /** + * Get the keys right to the spacebar. + * @param isPhone true if requesting phone's keys. + * @return the array of {@link ExpectedKey} that should be placed at right of the spacebar. + */ + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + final ExpectedKey periodKey = key(".", getPunctuationMoreKeys(isPhone)); + return joinKeys(periodKey); + } + + /** + * Get "more keys" for the punctuation key (usually the period key). + * @param isPhone true if requesting phone's keys. + * @return the array of {@link ExpectedKey} that are "more keys" of the punctuation key. + */ + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return isPhone ? PHONE_PUNCTUATION_MORE_KEYS : TABLET_PUNCTUATION_MORE_KEYS; + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NepaliCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NepaliCustomizer.java new file mode 100644 index 000000000..aa557ba5b --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NepaliCustomizer.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +public class NepaliCustomizer extends DevanagariCustomizer { + public NepaliCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_NEPALI; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY, key(ZWNJ_KEY, ZWJ_KEY)); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + // U+0964: "।" DEVANAGARI DANDA + final ExpectedKey periodKey = key("\u0964", getPunctuationMoreKeys(isPhone)); + return joinKeys(periodKey); + } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return isPhone ? NEPALI_PHONE_PUNCTUATION_MORE_KEYS + : NEPALI_TABLET_PUNCTUATION_MORE_KEYS; + } + + // U+0930/U+0941/U+002E "रु." NEPALESE RUPEE SIGN + private static final ExpectedKey CURRENCY_NEPALI = key("\u0930\u0941\u002E", + Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN, Symbols.EURO_SIGN, Symbols.POUND_SIGN, + Symbols.YEN_SIGN, Symbols.PESO_SIGN); + + // Punctuation more keys for phone form factor. + private static final ExpectedKey[] NEPALI_PHONE_PUNCTUATION_MORE_KEYS = joinKeys( + ".", ",", "?", "!", "#", ")", "(", "/", ";", + "'", "@", ":", "-", "\"", "+", "%", "&"); + // Punctuation more keys for tablet form factor. + private static final ExpectedKey[] NEPALI_TABLET_PUNCTUATION_MORE_KEYS = joinKeys( + ".", ",", "'", "#", ")", "(", "/", ";", + "@", ":", "-", "\"", "+", "%", "&"); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NoLanguageCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NoLanguageCustomizer.java new file mode 100644 index 000000000..2581b67bb --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NoLanguageCustomizer.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class NoLanguageCustomizer extends LayoutCustomizer { + public NoLanguageCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0175: "ŵ" LATIN SMALL LETTER W WITH CIRCUMFLEX + .setMoreKeysOf("w", "\u0175") + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+0115: "ĕ" LATIN SMALL LETTER E WITH BREVE + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + .setMoreKeysOf("e", + "\u00E8", "\u00E9", "\u00EA", "\u00EB", "\u0113", "\u0115", "\u0117", + "\u0119", "\u011B") + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + .setMoreKeysOf("r", "\u0155", "\u0157", "\u0159") + // U+00FE: "þ" LATIN SMALL LETTER THORN + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + // U+0167: "ŧ" LATIN SMALL LETTER T WITH STROKE + .setMoreKeysOf("t", "\u00FE", "\u0163", "\u0165", "\u0167") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+0177: "ŷ" LATIN SMALL LETTER Y WITH CIRCUMFLEX + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + // U+0133: "ij" LATIN SMALL LIGATURE IJ + .setMoreKeysOf("y", "\u00FD", "\u0177", "\u00FF", "\u0133") + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+0169: "ũ" LATIN SMALL LETTER U WITH TILDE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+016D: "ŭ" LATIN SMALL LETTER U WITH BREVE + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + .setMoreKeysOf("u", + "\u00F9", "\u00FA", "\u00FB", "\u00FC", "\u0169", "\u016B", "\u016D", + "\u016F", "\u0171", "\u0173") + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0129: "ĩ" LATIN SMALL LETTER I WITH TILDE + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+012D: "ĭ" LATIN SMALL LETTER I WITH BREVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+0133: "ij" LATIN SMALL LIGATURE IJ + .setMoreKeysOf("i", + "\u00EC", "\u00ED", "\u00EE", "\u00EF", "\u0129", "\u012B", "\u012D", + "\u012F", "\u0131", "\u0133") + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+014F: "ŏ" LATIN SMALL LETTER O WITH BREVE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + .setMoreKeysOf("o", + "\u00F2", "\u00F3", "\u00F4", "\u00F5", "\u00F6", "\u00F8", "\u014D", + "\u014F", "\u0151", "\u0153", "\u00BA") + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + .setMoreKeysOf("a", + "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u00E4", "\u00E5", "\u00E6", + "\u0101", "\u0103", "\u0105", "\u00AA") + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015D: "ŝ" LATIN SMALL LETTER S WITH CIRCUMFLEX + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+017F: "ſ" LATIN SMALL LETTER LONG S + .setMoreKeysOf("s", "\u00DF", "\u015B", "\u015D", "\u015F", "\u0161", "\u017F") + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + // U+00F0: "ð" LATIN SMALL LETTER ETH + .setMoreKeysOf("d", "\u010F", "\u0111", "\u00F0") + // U+011D: "ĝ" LATIN SMALL LETTER G WITH CIRCUMFLEX + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + // U+0121: "ġ" LATIN SMALL LETTER G WITH DOT ABOVE + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + .setMoreKeysOf("g", "\u011D", "\u011F", "\u0121", "\u0123") + // U+0125: "ĥ" LATIN SMALL LETTER H WITH CIRCUMFLEX + .setMoreKeysOf("h", "\u0125") + // U+0135: "ĵ" LATIN SMALL LETTER J WITH CIRCUMFLEX + .setMoreKeysOf("j", "\u0135") + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + // U+0138: "ĸ" LATIN SMALL LETTER KRA + .setMoreKeysOf("k", "\u0137", "\u0138") + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + // U+0140: "ŀ" LATIN SMALL LETTER L WITH MIDDLE DOT + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u013A", "\u013C", "\u013E", "\u0140", "\u0142") + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017A", "\u017C", "\u017E") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+0109: "ĉ" LATIN SMALL LETTER C WITH CIRCUMFLEX + // U+010B: "ċ" LATIN SMALL LETTER C WITH DOT ABOVE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u0109", "\u010B", "\u010D") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+0149: "ʼn" LATIN SMALL LETTER N PRECEDED BY APOSTROPHE + // U+014B: "ŋ" LATIN SMALL LETTER ENG + .setMoreKeysOf("n", "\u00F1", "\u0144", "\u0146", "\u0148", "\u0149", "\u014B"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NorwegianCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NorwegianCustomizer.java new file mode 100644 index 000000000..02dd48dc0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/NorwegianCustomizer.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class NorwegianCustomizer extends LayoutCustomizer { + public NorwegianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F8") + .setMoreKeysOf("\u00F8", "\u00F6") + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E6") + .setMoreKeysOf("\u00E6", "\u00E4"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E4", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u0101"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F4", "\u00F2", "\u00F3", "\u00F5", "\u0153", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", "\u0113") + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/PcQwertyCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/PcQwertyCustomizer.java new file mode 100644 index 000000000..03d72a485 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/PcQwertyCustomizer.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +public class PcQwertyCustomizer extends LayoutCustomizer { + public PcQwertyCustomizer(final Locale locale) { super(locale); } + + @Override + public int getNumberOfRows() { return 5; } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return joinKeys(SHIFT_KEY); + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return joinKeys(SHIFT_KEY); + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + return joinKeys(SETTINGS_KEY); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + return isPhone + ? joinKeys(key(ENTER_KEY, EMOJI_ACTION_KEY)) + : joinKeys(EMOJI_NORMAL_KEY); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/PortugueseCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/PortugueseCustomizer.java new file mode 100644 index 000000000..253b63e2f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/PortugueseCustomizer.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class PortugueseCustomizer extends LayoutCustomizer { + public PortugueseCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + .setMoreKeysOf("e", + "\u00E9", "\u00EA", "\u00E8", "\u0119", "\u0117", "\u0113", "\u00EB") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00F9", "\u00FB", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00ED", "\u00EE", "\u00EC", "\u00EF", "\u012F", "\u012B") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + .setMoreKeysOf("o", + "\u00F3", "\u00F5", "\u00F4", "\u00F2", "\u00F6", "\u0153", "\u00F8", + "\u014D", "\u00BA") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + .setMoreKeysOf("a", + "\u00E1", "\u00E3", "\u00E0", "\u00E2", "\u00E4", "\u00E5", "\u00E6", + "\u00AA") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u00E7", "\u010D", "\u0107"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SerbianLatinCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SerbianLatinCustomizer.java new file mode 100644 index 000000000..ef075c264 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SerbianLatinCustomizer.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.SerbianQwertz; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class SerbianLatinCustomizer extends LayoutCustomizer { + public SerbianLatinCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + protected void setSerbianKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .replaceKeyOfLabel(SerbianQwertz.ROW1_11, "\u0161") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .replaceKeyOfLabel(SerbianQwertz.ROW2_10, "\u010D") + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .replaceKeyOfLabel(SerbianQwertz.ROW2_11, "\u0107") + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .replaceKeyOfLabel(SerbianQwertz.ROW3_8, "\u0111") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .replaceKeyOfLabel(SerbianQwertz.ROW3_9, "\u017E"); + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfS(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "š" key. + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfC(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "č" and "ć" keys. + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfD(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "đ" key. + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfZ(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "ž" key. + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setSerbianKeys(builder); + setMoreKeysOfS(builder); + setMoreKeysOfC(builder); + setMoreKeysOfD(builder); + setMoreKeysOfZ(builder); + return builder + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + .setMoreKeysOf("e", "\u00E8") + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + .setMoreKeysOf("i", "\u00EC"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SouthSlavicLayoutCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SouthSlavicLayoutCustomizer.java new file mode 100644 index 000000000..bfe5913f6 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SouthSlavicLayoutCustomizer.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public class SouthSlavicLayoutCustomizer extends LayoutCustomizer { + public SouthSlavicLayoutCustomizer(final Locale locale) { + super(locale); + } + + @Override + public final ExpectedKey getAlphabetKey() { return SOUTH_SLAVIC_ALPHABET_KEY; } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + // U+0410: "А" CYRILLIC CAPITAL LETTER A + // U+0411: "Б" CYRILLIC CAPITAL LETTER BE + // U+0412: "В" CYRILLIC CAPITAL LETTER VE + private static final ExpectedKey SOUTH_SLAVIC_ALPHABET_KEY = key( + "\u0410\u0411\u0412", Constants.CODE_SWITCH_ALPHA_SYMBOL); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SpanishCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SpanishCustomizer.java new file mode 100644 index 000000000..400481c14 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SpanishCustomizer.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class SpanishCustomizer extends LayoutCustomizer { + public SpanishCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return isPhone ? SPANISH_PHONE_PUNCTUATION_MORE_KEYS : TABLET_PUNCTUATION_MORE_KEYS; + } + + // Punctuation more keys for phone form factor. + private static final ExpectedKey[] SPANISH_PHONE_PUNCTUATION_MORE_KEYS = joinKeys( + // U+00A1: "¡" INVERTED EXCLAMATION MARK + // U+00BF: "¿" INVERTED QUESTION MARK + ",", "?", "!", "#", ")", "(", "/", ";", "\u00A1", + "'", "@", ":", "-", "\"", "+", "%", "&", "\u00BF"); + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u00E8", "\u00EB", "\u00EA", "\u0119", "\u0117", "\u0113") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00F9", "\u00FB", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00ED", "\u00EF", "\u00EC", "\u00EE", "\u012F", "\u012B") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + .setMoreKeysOf("o", + "\u00F3", "\u00F2", "\u00F6", "\u00F4", "\u00F5", "\u00F8", "\u0153", + "\u014D", "\u00BA") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + .setMoreKeysOf("a", + "\u00E1", "\u00E0", "\u00E4", "\u00E2", "\u00E3", "\u00E5", "\u0105", + "\u00E6", "\u0101", "\u00AA") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + .replaceKeyOfLabel(Spanish.ROW2_10, "\u00F1") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SwedishCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SwedishCustomizer.java new file mode 100644 index 000000000..325f94f97 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/SwedishCustomizer.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class SwedishCustomizer extends LayoutCustomizer { + private final LayoutCustomizer mEuroCustomizer; + + public SwedishCustomizer(final Locale locale) { + super(locale); + mEuroCustomizer = new EuroCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { + return mEuroCustomizer.getCurrencyKey(); + } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mEuroCustomizer.getOtherCurrencyKeys(); + } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F6") + .setMoreKeysOf("\u00F6", "\u00F8", "\u0153") + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E4") + .setMoreKeysOf("\u00E4", "\u00E6"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + .setMoreKeysOf("a", "\u00E6", "\u00E1", "\u00E0", "\u00E2", "\u0105", "\u00E3"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u0153", "\u00F3", "\u00F2", "\u00F4", "\u00F5", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + .setMoreKeysOf("e", "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119") + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + .setMoreKeysOf("r", "\u0159") + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + // U+00FE: "þ" LATIN SMALL LETTER THORN + .setMoreKeysOf("t", "\u0165", "\u00FE") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FC", "\u00FA", "\u00F9", "\u00FB", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + .setMoreKeysOf("i", "\u00ED", "\u00EC", "\u00EE", "\u00EF") + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + .setMoreKeysOf("s", "\u015B", "\u0161", "\u015F", "\u00DF") + // U+00F0: "ð" LATIN SMALL LETTER ETH + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u00F0", "\u010F") + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u0142") + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + .setMoreKeysOf("z", "\u017A", "\u017E", "\u017C") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + .setMoreKeysOf("n", "\u0144", "\u00F1", "\u0148"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/TamilCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/TamilCustomizer.java new file mode 100644 index 000000000..13da88037 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/TamilCustomizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.Locale; + +public class TamilCustomizer extends LayoutCustomizer { + public TamilCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getAlphabetKey() { return TAMIL_ALPHABET_KEY; } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return EMPTY_KEYS; + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + // U+0BA4: "த" TAMIL LETTER TA + // U+0BAE/U+0BBF: "மி" TAMIL LETTER MA/TAMIL VOWEL SIGN I + // U+0BB4/U+0BCD: "ழ்" TAMIL LETTER LLLA/TAMIL SIGN VIRAMA + private static final ExpectedKey TAMIL_ALPHABET_KEY = key( + "\u0BA4\u0BAE\u0BBF\u0BB4\u0BCD", Constants.CODE_SWITCH_ALPHA_SYMBOL); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/TurkicCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/TurkicCustomizer.java new file mode 100644 index 000000000..6789a6e95 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/TurkicCustomizer.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * Turkic languages layout customizer. + */ +public class TurkicCustomizer extends LayoutCustomizer { + public TurkicCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0259: "ə" LATIN SMALL LETTER SCHWA + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + .setMoreKeysOf("e", "\u0259", "\u00E9") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + .setMoreKeysOf("y", "\u00FD") + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B") + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", + "\u0131", "\u00EE", "\u00EF", "\u00EC", "\u00ED", "\u012F", "\u012B") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F6", "\u00F4", "\u0153", "\u00F2", "\u00F3", "\u00F5", "\u00F8", + "\u014D") + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + .setMoreKeysOf("a", "\u00E2", "\u00E4", "\u00E1") + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u015F", "\u00DF", "\u015B", "\u0161") + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + .setMoreKeysOf("g", "\u011F") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017E") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + .setMoreKeysOf("n", "\u0148", "\u00F1"); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/UzbekCustomizer.java b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/UzbekCustomizer.java new file mode 100644 index 000000000..08dd3fd25 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/customizer/UzbekCustomizer.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.customizer; + +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +public class UzbekCustomizer extends TurkicCustomizer { + public UzbekCustomizer(final Locale locale) { super(locale); } + + protected void setUzbekKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+006F/U+02BB: "oʻ" LATIN SMALL LETTER O/MODIFIER LETTER TURNED COMMA + .replaceKeyOfLabel(Nordic.ROW1_11, "o\u02BB") + // U+0067/U+02BB: "gʻ" LATIN SMALL LETTER G/MODIFIER LETTER TURNED COMMA + .replaceKeyOfLabel(Nordic.ROW2_10, "g\u02BB") + // U+02BC: "ʼ" MODIFIER LETTER APOSTROPHE + .replaceKeyOfLabel(Nordic.ROW2_11, "\u02BC"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setUzbekKeys(builder); + return super.setAccentedLetters(builder); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java new file mode 100644 index 000000000..0ed74eb25 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.expected; + +import java.util.Arrays; + +/** + * This class builds a keyboard that is a two dimensional array of elements <code>E</code>. + * + * A keyboard consists of an array of rows, and a row consists of an array of elements. Each row + * may have different number of elements. A element of a keyboard can be specified by a row number + * and a column number, both numbers starts from 1. + * + * @param <E> the type of a keyboard element. A keyboard element must be an immutable object. + */ +abstract class AbstractKeyboardBuilder<E> { + // A building array of rows. + private E[][] mRows; + + // Returns an instance of default element. + abstract E defaultElement(); + // Returns an <code>E</code> array instance of the <code>size</code>. + abstract E[] newArray(final int size); + // Returns an <code>E[]</code> array instance of the <code>size</code>. + abstract E[][] newArrayOfArray(final int size); + + /** + * Construct an empty builder. + */ + AbstractKeyboardBuilder() { + mRows = newArrayOfArray(0); + } + + /** + * Construct a builder from template keyboard. This builder has the same dimensions and + * elements of <code>rows</rows>. + * @param rows the template keyboard rows. The elements of the <code>rows</code> will be + * shared with this builder. Therefore a element must be an immutable object. + */ + AbstractKeyboardBuilder(final E[][] rows) { + mRows = newArrayOfArray(rows.length); + for (int rowIndex = 0; rowIndex < rows.length; rowIndex++) { + final E[] row = rows[rowIndex]; + mRows[rowIndex] = Arrays.copyOf(row, row.length); + } + } + + /** + * Return current constructing keyboard. + * @return the array of the array of the element being constructed. + */ + E[][] build() { + return mRows; + } + + /** + * Return the number of rows. + * @return the number of rows being constructed. + */ + int getRowCount() { + return mRows.length; + } + + /** + * Get the current contents of the specified row. + * @param row the row number to get the contents. + * @return the array of elements at row number <code>row</code>. + * @throws RuntimeException if <code>row</code> is illegal. + */ + E[] getRowAt(final int row) { + final int rowIndex = row - 1; + if (rowIndex < 0 || rowIndex >= mRows.length) { + throw new RuntimeException("Illegal row number: " + row); + } + return mRows[rowIndex]; + } + + /** + * Set an array of elements to the specified row. + * @param row the row number to set <code>elements</code>. + * @param elements the array of elements to set at row number <code>row</code>. + * @throws RuntimeException if <code>row</code> is illegal. + */ + void setRowAt(final int row, final E[] elements) { + final int rowIndex = row - 1; + if (rowIndex < 0) { + throw new RuntimeException("Illegal row number: " + row); + } + final E[][] newRows = (rowIndex < mRows.length) ? mRows + : Arrays.copyOf(mRows, rowIndex + 1); + newRows[rowIndex] = elements; + mRows = newRows; + } + + /** + * Set or insert an element at specified position. + * @param row the row number to set or insert the <code>element</code>. + * @param column the column number to set or insert the <code>element</code>. + * @param element the element to set or insert at <code>row,column</code>. + * @param insert if true, the <code>element</code> is inserted at <code>row,column</code>. + * Otherwise the <code>element</code> replace the element at <code>row,column</code>. + * @throws RuntimeException if <code>row</code> or <code>column</code> is illegal. + */ + void setElementAt(final int row, final int column, final E element, final boolean insert) { + final E[] elements = getRowAt(row); + final int columnIndex = column - 1; + if (columnIndex < 0) { + throw new RuntimeException("Illegal column number: " + column); + } + if (insert) { + if (columnIndex >= elements.length + 1) { + throw new RuntimeException("Illegal column number: " + column); + } + final E[] newElements = Arrays.copyOf(elements, elements.length + 1); + // Shift the remaining elements. + System.arraycopy(newElements, columnIndex, newElements, columnIndex + 1, + elements.length - columnIndex); + // Insert the element at <code>row,column</code>. + newElements[columnIndex] = element; + // Replace the current row with one. + setRowAt(row, newElements); + return; + } + final E[] newElements = (columnIndex < elements.length) ? elements + : Arrays.copyOf(elements, columnIndex + 1); + newElements[columnIndex] = element; + setRowAt(row, newElements); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/expected/AbstractLayoutBase.java b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/AbstractLayoutBase.java new file mode 100644 index 000000000..dba595ab5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/AbstractLayoutBase.java @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.expected; + +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey; +import org.kelar.inputmethod.latin.common.Constants; + +/** + * Base class to create an expected keyboard for unit test. + */ +public abstract class AbstractLayoutBase { + // Those helper methods have a lower case name to be readable when defining expected keyboard + // layouts. + + // Helper method to create an {@link ExpectedKey} object that has the label. + public static ExpectedKey key(final String label, final ExpectedKey ... moreKeys) { + return ExpectedKey.newInstance(label, moreKeys); + } + + // Helper method to create an {@link ExpectedKey} object that has the label and the output text. + public static ExpectedKey key(final String label, final String outputText, + final ExpectedKey ... moreKeys) { + return ExpectedKey.newInstance(label, outputText, moreKeys); + } + + // Helper method to create an {@link ExpectedKey} object that has the label and the output code. + public static ExpectedKey key(final String label, final int code, + final ExpectedKey ... moreKeys) { + return ExpectedKey.newInstance(label, code, moreKeys); + } + + // Helper method to create an {@link ExpectedKey} object that has the icon and the output text. + public static ExpectedKey key(final int iconId, final String outputText, + final ExpectedKey ... moreKeys) { + return ExpectedKey.newInstance(iconId, outputText, moreKeys); + } + + // Helper method to create an {@link ExpectedKey} object that has the icon and the output code. + public static ExpectedKey key(final int iconId, final int code, + final ExpectedKey ... moreKeys) { + return ExpectedKey.newInstance(iconId, code, moreKeys); + } + + // Helper method to create an {@link ExpectedKey} object that has new "more keys". + public static ExpectedKey key(final ExpectedKey key, final ExpectedKey ... moreKeys) { + return ExpectedKey.newInstance(key.getVisual(), key.getOutput(), moreKeys); + } + + // Helper method to create an {@link ExpectedAdditionalMoreKey} object for an + // "additional more key" that has the label. + // The additional more keys can be defined independently from other more keys. The position of + // the additional more keys in the long press popup keyboard can be controlled by specifying + // special marker "%" in the usual more keys definitions. + public static ExpectedAdditionalMoreKey additionalMoreKey(final String label) { + return ExpectedAdditionalMoreKey.newInstance(label); + } + + // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label. + public static ExpectedKey moreKey(final String label) { + return ExpectedKey.newInstance(label); + } + + // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label + // and the output text. + public static ExpectedKey moreKey(final String label, final String outputText) { + return ExpectedKey.newInstance(label, outputText); + } + + // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label + // and the output code. + public static ExpectedKey moreKey(final String label, final int code) { + return ExpectedKey.newInstance(label, code); + } + + // Helper method to create an {@link ExpectedKey} object for a "more key" that has the icon + // and the output text. + public static ExpectedKey moreKey(final int iconId, final String outputText) { + return ExpectedKey.newInstance(iconId, outputText); + } + + // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey}, + // {@link ExpectedKey} array, and {@link String}. + public static ExpectedKey[] joinMoreKeys(final Object ... moreKeys) { + return joinKeys(moreKeys); + } + + // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey}, + // {@link ExpectedKey} array, and {@link String}. + public static ExpectedKey[] joinKeys(final Object ... keys) { + return ExpectedKeyboardBuilder.joinKeys(keys); + } + + // Icon ids. + private static final int ICON_DELETE = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_DELETE_KEY); + private static final int ICON_SPACE = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_SPACE_KEY); + private static final int ICON_TAB = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_TAB_KEY); + private static final int ICON_SHORTCUT = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_SHORTCUT_KEY); + private static final int ICON_SETTINGS = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_SETTINGS_KEY); + private static final int ICON_LANGUAGE_SWITCH = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_LANGUAGE_SWITCH_KEY); + private static final int ICON_ENTER = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_ENTER_KEY); + private static final int ICON_EMOJI_ACTION = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_EMOJI_ACTION_KEY); + private static final int ICON_EMOJI_NORMAL = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_EMOJI_NORMAL_KEY); + private static final int ICON_SHIFT = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_SHIFT_KEY); + private static final int ICON_SHIFTED_SHIFT = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_SHIFT_KEY_SHIFTED); + private static final int ICON_ZWNJ = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_ZWNJ_KEY); + private static final int ICON_ZWJ = KeyboardIconsSet.getIconId( + KeyboardIconsSet.NAME_ZWJ_KEY); + + // Functional keys. + protected static final ExpectedKey DELETE_KEY = key(ICON_DELETE, Constants.CODE_DELETE); + protected static final ExpectedKey TAB_KEY = key(ICON_TAB, Constants.CODE_TAB); + protected static final ExpectedKey SHORTCUT_KEY = key(ICON_SHORTCUT, Constants.CODE_SHORTCUT); + protected static final ExpectedKey SETTINGS_KEY = key(ICON_SETTINGS, Constants.CODE_SETTINGS); + protected static final ExpectedKey LANGUAGE_SWITCH_KEY = key( + ICON_LANGUAGE_SWITCH, Constants.CODE_LANGUAGE_SWITCH); + protected static final ExpectedKey ENTER_KEY = key(ICON_ENTER, Constants.CODE_ENTER); + protected static final ExpectedKey EMOJI_ACTION_KEY = key(ICON_EMOJI_ACTION, Constants.CODE_EMOJI); + protected static final ExpectedKey EMOJI_NORMAL_KEY = key(ICON_EMOJI_NORMAL, Constants.CODE_EMOJI); + protected static final ExpectedKey SPACE_KEY = key(ICON_SPACE, Constants.CODE_SPACE); + protected static final ExpectedKey CAPSLOCK_MORE_KEY = key(" ", Constants.CODE_CAPSLOCK); + protected static final ExpectedKey SHIFT_KEY = key(ICON_SHIFT, + Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY); + protected static final ExpectedKey SHIFTED_SHIFT_KEY = key(ICON_SHIFTED_SHIFT, + Constants.CODE_SHIFT, CAPSLOCK_MORE_KEY); + protected static final ExpectedKey ALPHABET_KEY = key("ABC", Constants.CODE_SWITCH_ALPHA_SYMBOL); + protected static final ExpectedKey SYMBOLS_KEY = key("?123", Constants.CODE_SWITCH_ALPHA_SYMBOL); + protected static final ExpectedKey BACK_TO_SYMBOLS_KEY = key("?123", Constants.CODE_SHIFT); + protected static final ExpectedKey SYMBOLS_SHIFT_KEY = key("= \\ <", Constants.CODE_SHIFT); + protected static final ExpectedKey TABLET_SYMBOLS_SHIFT_KEY = key("~ [ <", Constants.CODE_SHIFT); + + // U+00A1: "¡" INVERTED EXCLAMATION MARK + // U+00BF: "¿" INVERTED QUESTION MARK + protected static final ExpectedKey[] EXCLAMATION_AND_QUESTION_MARKS = joinKeys( + key("!", moreKey("\u00A1")), key("?", moreKey("\u00BF"))); + // U+200C: ZERO WIDTH NON-JOINER + // U+200D: ZERO WIDTH JOINER + protected static final ExpectedKey ZWNJ_KEY = key(ICON_ZWNJ, "\u200C"); + protected static final ExpectedKey ZWJ_KEY = key(ICON_ZWJ, "\u200D"); + // Domain key + protected static final ExpectedKey DOMAIN_KEY = + key(".com", joinMoreKeys(".net", ".org", ".gov", ".edu")).preserveCase(); + + // Punctuation more keys for phone form factor. + protected static final ExpectedKey[] PHONE_PUNCTUATION_MORE_KEYS = joinKeys( + ",", "?", "!", "#", ")", "(", "/", ";", + "'", "@", ":", "-", "\"", "+", "%", "&"); + // Punctuation more keys for tablet form factor. + protected static final ExpectedKey[] TABLET_PUNCTUATION_MORE_KEYS = joinKeys( + ",", "'", "#", ")", "(", "/", ";", + "@", ":", "-", "\"", "+", "%", "&"); +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java new file mode 100644 index 000000000..779cc0b6c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.expected; + +import org.kelar.inputmethod.keyboard.Key; +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.keyboard.internal.MoreKeySpec; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.common.StringUtils; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * This class builds an actual keyboard for unit test. + * + * An actual keyboard is an array of rows, and a row consists of an array of {@link Key}s. + * Each row may have different number of {@link Key}s. + */ +public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> { + private static ArrayList<Key> filterOutSpacer(final List<Key> keys) { + final ArrayList<Key> filteredKeys = new ArrayList<>(); + for (final Key key : keys) { + if (key.isSpacer()) { + continue; + } + filteredKeys.add(key); + } + return filteredKeys; + } + + /** + * Create the keyboard that consists of the array of rows of the actual keyboard's keys. + * @param sortedKeys keys list of the actual keyboard that is sorted from top-left to + * bottom-right. + * @return the actual keyboard grouped with rows. + */ + public static Key[][] buildKeyboard(final List<Key> sortedKeys) { + // Filter out spacer to prepare to create rows. + final ArrayList<Key> filteredSortedKeys = filterOutSpacer(sortedKeys); + + // Grouping keys into rows. + final ArrayList<ArrayList<Key>> rows = new ArrayList<>(); + ArrayList<Key> elements = new ArrayList<>(); + int lastY = filteredSortedKeys.get(0).getY(); + for (final Key key : filteredSortedKeys) { + if (lastY != key.getY()) { + // A new row is starting. + lastY = key.getY(); + rows.add(elements); + elements = new ArrayList<>(); + } + elements.add(key); + } + rows.add(elements); // Add the last row. + + // Calculate each dimension of rows and create a builder. + final int[] dimensions = new int[rows.size()]; + for (int rowIndex = 0; rowIndex < dimensions.length; rowIndex++) { + dimensions[rowIndex] = rows.get(rowIndex).size(); + } + final ActualKeyboardBuilder builder = new ActualKeyboardBuilder(); + + for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) { + final int row = rowIndex + 1; + final ArrayList<Key> rowKeys = rows.get(rowIndex); + builder.setRowAt(row, rowKeys.toArray(new Key[rowKeys.size()])); + } + return builder.build(); + } + + @Override + Key defaultElement() { return null; } + + @Override + Key[] newArray(final int size) { return new Key[size]; } + + @Override + Key[][] newArrayOfArray(final int size) { return new Key[size][]; } + + // Helper class to create concise representation from the key specification. + static class MoreKeySpecStringizer extends StringUtils.Stringizer<MoreKeySpec> { + static final MoreKeySpecStringizer STRINGIZER = new MoreKeySpecStringizer(); + + @Override + public String stringize(final MoreKeySpec spec) { + if (spec == null) { + return "null"; + } + return toString(spec.mLabel, spec.mIconId, spec.mOutputText, spec.mCode); + } + + @Nonnull + static String toString(final String label, final int iconId, final String outputText, + final int code) { + final String visual = (iconId != KeyboardIconsSet.ICON_UNDEFINED) + ? KeyboardIconsSet.getIconName(iconId) : label; + final String output; + if (code == Constants.CODE_OUTPUT_TEXT) { + output = outputText; + } else if (code < Constants.CODE_SPACE) { + output = Constants.printableCode(code); + } else { + output = StringUtils.newSingleCodePointString(code); + } + if (visual.equals(output)) { + return visual; + } + return visual + "|" + output; + } + } + + // Helper class to create concise representation from the key. + static class KeyStringizer extends StringUtils.Stringizer<Key> { + static final KeyStringizer STRINGIZER = new KeyStringizer(); + + @Override + public String stringize(@Nullable final Key key) { + if (key == null) { + return "NULL"; + } + if (key.isSpacer()) { + return "SPACER"; + } + final StringBuilder sb = new StringBuilder(); + sb.append(MoreKeySpecStringizer.toString( + key.getLabel(), key.getIconId(), key.getOutputText(), key.getCode())); + final MoreKeySpec[] moreKeys = key.getMoreKeys(); + if (moreKeys == null) { + return sb.toString(); + } + sb.append("^"); + sb.append(MoreKeySpecStringizer.STRINGIZER.join(moreKeys)); + return sb.toString(); + } + } + + /** + * Convert the key to human readable string. + * @param key the key to be converted to string. + * @return the human readable representation of <code>key</code>. + */ + @Nonnull + public static String toString(@Nullable final Key key) { + return KeyStringizer.STRINGIZER.stringize(key); + } + + /** + * Convert the keyboard row to human readable string. + * @param keys the keyboard row to be converted to string. + * @return the human readable representation of <code>keys</code>. + */ + @Nonnull + public static String toString(@Nullable final Key[] keys) { + return KeyStringizer.STRINGIZER.join(keys); + } + + // Helper class to create concise representation from the array of the key. + static class KeyArrayStringizer extends StringUtils.Stringizer<Key[]> { + static final KeyArrayStringizer STRINGIZER = new KeyArrayStringizer(); + + @Override + public String stringize(@Nullable final Key[] keyArray) { + return KeyStringizer.STRINGIZER.join(keyArray); + } + } + + /** + * Convert the keyboard to human readable string. + * @param rows the keyboard to be converted to string. + * @return the human readable representation of <code>rows</code>. + */ + @Nonnull + public static String toString(@Nullable final Key[][] rows) { + return KeyArrayStringizer.STRINGIZER.join(rows, "\n" /* delimiter */); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKey.java b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKey.java new file mode 100644 index 000000000..aeec19dde --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKey.java @@ -0,0 +1,376 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.expected; + +import org.kelar.inputmethod.keyboard.Key; +import org.kelar.inputmethod.keyboard.internal.MoreKeySpec; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; + +/** + * This class represents an expected key. + */ +public class ExpectedKey { + static ExpectedKey EMPTY_KEY = newInstance(""); + + // A key that has a string label and may have "more keys". + static ExpectedKey newInstance(final String label, final ExpectedKey... moreKeys) { + return newInstance(label, label, moreKeys); + } + + // A key that has a string label and a different output text and may have "more keys". + static ExpectedKey newInstance(final String label, final String outputText, + final ExpectedKey... moreKeys) { + return newInstance(ExpectedKeyVisual.newInstance(label), + ExpectedKeyOutput.newInstance(outputText), moreKeys); + } + + // A key that has a string label and a code point output and may have "more keys". + static ExpectedKey newInstance(final String label, final int code, + final ExpectedKey... moreKeys) { + return newInstance(ExpectedKeyVisual.newInstance(label), + ExpectedKeyOutput.newInstance(code), moreKeys); + } + + // A key that has an icon and an output text and may have "more keys". + static ExpectedKey newInstance(final int iconId, final String outputText, + final ExpectedKey... moreKeys) { + return newInstance(ExpectedKeyVisual.newInstance(iconId), + ExpectedKeyOutput.newInstance(outputText), moreKeys); + } + + // A key that has an icon and a code point output and may have "more keys". + static ExpectedKey newInstance(final int iconId, final int code, + final ExpectedKey... moreKeys) { + return newInstance(ExpectedKeyVisual.newInstance(iconId), + ExpectedKeyOutput.newInstance(code), moreKeys); + } + + static ExpectedKey newInstance(final ExpectedKeyVisual visual, final ExpectedKeyOutput output, + final ExpectedKey... moreKeys) { + if (moreKeys.length == 0) { + return new ExpectedKey(visual, output); + } + // The more keys are the extra keys that the main keyboard key may have in its long press + // popup keyboard. + // The additional more keys can be defined independently from other more keys. + // The position of the additional more keys in the long press popup keyboard can be + // controlled by specifying special marker "%" in the usual more keys definitions. + final ArrayList<ExpectedKey> moreKeysList = new ArrayList<>(); + final ArrayList<ExpectedAdditionalMoreKey> additionalMoreKeys = new ArrayList<>(); + int firstAdditionalMoreKeyIndex = -1; + for (int index = 0; index < moreKeys.length; index++) { + final ExpectedKey moreKey = moreKeys[index]; + if (moreKey instanceof ExpectedAdditionalMoreKey) { + additionalMoreKeys.add((ExpectedAdditionalMoreKey) moreKey); + if (firstAdditionalMoreKeyIndex < 0) { + firstAdditionalMoreKeyIndex = index; + } + } else { + moreKeysList.add(moreKey); + } + } + if (additionalMoreKeys.isEmpty()) { + return new ExpectedKeyWithMoreKeys(visual, output, moreKeys); + } + final ExpectedKey[] moreKeysArray = moreKeysList.toArray( + new ExpectedKey[moreKeysList.size()]); + final ExpectedAdditionalMoreKey[] additionalMoreKeysArray = additionalMoreKeys.toArray( + new ExpectedAdditionalMoreKey[additionalMoreKeys.size()]); + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + visual, output, moreKeysArray, firstAdditionalMoreKeyIndex, + additionalMoreKeysArray); + } + + private static final ExpectedKey[] EMPTY_KEYS = new ExpectedKey[0]; + + // The expected visual outlook of this key. + private final ExpectedKeyVisual mVisual; + // The expected output of this key. + private final ExpectedKeyOutput mOutput; + + protected final ExpectedKeyVisual getVisual() { + return mVisual; + } + + protected final ExpectedKeyOutput getOutput() { + return mOutput; + } + + public ExpectedKey[] getMoreKeys() { + // This key has no "more keys". + return EMPTY_KEYS; + } + + public ExpectedKey setMoreKeys(final ExpectedKey... moreKeys) { + return newInstance(mVisual, mOutput, moreKeys); + } + + public ExpectedKey setAdditionalMoreKeys( + final ExpectedAdditionalMoreKey... additionalMoreKeys) { + if (additionalMoreKeys.length == 0) { + return this; + } + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + mVisual, mOutput, EMPTY_KEYS, 0 /* additionalMoreKeysIndex */, additionalMoreKeys); + } + + public ExpectedKey setAdditionalMoreKeysIndex(final int additionalMoreKeysIndex) { + if (additionalMoreKeysIndex == 0) { + return this; + } + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + mVisual, mOutput, EMPTY_KEYS, additionalMoreKeysIndex); + } + + protected ExpectedKey(final ExpectedKeyVisual visual, final ExpectedKeyOutput output) { + mVisual = visual; + mOutput = output; + } + + public ExpectedKey toUpperCase(Locale locale) { + return newInstance(mVisual.toUpperCase(locale), mOutput.toUpperCase(locale)); + } + + public ExpectedKey preserveCase() { + final ExpectedKey[] moreKeys = getMoreKeys(); + final ExpectedKey[] casePreservedMoreKeys = new ExpectedKey[moreKeys.length]; + for (int index = 0; index < moreKeys.length; index++) { + final ExpectedKey moreKey = moreKeys[index]; + casePreservedMoreKeys[index] = newInstance( + moreKey.getVisual().preserveCase(), moreKey.getOutput().preserveCase()); + } + return newInstance( + getVisual().preserveCase(), getOutput().preserveCase(), casePreservedMoreKeys); + } + + public boolean equalsTo(final Key key) { + // This key has no "more keys". + return mVisual.hasSameKeyVisual(key) && mOutput.hasSameKeyOutput(key) + && key.getMoreKeys() == null; + } + + public boolean equalsTo(final MoreKeySpec moreKeySpec) { + return mVisual.hasSameKeyVisual(moreKeySpec) && mOutput.hasSameKeyOutput(moreKeySpec); + } + + @Override + public boolean equals(final Object object) { + if (object instanceof ExpectedKey) { + final ExpectedKey key = (ExpectedKey) object; + return mVisual.hasSameKeyVisual(key.mVisual) && mOutput.hasSameKeyOutput(key.mOutput) + && Arrays.equals(getMoreKeys(), key.getMoreKeys()); + } + return false; + } + + private static int hashCode(final Object... objects) { + return Arrays.hashCode(objects); + } + + @Override + public int hashCode() { + return hashCode(mVisual, mOutput, getMoreKeys()); + } + + @Override + public String toString() { + if (mVisual.hasSameKeyVisual(mOutput)) { + return mVisual.toString(); + } + return mVisual + "|" + mOutput; + } + + /** + * This class represents an expected "additional more key". + * + * The additional more keys can be defined independently from other more keys. The position of + * the additional more keys in the long press popup keyboard can be controlled by specifying + * special marker "%" in the usual more keys definitions. + */ + public static class ExpectedAdditionalMoreKey extends ExpectedKey { + public static ExpectedAdditionalMoreKey newInstance(final String label) { + return new ExpectedAdditionalMoreKey(ExpectedKeyVisual.newInstance(label), + ExpectedKeyOutput.newInstance(label)); + } + + public static ExpectedAdditionalMoreKey newInstance(final ExpectedKey key) { + return new ExpectedAdditionalMoreKey(key.getVisual(), key.getOutput()); + } + + ExpectedAdditionalMoreKey(final ExpectedKeyVisual visual, final ExpectedKeyOutput output) { + super(visual, output); + } + + @Override + public ExpectedAdditionalMoreKey toUpperCase(final Locale locale) { + final ExpectedKey upperCaseKey = super.toUpperCase(locale); + return new ExpectedAdditionalMoreKey( + upperCaseKey.getVisual(), upperCaseKey.getOutput()); + } + } + + /** + * This class represents an expected key that has "more keys". + */ + private static class ExpectedKeyWithMoreKeys extends ExpectedKey { + private final ExpectedKey[] mMoreKeys; + + ExpectedKeyWithMoreKeys(final ExpectedKeyVisual visual, final ExpectedKeyOutput output, + final ExpectedKey... moreKeys) { + super(visual, output); + mMoreKeys = moreKeys; + } + + @Override + public ExpectedKey toUpperCase(final Locale locale) { + final ExpectedKey[] upperCaseMoreKeys = new ExpectedKey[mMoreKeys.length]; + for (int i = 0; i < mMoreKeys.length; i++) { + upperCaseMoreKeys[i] = mMoreKeys[i].toUpperCase(locale); + } + return newInstance(getVisual().toUpperCase(locale), getOutput().toUpperCase(locale), + upperCaseMoreKeys); + } + + @Override + public ExpectedKey[] getMoreKeys() { + return mMoreKeys; + } + + @Override + public ExpectedKey setAdditionalMoreKeys( + final ExpectedAdditionalMoreKey... additionalMoreKeys) { + if (additionalMoreKeys.length == 0) { + return this; + } + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + getVisual(), getOutput(), mMoreKeys, 0 /* additionalMoreKeysIndex */, + additionalMoreKeys); + } + + @Override + public ExpectedKey setAdditionalMoreKeysIndex(final int additionalMoreKeysIndex) { + if (additionalMoreKeysIndex == 0) { + return this; + } + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + getVisual(), getOutput(), mMoreKeys, additionalMoreKeysIndex); + } + + @Override + public boolean equalsTo(final Key key) { + if (getVisual().hasSameKeyVisual(key) && getOutput().hasSameKeyOutput(key)) { + final MoreKeySpec[] moreKeySpecs = key.getMoreKeys(); + final ExpectedKey[] moreKeys = getMoreKeys(); + // This key should have at least one "more key". + if (moreKeySpecs == null || moreKeySpecs.length != moreKeys.length) { + return false; + } + for (int index = 0; index < moreKeySpecs.length; index++) { + if (!moreKeys[index].equalsTo(moreKeySpecs[index])) { + return false; + } + } + return true; + } + return false; + } + + @Override + public boolean equalsTo(final MoreKeySpec moreKeySpec) { + // MoreKeySpec has no "more keys". + return false; + } + + @Override + public String toString() { + return super.toString() + "^" + Arrays.toString(getMoreKeys()); + } + } + + /** + * This class represents an expected key that has "more keys" and "additional more keys". + */ + private static final class ExpectedKeyWithMoreKeysAndAdditionalMoreKeys + extends ExpectedKeyWithMoreKeys { + private final ExpectedAdditionalMoreKey[] mAdditionalMoreKeys; + private final int mAdditionalMoreKeysIndex; + + ExpectedKeyWithMoreKeysAndAdditionalMoreKeys(final ExpectedKeyVisual visual, + final ExpectedKeyOutput output, final ExpectedKey[] moreKeys, + final int additionalMoreKeysIndex, + final ExpectedAdditionalMoreKey... additionalMoreKeys) { + super(visual, output, moreKeys); + mAdditionalMoreKeysIndex = additionalMoreKeysIndex; + mAdditionalMoreKeys = additionalMoreKeys; + } + + @Override + public ExpectedKey setMoreKeys(final ExpectedKey... moreKeys) { + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + getVisual(), getOutput(), moreKeys, mAdditionalMoreKeysIndex, + mAdditionalMoreKeys); + } + + @Override + public ExpectedKey setAdditionalMoreKeys( + final ExpectedAdditionalMoreKey... additionalMoreKeys) { + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + getVisual(), getOutput(), super.getMoreKeys(), mAdditionalMoreKeysIndex, + additionalMoreKeys); + } + + @Override + public ExpectedKey setAdditionalMoreKeysIndex(final int additionalMoreKeysIndex) { + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + getVisual(), getOutput(), super.getMoreKeys(), additionalMoreKeysIndex, + mAdditionalMoreKeys); + } + + @Override + public ExpectedKey toUpperCase(final Locale locale) { + final ExpectedKey[] moreKeys = super.getMoreKeys(); + final ExpectedKey[] upperCaseMoreKeys = new ExpectedKey[moreKeys.length]; + for (int i = 0; i < moreKeys.length; i++) { + upperCaseMoreKeys[i] = moreKeys[i].toUpperCase(locale); + } + final ExpectedAdditionalMoreKey[] upperCaseAdditionalMoreKeys = + new ExpectedAdditionalMoreKey[mAdditionalMoreKeys.length]; + for (int i = 0; i < mAdditionalMoreKeys.length; i++) { + upperCaseAdditionalMoreKeys[i] = mAdditionalMoreKeys[i].toUpperCase(locale); + } + return new ExpectedKeyWithMoreKeysAndAdditionalMoreKeys( + getVisual().toUpperCase(locale), getOutput().toUpperCase(locale), + upperCaseMoreKeys, mAdditionalMoreKeysIndex, upperCaseAdditionalMoreKeys); + } + + @Override + public ExpectedKey[] getMoreKeys() { + final ExpectedKey[] moreKeys = super.getMoreKeys(); + final ExpectedKey[] edittedMoreKeys = Arrays.copyOf( + moreKeys, moreKeys.length + mAdditionalMoreKeys.length); + System.arraycopy(edittedMoreKeys, mAdditionalMoreKeysIndex, + edittedMoreKeys, mAdditionalMoreKeysIndex + mAdditionalMoreKeys.length, + moreKeys.length - mAdditionalMoreKeysIndex); + System.arraycopy(mAdditionalMoreKeys, 0, edittedMoreKeys, mAdditionalMoreKeysIndex, + mAdditionalMoreKeys.length); + return edittedMoreKeys; + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java new file mode 100644 index 000000000..fbfdc7403 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.expected; + +import org.kelar.inputmethod.keyboard.Key; +import org.kelar.inputmethod.keyboard.internal.MoreKeySpec; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.common.StringUtils; + +import java.util.Locale; + +/** + * This class represents an expected output of a key. + * + * There are two types of expected output, an integer code point and a string output text. + */ +abstract class ExpectedKeyOutput { + static ExpectedKeyOutput newInstance(final int code) { + return new Code(code); + } + + static ExpectedKeyOutput newInstance(final String outputText) { + // If the <code>outputText</code> is one code point string, use {@link CodePoint} object. + if (StringUtils.codePointCount(outputText) == 1) { + return new Code(outputText.codePointAt(0)); + } + return new Text(outputText); + } + + abstract ExpectedKeyOutput toUpperCase(final Locale locale); + abstract ExpectedKeyOutput preserveCase(); + abstract boolean hasSameKeyOutput(final String text); + abstract boolean hasSameKeyOutput(final Key key); + abstract boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec); + abstract boolean hasSameKeyOutput(final ExpectedKeyOutput output); + + /** + * This class represents an integer code point. + */ + private static class Code extends ExpectedKeyOutput { + // UNICODE code point or a special negative value defined in {@link Constants}. + private final int mCode; + + Code(final int code) { mCode = code; } + + @Override + ExpectedKeyOutput toUpperCase(final Locale locale) { + if (Constants.isLetterCode(mCode)) { + final String codeString = StringUtils.newSingleCodePointString(mCode); + // A letter may have an upper case counterpart that consists of multiple code + // points, for instance the upper case of "ß" is "SS". + return newInstance(StringUtils.toTitleCaseOfKeyLabel(codeString, locale)); + } + // A special negative value has no upper case. + return this; + } + + @Override + ExpectedKeyOutput preserveCase() { + return new CasePreservedCode(mCode); + } + + @Override + boolean hasSameKeyOutput(final String text) { + return StringUtils.codePointCount(text) == 1 && text.codePointAt(0) == mCode; + } + + @Override + boolean hasSameKeyOutput(final Key key) { + return mCode == key.getCode(); + } + + @Override + boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec) { + return mCode == moreKeySpec.mCode; + } + + @Override + boolean hasSameKeyOutput(final ExpectedKeyOutput output) { + return (output instanceof Code) && mCode == ((Code)output).mCode; + } + + @Override + public String toString() { + return Constants.isLetterCode(mCode) ? StringUtils.newSingleCodePointString(mCode) + : Constants.printableCode(mCode); + } + + private static class CasePreservedCode extends Code { + CasePreservedCode(final int code) { super(code); } + + @Override + ExpectedKeyOutput toUpperCase(final Locale locale) { return this; } + + @Override + ExpectedKeyOutput preserveCase() { return this; } + } + } + + /** + * This class represents a string output text. + */ + private static class Text extends ExpectedKeyOutput { + private final String mText; + + Text(final String text) { mText = text; } + + @Override + ExpectedKeyOutput toUpperCase(final Locale locale) { + return newInstance(mText.toUpperCase(locale)); + } + + @Override + ExpectedKeyOutput preserveCase() { + return new CasePreservedText(mText); + } + + @Override + boolean hasSameKeyOutput(final String text) { + return mText.equals(text); + } + + @Override + boolean hasSameKeyOutput(final Key key) { + return key.getCode() == Constants.CODE_OUTPUT_TEXT + && mText.equals(key.getOutputText()); + } + + @Override + boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec) { + return moreKeySpec.mCode == Constants.CODE_OUTPUT_TEXT + && mText.equals(moreKeySpec.mOutputText); + } + + @Override + boolean hasSameKeyOutput(final ExpectedKeyOutput output) { + return (output instanceof Text) && mText == ((Text)output).mText; + } + + @Override + public String toString() { + return mText; + } + + private static class CasePreservedText extends Text { + CasePreservedText(final String text) { super(text); } + + @Override + ExpectedKeyOutput toUpperCase(final Locale locale) { return this; } + + @Override + ExpectedKeyOutput preserveCase() { return this; } + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java new file mode 100644 index 000000000..bdd939b1e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.expected; + +import org.kelar.inputmethod.keyboard.Key; +import org.kelar.inputmethod.keyboard.internal.KeyboardIconsSet; +import org.kelar.inputmethod.keyboard.internal.MoreKeySpec; +import org.kelar.inputmethod.latin.common.StringUtils; + +import java.util.Locale; + +/** + * This class represents an expected visual outlook of a key. + * + * There are two types of expected visual, an integer icon id and a string label. + */ +public abstract class ExpectedKeyVisual { + public static ExpectedKeyVisual newInstance(final String label) { + return new Label(label); + } + + public static ExpectedKeyVisual newInstance(final int iconId) { + return new Icon(iconId); + } + + public abstract int getIconId(); + public abstract String getLabel(); + abstract ExpectedKeyVisual toUpperCase(final Locale locale); + abstract ExpectedKeyVisual preserveCase(); + abstract boolean hasSameKeyVisual(final String text); + abstract boolean hasSameKeyVisual(final Key key); + abstract boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec); + abstract boolean hasSameKeyVisual(final ExpectedKeyOutput output); + abstract boolean hasSameKeyVisual(final ExpectedKeyVisual visual); + + /** + * This class represents an integer icon id. + */ + private static class Icon extends ExpectedKeyVisual { + private final int mIconId; + + Icon(final int iconId) { + mIconId = iconId; + } + + @Override + public int getIconId() { + return mIconId; + } + + @Override + public String getLabel() { + return null; + } + + @Override + ExpectedKeyVisual toUpperCase(final Locale locale) { + return this; + } + + @Override + ExpectedKeyVisual preserveCase() { + return this; + } + + @Override + boolean hasSameKeyVisual(final String text) { + return false; + } + + @Override + boolean hasSameKeyVisual(final Key key) { + // If the actual key has an icon as its visual, a label has to be null. + // See {@link KeyboardView#onDrawKeyTopVisuals(Key,Canvas,Paint,KeyDrawParams). + return mIconId == key.getIconId() && key.getLabel() == null; + } + + @Override + boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec) { + // If the actual more key has an icon as its visual, a label has to be null. + // See {@link KeySpecParser#getIconId(String)} and + // {@link KeySpecParser#getLabel(String)}. + return mIconId == moreKeySpec.mIconId && moreKeySpec.mLabel == null; + } + + @Override + boolean hasSameKeyVisual(final ExpectedKeyOutput output) { + return false; + } + + @Override + boolean hasSameKeyVisual(final ExpectedKeyVisual visual) { + return (visual instanceof Icon) && mIconId == ((Icon)visual).mIconId; + } + + @Override + public String toString() { + return KeyboardIconsSet.getIconName(mIconId); + } + } + + /** + * This class represents a string label. + */ + private static class Label extends ExpectedKeyVisual { + private final String mLabel; + + Label(final String label) { + mLabel = label; + } + + @Override + public int getIconId() { + return KeyboardIconsSet.ICON_UNDEFINED; + } + + @Override + public String getLabel() { + return mLabel; + } + + @Override + ExpectedKeyVisual toUpperCase(final Locale locale) { + return new Label(StringUtils.toTitleCaseOfKeyLabel(mLabel, locale)); + } + + @Override + ExpectedKeyVisual preserveCase() { + return new CasePreservedLabel(mLabel); + } + + @Override + boolean hasSameKeyVisual(final String text) { + return mLabel.equals(text); + } + + @Override + boolean hasSameKeyVisual(final Key key) { + // If the actual key has a label as its visual, an icon has to be undefined. + // See {@link KeyboardView#onDrawKeyTopVisuals(Key,Canvas,Paint,KeyDrawParams). + return mLabel.equals(key.getLabel()) + && key.getIconId() == KeyboardIconsSet.ICON_UNDEFINED; + } + + @Override + boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec) { + // If the actual more key has a label as its visual, an icon has to be undefined. + // See {@link KeySpecParser#getIconId(String)} and + // {@link KeySpecParser#getLabel(String)}. + return mLabel.equals(moreKeySpec.mLabel) + && moreKeySpec.mIconId == KeyboardIconsSet.ICON_UNDEFINED; + } + + @Override + boolean hasSameKeyVisual(final ExpectedKeyOutput output) { + return output.hasSameKeyOutput(mLabel); + } + + @Override + boolean hasSameKeyVisual(final ExpectedKeyVisual visual) { + return (visual instanceof Label) && mLabel.equals(((Label)visual).mLabel); + } + + @Override + public String toString() { + return mLabel; + } + + private static class CasePreservedLabel extends Label { + CasePreservedLabel(final String label) { super(label); } + + @Override + ExpectedKeyVisual toUpperCase(final Locale locale) { return this; } + + @Override + ExpectedKeyVisual preserveCase() { return this; } + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java new file mode 100644 index 000000000..9da1ac4df --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.expected; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; + +/** + * This class builds an expected keyboard for unit test. + * + * An expected keyboard is an array of rows, and a row consists of an array of {@link ExpectedKey}s. + * Each row may have different number of {@link ExpectedKey}s. While building an expected keyboard, + * an {@link ExpectedKey} can be specified by a row number and a column number, both numbers starts + * from 1. + */ +public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<ExpectedKey> { + public ExpectedKeyboardBuilder() { + super(); + } + + public ExpectedKeyboardBuilder(final ExpectedKey[][] rows) { + super(rows); + } + + @Override + protected ExpectedKey defaultElement() { + return ExpectedKey.EMPTY_KEY; + } + + @Override + ExpectedKey[] newArray(final int size) { + return new ExpectedKey[size]; + } + + @Override + ExpectedKey[][] newArrayOfArray(final int size) { + return new ExpectedKey[size][]; + } + + @Override + public ExpectedKey[][] build() { + return super.build(); + } + + // A replacement job to be performed. + private interface ReplaceJob { + // Returns a {@link ExpectedKey} objects to replace. + ExpectedKey[] replacingKeys(final ExpectedKey oldKey); + // Return true if replacing should be stopped at first occurrence. + boolean stopAtFirstOccurrence(); + } + + private static ExpectedKey[] replaceKeyAt(final ExpectedKey[] keys, final int columnIndex, + final ExpectedKey[] replacingKeys) { + // Optimization for replacing a key with another key. + if (replacingKeys.length == 1) { + keys[columnIndex] = replacingKeys[0]; + return keys; + } + final int newLength = keys.length - 1 + replacingKeys.length; + // Remove the key at columnIndex. + final ExpectedKey[] newKeys = Arrays.copyOf(keys, newLength); + System.arraycopy(keys, columnIndex + 1, newKeys, columnIndex + replacingKeys.length, + keys.length - 1 - columnIndex); + // Insert replacing keys at columnIndex. + System.arraycopy(replacingKeys, 0, newKeys, columnIndex, replacingKeys.length); + return newKeys; + + } + + // Replace key(s) that has the specified visual. + private void replaceKeyOf(final ExpectedKeyVisual visual, final ReplaceJob job) { + int replacedCount = 0; + final int rowCount = getRowCount(); + for (int row = 1; row <= rowCount; row++) { + ExpectedKey[] keys = getRowAt(row); + for (int columnIndex = 0; columnIndex < keys.length; /* nothing */) { + final ExpectedKey currentKey = keys[columnIndex]; + if (!currentKey.getVisual().hasSameKeyVisual(visual)) { + columnIndex++; + continue; + } + final ExpectedKey[] replacingKeys = job.replacingKeys(currentKey); + keys = replaceKeyAt(keys, columnIndex, replacingKeys); + columnIndex += replacingKeys.length; + setRowAt(row, keys); + replacedCount++; + if (job.stopAtFirstOccurrence()) { + return; + } + } + } + if (replacedCount == 0) { + throw new RuntimeException( + "Can't find key that has visual: " + visual + " in\n" + this); + } + } + + // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey}, + // {@link ExpectedKey} array, and {@link String}. + static ExpectedKey[] joinKeys(final Object ... keys) { + final ArrayList<ExpectedKey> list = new ArrayList<>(); + for (final Object key : keys) { + if (key instanceof ExpectedKey) { + list.add((ExpectedKey)key); + } else if (key instanceof ExpectedKey[]) { + list.addAll(Arrays.asList((ExpectedKey[])key)); + } else if (key instanceof String) { + list.add(ExpectedKey.newInstance((String)key)); + } else { + throw new RuntimeException("Unknown expected key type: " + key); + } + } + return list.toArray(new ExpectedKey[list.size()]); + } + + /** + * Set the row with specified keys. + * @param row the row number to set keys. + * @param keys the keys to be set at <code>row</code>. Each key can be {@link ExpectedKey}, + * {@link ExpectedKey} array, and {@link String}. + * @return this builder. + */ + public ExpectedKeyboardBuilder setKeysOfRow(final int row, final Object ... keys) { + setRowAt(row, joinKeys(keys)); + return this; + } + + /** + * Set the "more keys" of the key that has the specified label. + * @param label the label of the key to set the "more keys". + * @param moreKeys the array of "more key" to be set. Each "more key" can be + * {@link ExpectedKey}, {@link ExpectedKey} array, and {@link String}. + * @return this builder. + */ + public ExpectedKeyboardBuilder setMoreKeysOf(final String label, final Object ... moreKeys) { + setMoreKeysOf(ExpectedKeyVisual.newInstance(label), joinKeys(moreKeys)); + return this; + } + + /** + * Set the "more keys" of the key that has the specified icon. + * @param iconId the icon id of the key to set the "more keys". + * @param moreKeys the array of "more key" to be set. Each "more key" can be + * {@link ExpectedKey}, {@link ExpectedKey} array, and {@link String}. + * @return this builder. + */ + public ExpectedKeyboardBuilder setMoreKeysOf(final int iconId, final Object ... moreKeys) { + setMoreKeysOf(ExpectedKeyVisual.newInstance(iconId), joinKeys(moreKeys)); + return this; + } + + private void setMoreKeysOf(final ExpectedKeyVisual visual, final ExpectedKey[] moreKeys) { + replaceKeyOf(visual, new ReplaceJob() { + @Override + public ExpectedKey[] replacingKeys(final ExpectedKey oldKey) { + return new ExpectedKey[] { oldKey.setMoreKeys(moreKeys) }; + } + @Override + public boolean stopAtFirstOccurrence() { + return true; + } + }); + } + + /** + * Set the "additional more keys position" of the key that has the specified label. + * @param label the label of the key to set the "additional more keys". + * @param additionalMoreKeysPosition the position in the "more keys" where + * "additional more keys" will be merged. The position starts from 1. + * @return this builder. + */ + public ExpectedKeyboardBuilder setAdditionalMoreKeysPositionOf(final String label, + final int additionalMoreKeysPosition) { + final int additionalMoreKeysIndex = additionalMoreKeysPosition - 1; + if (additionalMoreKeysIndex < 0) { + throw new RuntimeException("Illegal additional more keys position: " + + additionalMoreKeysPosition); + } + final ExpectedKeyVisual visual = ExpectedKeyVisual.newInstance(label); + replaceKeyOf(visual, new ReplaceJob() { + @Override + public ExpectedKey[] replacingKeys(final ExpectedKey oldKey) { + return new ExpectedKey[] { + oldKey.setAdditionalMoreKeysIndex(additionalMoreKeysIndex) + }; + } + @Override + public boolean stopAtFirstOccurrence() { + return true; + } + }); + return this; + } + + /** + * Insert the keys at specified position. + * @param row the row number to insert the <code>keys</code>. + * @param column the column number to insert the <code>keys</code>. + * @param keys the array of keys to insert at <code>row,column</code>. Each key can be + * {@link ExpectedKey}, {@link ExpectedKey} array, and {@link String}. + * @return this builder. + * @throws RuntimeException if <code>row</code> or <code>column</code> is illegal. + */ + public ExpectedKeyboardBuilder insertKeysAtRow(final int row, final int column, + final Object ... keys) { + final ExpectedKey[] expectedKeys = joinKeys(keys); + for (int index = 0; index < keys.length; index++) { + setElementAt(row, column + index, expectedKeys[index], true /* insert */); + } + return this; + } + + /** + * Add the keys on the left most of the row. + * @param row the row number to add the <code>keys</code>. + * @param keys the array of keys to add on the left most of the row. Each key can be + * {@link ExpectedKey}, {@link ExpectedKey} array, and {@link String}. + * @return this builder. + * @throws RuntimeException if <code>row</code> is illegal. + */ + public ExpectedKeyboardBuilder addKeysOnTheLeftOfRow(final int row, + final Object ... keys) { + final ExpectedKey[] expectedKeys = joinKeys(keys); + // Keys should be inserted from the last to preserve the order. + for (int index = keys.length - 1; index >= 0; index--) { + setElementAt(row, 1, expectedKeys[index], true /* insert */); + } + return this; + } + + /** + * Add the keys on the right most of the row. + * @param row the row number to add the <code>keys</code>. + * @param keys the array of keys to add on the right most of the row. Each key can be + * {@link ExpectedKey}, {@link ExpectedKey} array, and {@link String}. + * @return this builder. + * @throws RuntimeException if <code>row</code> is illegal. + */ + public ExpectedKeyboardBuilder addKeysOnTheRightOfRow(final int row, + final Object ... keys) { + final int rightEnd = getRowAt(row).length + 1; + insertKeysAtRow(row, rightEnd, keys); + return this; + } + + /** + * Replace the most top-left key that has the specified label with the new keys. + * @param label the label of the key to set <code>newKeys</code>. + * @param newKeys the keys to be set. Each key can be {@link ExpectedKey}, {@link ExpectedKey} + * array, and {@link String}. + * @return this builder. + */ + public ExpectedKeyboardBuilder replaceKeyOfLabel(final String label, + final Object ... newKeys) { + final ExpectedKeyVisual visual = ExpectedKeyVisual.newInstance(label); + replaceKeyOf(visual, new ReplaceJob() { + @Override + public ExpectedKey[] replacingKeys(final ExpectedKey oldKey) { + return joinKeys(newKeys); + } + @Override + public boolean stopAtFirstOccurrence() { + return true; + } + }); + return this; + } + + /** + * Replace the all specified keys with the new keys. + * @param key the key to be replaced by <code>newKeys</code>. + * @param newKeys the keys to be set. Each key can be {@link ExpectedKey}, {@link ExpectedKey} + * array, and {@link String}. + * @return this builder. + */ + public ExpectedKeyboardBuilder replaceKeysOfAll(final ExpectedKey key, + final Object ... newKeys) { + replaceKeyOf(key.getVisual(), new ReplaceJob() { + @Override + public ExpectedKey[] replacingKeys(final ExpectedKey oldKey) { + return joinKeys(newKeys); + } + @Override + public boolean stopAtFirstOccurrence() { + return false; + } + }); + return this; + } + + /** + * Convert all keys of this keyboard builder to upper case keys. + * @param locale the locale used to convert cases. + * @return this builder + */ + public ExpectedKeyboardBuilder toUpperCase(final Locale locale) { + final int rowCount = getRowCount(); + for (int row = 1; row <= rowCount; row++) { + final ExpectedKey[] lowerCaseKeys = getRowAt(row); + final ExpectedKey[] upperCaseKeys = new ExpectedKey[lowerCaseKeys.length]; + for (int columnIndex = 0; columnIndex < lowerCaseKeys.length; columnIndex++) { + upperCaseKeys[columnIndex] = lowerCaseKeys[columnIndex].toUpperCase(locale); + } + setRowAt(row, upperCaseKeys); + } + return this; + } + + @Override + public String toString() { + return toString(build()); + } + + /** + * Convert the keyboard to human readable string. + * @param rows the keyboard to be converted to string. + * @return the human readable representation of <code>rows</code>. + */ + public static String toString(final ExpectedKey[][] rows) { + final StringBuilder sb = new StringBuilder(); + for (int rowIndex = 0; rowIndex < rows.length; rowIndex++) { + if (rowIndex > 0) { + sb.append("\n"); + } + sb.append(Arrays.toString(rows[rowIndex])); + } + return sb.toString(); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/KeyboardLayoutSetSubtypesCountTests.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/KeyboardLayoutSetSubtypesCountTests.java new file mode 100644 index 000000000..c2fc8dff2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/KeyboardLayoutSetSubtypesCountTests.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.KeyboardLayoutSetTestsBase; +import org.kelar.inputmethod.keyboard.KeyboardTheme; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.ArrayList; + +@SmallTest +public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsBase { + private static final int NUMBER_OF_SUBTYPES = 81; + private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 49; + private static final int NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES = 2; + + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } + + private static String toString(final ArrayList<InputMethodSubtype> subtypeList) { + final StringBuilder sb = new StringBuilder(); + for (int index = 0; index < subtypeList.size(); index++) { + final InputMethodSubtype subtype = subtypeList.get(index); + sb.append(index + ": "); + sb.append(SubtypeLocaleUtils.getSubtypeNameForLogging(subtype)); + sb.append("\n"); + } + return sb.toString(); + } + + public final void testAllSubtypesCount() { + final ArrayList<InputMethodSubtype> allSubtypesList = getAllSubtypesList(); + assertEquals(toString(allSubtypesList), NUMBER_OF_SUBTYPES, allSubtypesList.size()); + } + + public final void testAsciiCapableSubtypesCount() { + final ArrayList<InputMethodSubtype> asciiCapableSubtypesList = + getSubtypesFilteredBy(FILTER_IS_ASCII_CAPABLE); + assertEquals(toString(asciiCapableSubtypesList), + NUMBER_OF_ASCII_CAPABLE_SUBTYPES, asciiCapableSubtypesList.size()); + } + + public final void testAdditionalSubtypesCount() { + final ArrayList<InputMethodSubtype> additionalSubtypesList = + getSubtypesFilteredBy(FILTER_IS_ADDITIONAL_SUBTYPE); + assertEquals(toString(additionalSubtypesList), + NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES, additionalSubtypesList.size()); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/LayoutTestsBase.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/LayoutTestsBase.java new file mode 100644 index 000000000..2e8f4d3e8 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/LayoutTestsBase.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import android.util.Log; +import android.view.inputmethod.InputMethodSubtype; + +import org.kelar.inputmethod.keyboard.Key; +import org.kelar.inputmethod.keyboard.Keyboard; +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.KeyboardLayoutSetTestsBase; +import org.kelar.inputmethod.keyboard.KeyboardTheme; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.expected.AbstractLayoutBase; +import org.kelar.inputmethod.keyboard.layout.expected.ActualKeyboardBuilder; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Arrays; + +/** + * Base class for keyboard layout unit test. + */ +abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase { + private LayoutBase mLayout; + private InputMethodSubtype mSubtype; + private String mLogTag; + private KeyboardLayoutSet mKeyboardLayoutSet; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mLayout = getLayout(); + mSubtype = getSubtype(mLayout.getLocale(), mLayout.getName()); + mLogTag = SubtypeLocaleUtils.getSubtypeNameForLogging(mSubtype) + "/" + + (isPhone() ? "phone" : "tablet"); + // TODO: Test with language switch key enabled and disabled. + mKeyboardLayoutSet = createKeyboardLayoutSet(mSubtype, null /* editorInfo */, + true /* voiceInputKeyEnabled */, true /* languageSwitchKeyEnabled */, + false /* splitLayoutEnabled */); + } + + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } + + // Those helper methods have a lower case name to be readable when defining expected keyboard + // layouts. + + // Helper method to create an {@link ExpectedKey} object that has the label. + static ExpectedKey key(final String label, final ExpectedKey ... moreKeys) { + return AbstractLayoutBase.key(label, moreKeys); + } + + // Helper method to create an {@link ExpectedKey} object that has the label and the output text. + static ExpectedKey key(final String label, final String outputText, + final ExpectedKey ... moreKeys) { + return AbstractLayoutBase.key(label, outputText, moreKeys); + } + + // Helper method to create an {@link ExpectedKey} object that has new "more keys". + static ExpectedKey key(final ExpectedKey key, final ExpectedKey ... moreKeys) { + return AbstractLayoutBase.key(key, moreKeys); + } + + // Helper method to create an {@link ExpectedAdditionalMoreKey} object for an + // "additional more key" that has the label. + public static ExpectedAdditionalMoreKey additionalMoreKey(final String label) { + return AbstractLayoutBase.additionalMoreKey(label); + } + + // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label. + static ExpectedKey moreKey(final String label) { + return AbstractLayoutBase.moreKey(label); + } + + // Helper method to create an {@link ExpectedKey} object for a "more key" that has the label + // and the output text. + static ExpectedKey moreKey(final String label, final String outputText) { + return AbstractLayoutBase.moreKey(label, outputText); + } + + // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey}, + // {@link ExpectedKey} array, and {@link String}. + static ExpectedKey[] joinMoreKeys(final Object ... moreKeys) { + return AbstractLayoutBase.joinKeys(moreKeys); + } + + // Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey}, + // {@link ExpectedKey} array, and {@link String}. + static ExpectedKey[] joinKeys(final Object ... keys) { + return AbstractLayoutBase.joinKeys(keys); + } + + // Keyboard layout for testing subtype. + abstract LayoutBase getLayout(); + + ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder; + } + + // TODO: Add phone, phone symbols, number, number password layout tests. + + public final void testLayouts() { + doKeyboardTests(KeyboardId.ELEMENT_ALPHABET); + doKeyboardTests(KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED); + doKeyboardTests(KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED); + doKeyboardTests(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED); + doKeyboardTests(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED); + doKeyboardTests(KeyboardId.ELEMENT_SYMBOLS); + doKeyboardTests(KeyboardId.ELEMENT_SYMBOLS_SHIFTED); + } + + // Comparing expected keyboard and actual keyboard. + private void doKeyboardTests(final int elementId) { + final ExpectedKey[][] expectedKeyboard = mLayout.getLayout(isPhone(), elementId); + // Skip test if no keyboard is defined. + if (expectedKeyboard == null) { + return; + } + final String tag = mLogTag + "/" + KeyboardId.elementIdToName(elementId); + // Create actual keyboard object. + final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(elementId); + // Create actual keyboard to be compared with the expected keyboard. + final Key[][] actualKeyboard = ActualKeyboardBuilder.buildKeyboard( + keyboard.getSortedKeys()); + + // Dump human readable definition of expected/actual keyboards. + Log.d(tag, "expected=\n" + ExpectedKeyboardBuilder.toString(expectedKeyboard)); + Log.d(tag, "actual =\n" + ActualKeyboardBuilder.toString(actualKeyboard)); + // Test both keyboards have the same number of rows. + assertEquals(tag + " labels" + + "\nexpected=" + ExpectedKeyboardBuilder.toString(expectedKeyboard) + + "\nactual =" + ActualKeyboardBuilder.toString(actualKeyboard), + expectedKeyboard.length, actualKeyboard.length); + for (int r = 0; r < actualKeyboard.length; r++) { + final int row = r + 1; + // Test both keyboards' rows have the same number of columns. + assertEquals(tag + " labels row=" + row + + "\nexpected=" + Arrays.toString(expectedKeyboard[r]) + + "\nactual =" + ActualKeyboardBuilder.toString(actualKeyboard[r]), + expectedKeyboard[r].length, actualKeyboard[r].length); + for (int c = 0; c < actualKeyboard[r].length; c++) { + final int column = c + 1; + final Key actualKey = actualKeyboard[r][c]; + final ExpectedKey expectedKey = expectedKeyboard[r][c]; + // Test both keyboards' keys have the same visual outlook and key output. + assertTrue(tag + " labels row,column=" + row + "," + column + + "\nexpected=" + expectedKey + + "\nactual =" + ActualKeyboardBuilder.toString(actualKey), + expectedKey.equalsTo(actualKey)); + } + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsAfrikaans.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsAfrikaans.java new file mode 100644 index 000000000..8bc2b3dcc --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsAfrikaans.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * af: TestsAfrikaans/qwerty + */ +@SmallTest +public final class TestsAfrikaans extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("af"); + private static final LayoutBase LAYOUT = new Qwerty(new AfrikaansCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class AfrikaansCustomizer extends LayoutCustomizer { + AfrikaansCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", "\u0113") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FB", "\u00FC", "\u00F9", "\u016B") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+0133: "ij" LATIN SMALL LIGATURE IJ + .setMoreKeysOf("y", "\u00FD", "\u0133") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+0133: "ij" LATIN SMALL LIGATURE IJ + .setMoreKeysOf("i", + "\u00ED", "\u00EC", "\u00EF", "\u00EE", "\u012F", "\u012B", "\u0133") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F3", "\u00F4", "\u00F6", "\u00F2", "\u00F5", "\u0153", "\u00F8", + "\u014D") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E1", "\u00E2", "\u00E4", "\u00E0", "\u00E6", "\u00E3", "\u00E5", + "\u0101") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsArabic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsArabic.java new file mode 100644 index 000000000..ae489eca3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsArabic.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Arabic; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * ar: Arabic/arabic + */ +@SmallTest +public class TestsArabic extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ar"); + private static final LayoutBase LAYOUT = new Arabic(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsArmenianAMPhonetic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsArmenianAMPhonetic.java new file mode 100644 index 000000000..bc5b6bfa1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsArmenianAMPhonetic.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.ArmenianPhonetic; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * hy_AM: Armenian (Armenia) Phonetic/armenian_phonetic + */ +@SmallTest +public final class TestsArmenianAMPhonetic extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("hy", "AM"); + private static final LayoutBase LAYOUT = new ArmenianPhonetic(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsAzerbaijaniAZ.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsAzerbaijaniAZ.java new file mode 100644 index 000000000..dabf419bb --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsAzerbaijaniAZ.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.TurkicCustomizer; + +import java.util.Locale; + +/** + * az_AZ: Azerbaijani (Azerbaijan)/qwerty + */ +@SmallTest +public final class TestsAzerbaijaniAZ extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("az", "AZ"); + private static final LayoutBase LAYOUT = new Qwerty(new TurkicCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBasqueES.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBasqueES.java new file mode 100644 index 000000000..8ca34122e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBasqueES.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.SpanishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * eu_ES: Basque (Spain)/spanish + */ +@SmallTest +public class TestsBasqueES extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("eu", "ES"); + private static final LayoutBase LAYOUT = new Spanish(new BasqueESCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class BasqueESCustomizer extends EuroCustomizer { + private final SpanishCustomizer mSpanishCustomizer; + + BasqueESCustomizer(final Locale locale) { + super(locale); + mSpanishCustomizer = new SpanishCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mSpanishCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBelarusianBY.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBelarusianBY.java new file mode 100644 index 000000000..cc7f31994 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBelarusianBY.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.EastSlavic; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * be_BY: Belarusian (Belarus)/east_slavic + */ +@SmallTest +public final class TestsBelarusianBY extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("be", "BY"); + private static final LayoutBase LAYOUT = new EastSlavic(new BelarusianBYCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class BelarusianBYCustomizer extends EastSlavicCustomizer { + BelarusianBYCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { + return Symbols.DOUBLE_QUOTES_R9L; + } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { + return Symbols.SINGLE_QUOTES_R9L; + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0435: "е" CYRILLIC SMALL LETTER IE + // U+0451: "ё" CYRILLIC SMALL LETTER IO + .setMoreKeysOf("\u0435", "\u0451") + // U+045E: "ў" CYRILLIC SMALL LETTER SHORT U + .replaceKeyOfLabel(EastSlavic.ROW1_9, key("\u045E", additionalMoreKey("9"))) + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + .replaceKeyOfLabel(EastSlavic.ROW2_2, "\u044B") + // U+044D: "э" CYRILLIC SMALL LETTER E + .replaceKeyOfLabel(EastSlavic.ROW2_11, "\u044D") + // U+0456: "і" CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I + .replaceKeyOfLabel(EastSlavic.ROW3_5, "\u0456") + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + .setMoreKeysOf("\u044C", "\u044A"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBengaliBD.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBengaliBD.java new file mode 100644 index 000000000..af63d113a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBengaliBD.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.BengaliAkkhor; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.BengaliCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * bn_BD: Bengali (Bangladesh)/bengali_akkhor + */ +@SmallTest +public final class TestsBengaliBD extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("bn", "BD"); + private static final LayoutBase LAYOUT = new BengaliAkkhor(new BengaliBDCustomzier(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class BengaliBDCustomzier extends BengaliCustomizer { + BengaliBDCustomzier(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : EXCLAMATION_AND_QUESTION_MARKS; + } + + @Override + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY, key(ZWNJ_KEY, ZWJ_KEY)); + } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + // U+09F3: "৳" BENGALI RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u09F3", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBengaliIN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBengaliIN.java new file mode 100644 index 000000000..8a4570e01 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBengaliIN.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Bengali; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.BengaliCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * bn_IN: Bengali (India)/bengali + */ +@SmallTest +public final class TestsBengaliIN extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("bn", "IN"); + private static final LayoutBase LAYOUT = new Bengali(new BengaliINCustomzier(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class BengaliINCustomzier extends BengaliCustomizer { + BengaliINCustomzier(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { return EMPTY_KEYS; } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBulgarian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBulgarian.java new file mode 100644 index 000000000..9ce1906d1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBulgarian.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Bulgarian; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * bg: TestsBulgarian/bulgarian + */ +@SmallTest +public final class TestsBulgarian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("bg"); + private static final LayoutBase LAYOUT = new Bulgarian(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBulgarianBds.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBulgarianBds.java new file mode 100644 index 000000000..651b5414c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsBulgarianBds.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.BulgarianBds; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * bg: Bulgarian/bulgarian_bds + */ +@SmallTest +public final class TestsBulgarianBds extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("bg"); + private static final LayoutBase LAYOUT = new BulgarianBds(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCatalan.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCatalan.java new file mode 100644 index 000000000..57515cb74 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCatalan.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * ca: Catalan/spanish + */ +@SmallTest +public class TestsCatalan extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ca"); + private static final LayoutBase LAYOUT = new Spanish(new CatalanCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class CatalanCustomizer extends EuroCustomizer { + CatalanCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return isPhone ? CATALAN_PHONE_PUNCTUATION_MORE_KEYS + : CATALAN_TABLET_PUNCTUATION_MORE_KEYS; + } + + // U+00B7: "·" MIDDLE DOT + private static final ExpectedKey[] CATALAN_PHONE_PUNCTUATION_MORE_KEYS = joinKeys( + ",", "?", "!", "\u00B7", "#", ")", "(", "/", ";", + "'", "@", ":", "-", "\"", "+", "%", "&"); + + private static final ExpectedKey[] CATALAN_TABLET_PUNCTUATION_MORE_KEYS = joinKeys( + ",", "'", "\u00B7", "#", ")", "(", "/", ";", + "@", ":", "-", "\"", "+", "%", "&"); + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E8", "\u00E9", "\u00EB", "\u00EA", "\u0119", "\u0117", "\u0113") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00F9", "\u00FB", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00ED", "\u00EF", "\u00EC", "\u00EE", "\u012F", "\u012B") + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + .setMoreKeysOf("o", + "\u00F2", "\u00F3", "\u00F6", "\u00F4", "\u00F5", "\u00F8", "\u0153", + "\u014D", "\u00BA") + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + .setMoreKeysOf("a", + "\u00E0", "\u00E1", "\u00E4", "\u00E2", "\u00E3", "\u00E5", "\u0105", + "\u00E6", "\u0101", "\u00AA") + // U+00B7: "·" MIDDLE DOT + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "l\u00B7l", "\u0142") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + .replaceKeyOfLabel(Spanish.ROW2_10, "\u00E7") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCroatian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCroatian.java new file mode 100644 index 000000000..ca96dc892 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCroatian.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwertz; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * hr: Croatian/qwertz + */ +@SmallTest +public final class TestsCroatian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("hr"); + private static final LayoutBase LAYOUT = new Qwertz(new CroatianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class CroatianCustomizer extends LayoutCustomizer { + CroatianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + .setMoreKeysOf("z", "\u017E", "\u017A", "\u017C") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + .setMoreKeysOf("s", "\u0161", "\u015B", "\u00DF") + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .setMoreKeysOf("d", "\u0111") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + .setMoreKeysOf("c", "\u010D", "\u0107", "\u00E7") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCzech.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCzech.java new file mode 100644 index 000000000..2b7a5253a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsCzech.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwertz; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * cs: Czech/qwertz + */ +@SmallTest +public final class TestsCzech extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("cs"); + private static final LayoutBase LAYOUT = new Qwertz(new CzechCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class CzechCustomizer extends LayoutCustomizer { + CzechCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u011B", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", + "\u0113") + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + .setMoreKeysOf("r", "\u0159") + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + .setMoreKeysOf("t", "\u0165") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + .setMoreKeysOf("z", "\u017E", "\u017A", "\u017C") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u016F", "\u00FB", "\u00FC", "\u00F9", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00ED", "\u00EE", "\u00EF", "\u00EC", "\u012F", "\u012B") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F3", "\u00F6", "\u00F4", "\u00F2", "\u00F5", "\u0153", "\u00F8", + "\u014D") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E1", "\u00E0", "\u00E2", "\u00E4", "\u00E6", "\u00E3", "\u00E5", + "\u0101") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B") + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u010F") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u00E7", "\u0107") + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u0148", "\u00F1", "\u0144"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDanish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDanish.java new file mode 100644 index 000000000..ca18e31f4 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDanish.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.customizer.DanishCustomizer; + +import java.util.Locale; + +/** + * da: Danish/nordic + */ +@SmallTest +public final class TestsDanish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("da"); + private static final LayoutBase LAYOUT = new Nordic(new DanishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDanishQwertz.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDanishQwertz.java new file mode 100644 index 000000000..019f5dc89 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDanishQwertz.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwertz; +import org.kelar.inputmethod.keyboard.layout.customizer.DanishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * da: Danish/qwertz + */ +@SmallTest +public final class TestsDanishQwertz extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("da"); + private static final LayoutBase LAYOUT = new Qwertz(new DanishQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class DanishQwertyCustomizer extends DanishCustomizer { + DanishQwertyCustomizer(final Locale locale) { super(locale); } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // QWERTZ layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E5", "\u00E6", "\u00E1", "\u00E4", "\u00E0", "\u00E2", + "\u00E3", "\u0101"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u00F6", "\u00F3", "\u00F4", "\u00F2", "\u00F5", + "\u0153", "\u014D"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDutch.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDutch.java new file mode 100644 index 000000000..281cb1858 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDutch.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.DutchCustomizer; + +import java.util.Locale; + +/** + * nl: Dutch/qwerty + */ +@SmallTest +public final class TestsDutch extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("nl"); + private static final LayoutBase LAYOUT = new Qwerty(new DutchCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDutchBE.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDutchBE.java new file mode 100644 index 000000000..9e66d6884 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDutchBE.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Azerty; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.DutchCustomizer; + +import java.util.Locale; + +/** + * nl_BE: Dutch (Belgium)/azerty + */ +@SmallTest +public final class TestsDutchBE extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("nl", "BE"); + private static final LayoutBase LAYOUT = new Azerty(new DutchCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDvorakEmail.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDvorakEmail.java new file mode 100644 index 000000000..72a093fb0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDvorakEmail.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.layout.Dvorak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.DvorakCustomizer.EnglishDvorakCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * en_US: English (United States)/dvorak, email input field. + */ +@SmallTest +public class TestsDvorakEmail extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new DvorakEmail(new DvorakEmailCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + @Override + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { + final EditorInfo emailField = new EditorInfo(); + emailField.inputType = + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; + return super.createKeyboardLayoutSet( + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); + } + + private static class DvorakEmailCustomizer extends EnglishDvorakCustomizer { + DvorakEmailCustomizer(final Locale locale) { + super(locale); + } + + @Override + public ExpectedKey getEnterKey(final boolean isPhone) { + return isPhone ? ENTER_KEY : super.getEnterKey(isPhone); + } + + @Override + public ExpectedKey getEmojiKey(final boolean isPhone) { + return DOMAIN_KEY; + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + return isPhone ? super.getKeysLeftToSpacebar(isPhone) + : joinKeys(key("@", SETTINGS_KEY)); + } + } + + private static class DvorakEmail extends Dvorak { + DvorakEmail(final LayoutCustomizer customizer) { + super(customizer); + } + + @Override + protected ExpectedKey getRow1_1Key(final boolean isPhone, final int elementId) { + if (isPhone && (elementId == KeyboardId.ELEMENT_ALPHABET + || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED)) { + return key("@", joinMoreKeys(additionalMoreKey("1"))); + } + return super.getRow1_1Key(isPhone, elementId); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDvorakUrl.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDvorakUrl.java new file mode 100644 index 000000000..e0d8989cf --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsDvorakUrl.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.KeyboardId; +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.layout.Dvorak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.DvorakCustomizer.EnglishDvorakCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * en_US: English (United States)/dvorak, URL input field. + */ +@SmallTest +public class TestsDvorakUrl extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new DvorakEmail(new DvorakUrlCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + @Override + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { + final EditorInfo emailField = new EditorInfo(); + emailField.inputType = + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; + return super.createKeyboardLayoutSet( + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); + } + + private static class DvorakUrlCustomizer extends EnglishDvorakCustomizer { + DvorakUrlCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getEnterKey(final boolean isPhone) { + return isPhone ? ENTER_KEY : super.getEnterKey(isPhone); + } + + @Override + public ExpectedKey getEmojiKey(final boolean isPhone) { + return DOMAIN_KEY; + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + return isPhone ? super.getKeysLeftToSpacebar(isPhone) + : joinKeys(key("/", SETTINGS_KEY)); + } + } + + private static class DvorakEmail extends Dvorak { + DvorakEmail(final LayoutCustomizer customizer) { super(customizer); } + + @Override + protected ExpectedKey getRow1_1Key(final boolean isPhone, final int elementId) { + if (isPhone && (elementId == KeyboardId.ELEMENT_ALPHABET + || elementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED)) { + return key("/", joinMoreKeys(additionalMoreKey("1"))); + } + return super.getRow1_1Key(isPhone, elementId); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishDvorak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishDvorak.java new file mode 100644 index 000000000..4ce4a4ecc --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishDvorak.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Dvorak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.DvorakCustomizer.EnglishDvorakCustomizer; + +import java.util.Locale; + +/** + * en_US: English (United States)/dvorak + */ +@SmallTest +public class TestsEnglishDvorak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new Dvorak(new EnglishDvorakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishIN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishIN.java new file mode 100644 index 000000000..85c54b693 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishIN.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.EnglishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/* + * en_IN: English (India)/qwerty + */ +@SmallTest +public final class TestsEnglishIN extends TestsEnglishUS { + private static final Locale LOCALE = new Locale("en", "IN"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishINCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class EnglishINCustomizer extends EnglishCustomizer { + EnglishINCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishUK.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishUK.java new file mode 100644 index 000000000..648ca3879 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishUK.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.EnglishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/* + * en_GB: English (Great Britain)/qwerty + */ +@SmallTest +public final class TestsEnglishUK extends TestsEnglishUS { + private static final Locale LOCALE = new Locale("en", "GB"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishUKCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class EnglishUKCustomizer extends EnglishCustomizer { + EnglishUKCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_POUND; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { return CURRENCIES_OTHER_THAN_POUND; } + + private static final ExpectedKey CURRENCY_POUND = key(Symbols.POUND_SIGN, + Symbols.CENT_SIGN, Symbols.DOLLAR_SIGN, Symbols.EURO_SIGN, Symbols.YEN_SIGN, + Symbols.PESO_SIGN); + + private static final ExpectedKey[] CURRENCIES_OTHER_THAN_POUND = { + Symbols.EURO_SIGN, Symbols.YEN_SIGN, key(Symbols.DOLLAR_SIGN, Symbols.CENT_SIGN), + Symbols.CENT_SIGN + }; + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishUS.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishUS.java new file mode 100644 index 000000000..72f57db8f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEnglishUS.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EnglishCustomizer; + +import java.util.Locale; + +/** + * en_US: English (United States)/qwerty + */ +@SmallTest +public class TestsEnglishUS extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEsperanto.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEsperanto.java new file mode 100644 index 000000000..de34b7a38 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEsperanto.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * eo: Esperanto/spanish + */ +@SmallTest +public class TestsEsperanto extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("eo"); + private static final LayoutBase LAYOUT = new Spanish(new EsperantoCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class EsperantoCustomizer extends LayoutCustomizer { + EsperantoCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+015D: "ŝ" LATIN SMALL LETTER S WITH CIRCUMFLEX + .replaceKeyOfLabel("q", key("\u015D", joinMoreKeys( + additionalMoreKey("1"), "q"))) + // U+011D: "ĝ" LATIN SMALL LETTER G WITH CIRCUMFLEX + // U+0175: "ŵ" LATIN SMALL LETTER W WITH CIRCUMFLEX + .replaceKeyOfLabel("w", key("\u011D", joinMoreKeys( + additionalMoreKey("2"), "w", "\u0175"))) + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u011B", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", + "\u0113") + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + .setMoreKeysOf("r", "\u0159", "\u0155", "\u0157") + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + // U+021B: "ț" LATIN SMALL LETTER T WITH COMMA BELOW + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0167: "ŧ" LATIN SMALL LETTER T WITH STROKE + .setMoreKeysOf("t", "\u0165", "\u021B", "\u0163", "\u0167") + // U+016D: "ŭ" LATIN SMALL LETTER U WITH BREVE + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+0177: "ŷ" LATIN SMALL LETTER Y WITH CIRCUMFLEX + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + // U+00FE: "þ" LATIN SMALL LETTER THORN + .replaceKeyOfLabel("y", key("\u016D", joinMoreKeys( + additionalMoreKey("6"), "y", "\u00FD", "\u0177", "\u00FF", "\u00FE"))) + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0169: "ũ" LATIN SMALL LETTER U WITH TILDE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00B5: "µ" MICRO SIGN + .setMoreKeysOf("u", + "\u00FA", "\u016F", "\u00FB", "\u00FC", "\u00F9", "\u016B", "\u0169", + "\u0171", "\u0173", "\u00B5") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0129: "ĩ" LATIN SMALL LETTER I WITH TILDE + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+0133: "ij" LATIN SMALL LIGATURE IJ + .setMoreKeysOf("i", + "\u00ED", "\u00EE", "\u00EF", "\u0129", "\u00EC", "\u012F", "\u012B", + "\u0131", "\u0133") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + .setMoreKeysOf("o", + "\u00F3", "\u00F6", "\u00F4", "\u00F2", "\u00F5", "\u0153", "\u00F8", + "\u014D", "\u0151", "\u00BA") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + .setMoreKeysOf("a", + "\u00E1", "\u00E0", "\u00E2", "\u00E4", "\u00E6", "\u00E3", "\u00E5", + "\u0101", "\u0103", "\u0105", "\u00AA") + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0219: "ș" LATIN SMALL LETTER S WITH COMMA BELOW + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + .setMoreKeysOf("s", "\u00DF", "\u0161", "\u015B", "\u0219", "\u015F") + // U+00F0: "ð" LATIN SMALL LETTER ETH + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .setMoreKeysOf("d", "\u00F0", "\u010F", "\u0111") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+0149: "ʼn" LATIN SMALL LETTER N PRECEDED BY APOSTROPHE + // U+014B: "ŋ" LATIN SMALL LETTER ENG + .setMoreKeysOf("n", "\u00F1", "\u0144", "\u0146", "\u0148", "\u0149", "\u014B") + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + // U+0121: "ġ" LATIN SMALL LETTER G WITH DOT ABOVE + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + .setMoreKeysOf("g", "\u011F", "\u0121", "\u0123") + // U+0125: "ĥ" LATIN SMALL LETTER H WITH CIRCUMFLEX + // U+0127: "ħ" LATIN SMALL LETTER H WITH STROKE + .setMoreKeysOf("h", "\u0125", "\u0127") + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + // U+0138: "ĸ" LATIN SMALL LETTER KRA + .setMoreKeysOf("k", "\u0137", "\u0138") + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + // U+0140: "ŀ" LATIN SMALL LETTER L WITH MIDDLE DOT + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u013A", "\u013C", "\u013E", "\u0140", "\u0142") + // U+0135: "ĵ" LATIN SMALL LETTER J WITH CIRCUMFLEX + .replaceKeyOfLabel(Spanish.ROW2_10, "\u0135") + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017A", "\u017C", "\u017E") + // U+0109: "ĉ" LATIN SMALL LETTER C WITH CIRCUMFLEX + .replaceKeyOfLabel("x", key("\u0109", moreKey("x"))) + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+010B: "ċ" LATIN SMALL LETTER C WITH DOT ABOVE + .setMoreKeysOf("c", "\u0107", "\u010D", "\u00E7", "\u010B") + // U+0175: "ŵ" LATIN SMALL LETTER W WITH CIRCUMFLEX + .setMoreKeysOf("v", "w", "\u0175"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEstonianEE.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEstonianEE.java new file mode 100644 index 000000000..2a0f636de --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEstonianEE.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.customizer.EstonianEECustomizer; + +import java.util.Locale; + +/** + * et_EE: Estonian (Estonia)/nordic + */ +@SmallTest +public final class TestsEstonianEE extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("et", "EE"); + private static final LayoutBase LAYOUT = new Nordic(new EstonianEECustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEstonianEEQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEstonianEEQwerty.java new file mode 100644 index 000000000..1727523da --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsEstonianEEQwerty.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EstonianEECustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * et_EE: Estonian (Estonia)/qwerty + */ +@SmallTest +public final class TestsEstonianEEQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("et", "EE"); + private static final LayoutBase LAYOUT = new Qwerty(new EstonianEEQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class EstonianEEQwertyCustomizer extends EstonianEECustomizer { + EstonianEEQwertyCustomizer(final Locale locale) { super(locale); } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // QWERTY layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + .setMoreKeysOf("a", "\u00E4", "\u0101", "\u00E0", "\u00E1", "\u00E2", "\u00E3", + "\u00E5", "\u00E6", "\u0105"); + } + + @Override + protected void setMoreKeysOfI(final ExpectedKeyboardBuilder builder, final int elementId) { + // TODO: The upper-case letter of "ı" in Estonian locale is "I". It should be omitted + // from the more keys of "I". + builder + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + .setMoreKeysOf("i", + "\u012B", "\u00EC", "\u012F", "\u00ED", "\u00EE", "\u00EF", "\u0131"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .setMoreKeysOf("o", "\u00F6", "\u00F5", "\u00F2", "\u00F3", "\u00F4", "\u0153", + "\u0151", "\u00F8"); + } + + @Override + protected void setMoreKeysOfU(final ExpectedKeyboardBuilder builder) { + builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + .setMoreKeysOf("u", "\u00FC", "\u016B", "\u0173", "\u00F9", "\u00FA", "\u00FB", + "\u016F", "\u0171"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFinnish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFinnish.java new file mode 100644 index 000000000..329c22ac8 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFinnish.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.customizer.FinnishCustomizer; + +import java.util.Locale; + +/** + * fi: Finnish/nordic + */ +@SmallTest +public final class TestsFinnish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fi"); + private static final LayoutBase LAYOUT = new Nordic(new FinnishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFinnishQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFinnishQwerty.java new file mode 100644 index 000000000..5aeade2dd --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFinnishQwerty.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.FinnishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * fi: Finnish/qwerty + */ +@SmallTest +public final class TestsFinnishQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fi"); + private static final LayoutBase LAYOUT = new Qwerty(new FinnishQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class FinnishQwertyCustomizer extends FinnishCustomizer { + FinnishQwertyCustomizer(final Locale locale) { super(locale); } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // QWERTY layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E4", "\u00E5", "\u00E6", "\u00E0", "\u00E1", "\u00E2", + "\u00E3", "\u0101"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F8", "\u00F4", "\u00F2", "\u00F3", "\u00F5", + "\u0153", "\u014D"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrench.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrench.java new file mode 100644 index 000000000..b8f5331b7 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrench.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Azerty; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.FrenchCustomizer.FrenchEuroCustomizer; + +import java.util.Locale; + +/** + * fr: French/azerty + */ +@SmallTest +public final class TestsFrench extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fr"); + private static final LayoutBase LAYOUT = new Azerty(new FrenchEuroCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchCA.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchCA.java new file mode 100644 index 000000000..59092d344 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchCA.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.FrenchCustomizer; + +import java.util.Locale; + +/** + * fr_CA: French (Canada)/qwerty + */ +@SmallTest +public final class TestsFrenchCA extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fr", "CA"); + private static final LayoutBase LAYOUT = new Qwerty(new FrenchCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchCH.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchCH.java new file mode 100644 index 000000000..1bd896cae --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchCH.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Swiss; +import org.kelar.inputmethod.keyboard.layout.customizer.FrenchCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * fr_CH: French (Switzerland)/swiss + */ +@SmallTest +public final class TestsFrenchCH extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fr", "CH"); + private static final LayoutBase LAYOUT = new Swiss(new FrenchCHCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class FrenchCHCustomizer extends FrenchCustomizer { + FrenchCHCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + super.setAccentedLetters(builder); + return builder + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + .replaceKeyOfLabel(Swiss.ROW1_11, key("\u00E8", moreKey("\u00FC"))) + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + .replaceKeyOfLabel(Swiss.ROW2_10, key("\u00E9", moreKey("\u00F6"))) + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + .replaceKeyOfLabel(Swiss.ROW2_11, key("\u00E0", moreKey("\u00E4"))); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchDvorak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchDvorak.java new file mode 100644 index 000000000..2d04239b3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchDvorak.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Dvorak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.DvorakCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.FrenchCustomizer.FrenchEuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * fr: French/dvorak + */ +@SmallTest +public final class TestsFrenchDvorak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fr"); + private static final LayoutBase LAYOUT = new Dvorak(new FrenchDvorakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class FrenchDvorakCustomizer extends DvorakCustomizer { + private final FrenchEuroCustomizer mFrenchEuroCustomizer; + + FrenchDvorakCustomizer(final Locale locale) { + super(locale); + mFrenchEuroCustomizer = new FrenchEuroCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { return mFrenchEuroCustomizer.getCurrencyKey(); } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mFrenchEuroCustomizer.getOtherCurrencyKeys(); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mFrenchEuroCustomizer.setAccentedLetters(builder); + } + } +}
\ No newline at end of file diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchQwertz.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchQwertz.java new file mode 100644 index 000000000..a6ab73174 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsFrenchQwertz.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwertz; +import org.kelar.inputmethod.keyboard.layout.customizer.FrenchCustomizer.FrenchEuroCustomizer; + +import java.util.Locale; + +/** + * fr: French/qwertz + */ +@SmallTest +public final class TestsFrenchQwertz extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fr"); + private static final LayoutBase LAYOUT = new Qwertz(new FrenchEuroCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGalicianES.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGalicianES.java new file mode 100644 index 000000000..6c7a0e1e4 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGalicianES.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.SpanishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * gl_ES: Galician (Spain)/spanish + */ +@SmallTest +public class TestsGalicianES extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("gl", "ES"); + private static final LayoutBase LAYOUT = new Spanish(new GalicianESCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class GalicianESCustomizer extends EuroCustomizer { + private final SpanishCustomizer mSpanishCustomizer; + + GalicianESCustomizer(final Locale locale) { + super(locale); + mSpanishCustomizer = new SpanishCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mSpanishCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGeorgianGE.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGeorgianGE.java new file mode 100644 index 000000000..db278e91e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGeorgianGE.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Georgian; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * ka_GE: Georgian (Georgia)/georgian + */ +@SmallTest +public final class TestsGeorgianGE extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ka", "GE"); + private static final LayoutBase LAYOUT = new Georgian(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGerman.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGerman.java new file mode 100644 index 000000000..dc4c65e2c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGerman.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwertz; +import org.kelar.inputmethod.keyboard.layout.customizer.GermanCustomizer.GermanEuroCustomizer; + +import java.util.Locale; + +/** + * de: German/qwertz + */ +@SmallTest +public final class TestsGerman extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("de"); + private static final LayoutBase LAYOUT = new Qwertz(new GermanEuroCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanCH.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanCH.java new file mode 100644 index 000000000..756c7a77c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanCH.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Swiss; +import org.kelar.inputmethod.keyboard.layout.customizer.GermanCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * de_CH: German (Switzerland)/swiss + */ +@SmallTest +public final class TestsGermanCH extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("de", "CH"); + private static final LayoutBase LAYOUT = new Swiss(new GermanCHCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class GermanCHCustomizer extends GermanCustomizer { + GermanCHCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + super.setAccentedLetters(builder); + return builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + .replaceKeyOfLabel(Swiss.ROW1_11, key("\u00FC", moreKey("\u00E8"))) + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + .replaceKeyOfLabel(Swiss.ROW2_10, key("\u00F6", moreKey("\u00E9"))) + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + .replaceKeyOfLabel(Swiss.ROW2_11, key("\u00E4", moreKey("\u00E0"))); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanDvorak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanDvorak.java new file mode 100644 index 000000000..0da8eb4ef --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanDvorak.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Dvorak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.DvorakCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.GermanCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * de: German/dvorak + */ +@SmallTest +public final class TestsGermanDvorak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("de"); + private static final LayoutBase LAYOUT = new Dvorak(new GermanDvorakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class GermanDvorakCustomizer extends DvorakCustomizer { + private final GermanCustomizer mGermanCustomizer; + + GermanDvorakCustomizer(final Locale locale) { + super(locale); + mGermanCustomizer = new GermanCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { return Symbols.CURRENCY_EURO; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_THAN_EURO; + } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mGermanCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanQwerty.java new file mode 100644 index 000000000..33bf2df25 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGermanQwerty.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.GermanCustomizer.GermanEuroCustomizer; + +import java.util.Locale; + +/** + * de: German/qwerty + */ +@SmallTest +public final class TestsGermanQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("de"); + private static final LayoutBase LAYOUT = new Qwerty(new GermanEuroCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGreek.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGreek.java new file mode 100644 index 000000000..5c8e8e6d1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsGreek.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Greek; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * el: Greek/greek + */ +@SmallTest +public class TestsGreek extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("el"); + private static final LayoutBase LAYOUT = new Greek(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHebrew.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHebrew.java new file mode 100644 index 000000000..eb31e4e12 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHebrew.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Hebrew; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * iw: Hebrew/hebrew + */ +@SmallTest +public class TestsHebrew extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("iw"); + private static final LayoutBase LAYOUT = new Hebrew(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHindi.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHindi.java new file mode 100644 index 000000000..b67cf0f1c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHindi.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Hindi; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.HindiCustomizer; + +import java.util.Locale; + +/** + * hi: Hindi/hindi + */ +@SmallTest +public final class TestsHindi extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("hi"); + private static final LayoutBase LAYOUT = new Hindi(new HindiCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHindiCompact.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHindiCompact.java new file mode 100644 index 000000000..a70cf7c6f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHindiCompact.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.HindiCompact; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * hi: Hindi/hindi_compact + */ +@SmallTest +public final class TestsHindiCompact extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("hi"); + private static final LayoutBase LAYOUT = new HindiCompact(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHinglish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHinglish.java new file mode 100644 index 000000000..7b6563001 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHinglish.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.Suppress; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/* + * hi_ZZ: Hinglish/qwerty + */ +@Suppress +public final class TestsHinglish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("hi", "ZZ"); + private static final LayoutBase LAYOUT = new Qwerty(new HinglishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class HinglishCustomizer extends LayoutCustomizer { + HinglishCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHungarian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHungarian.java new file mode 100644 index 000000000..f3536e122 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsHungarian.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwertz; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * hu: Hungarian/qwertz + */ +@SmallTest +public final class TestsHungarian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("hu"); + private static final LayoutBase LAYOUT = new Qwertz(new HungarianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class HungarianCustomizer extends LayoutCustomizer { + HungarianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", "\u0113") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u0171", "\u00FB", "\u00F9", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00ED", "\u00EE", "\u00EF", "\u00EC", "\u012F", "\u012B") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F3", "\u00F6", "\u0151", "\u00F4", "\u00F2", "\u00F5", "\u0153", + "\u00F8", "\u014D") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E1", "\u00E0", "\u00E2", "\u00E4", "\u00E6", "\u00E3", "\u00E5", + "\u0101"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsIcelandic.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsIcelandic.java new file mode 100644 index 000000000..76a039f87 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsIcelandic.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * is: Icelandic/qwerty + */ +@SmallTest +public final class TestsIcelandic extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("is"); + private static final LayoutBase LAYOUT = new Qwerty(new IcelandicCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class IcelandicCustomizer extends LayoutCustomizer { + IcelandicCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u00EB", "\u00E8", "\u00EA", "\u0119", "\u0117", "\u0113") + // U+00FE: "þ" LATIN SMALL LETTER THORN + .setMoreKeysOf("t", "\u00FE") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00FB", "\u00F9", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00ED", "\u00EF", "\u00EE", "\u00EC", "\u012F", "\u012B") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F3", "\u00F6", "\u00F4", "\u00F2", "\u00F5", "\u0153", "\u00F8", + "\u014D") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E1", "\u00E4", "\u00E6", "\u00E5", "\u00E0", "\u00E2", "\u00E3", + "\u0101") + // U+00F0: "ð" LATIN SMALL LETTER ETH + .setMoreKeysOf("d", "\u00F0"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsIndonesian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsIndonesian.java new file mode 100644 index 000000000..0c122fddd --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsIndonesian.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; + +import java.util.Locale; + +/** + * in: Indonesian/qwerty # "id" is the official language code of Indonesian. + */ +@SmallTest +public final class TestsIndonesian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("in"); + private static final LayoutBase LAYOUT = new Qwerty(new LayoutCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsItalian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsItalian.java new file mode 100644 index 000000000..4f727f140 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsItalian.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.ItalianCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * it: Italian/qwerty + */ +@SmallTest +public final class TestsItalian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("it"); + private static final LayoutBase LAYOUT = new Qwerty(new ItalianITCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class ItalianITCustomizer extends EuroCustomizer { + private final ItalianCustomizer mItalianCustomizer; + + ItalianITCustomizer(final Locale locale) { + super(locale); + mItalianCustomizer = new ItalianCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mItalianCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsItalianCH.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsItalianCH.java new file mode 100644 index 000000000..ff7c04620 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsItalianCH.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Swiss; +import org.kelar.inputmethod.keyboard.layout.customizer.ItalianCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * it_CH: Italian (Switzerland)/swiss + */ +@SmallTest +public final class TestsItalianCH extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("it", "CH"); + private static final LayoutBase LAYOUT = new Swiss(new ItalianCHCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class ItalianCHCustomizer extends ItalianCustomizer { + ItalianCHCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + super.setAccentedLetters(builder); + return builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + .replaceKeyOfLabel(Swiss.ROW1_11, key("\u00FC", moreKey("\u00E8"))) + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + .replaceKeyOfLabel(Swiss.ROW2_10, key("\u00F6", moreKey("\u00E9"))) + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + .replaceKeyOfLabel(Swiss.ROW2_11, key("\u00E4", moreKey("\u00E0"))); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKannadaIN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKannadaIN.java new file mode 100644 index 000000000..3f5169444 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKannadaIN.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Kannada; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * kn_IN: Kannada (India)/kannada + */ +@SmallTest +public final class TestsKannadaIN extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("kn", "IN"); + private static final LayoutBase LAYOUT = new Kannada(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKazakh.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKazakh.java new file mode 100644 index 000000000..92797d005 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKazakh.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.EastSlavic; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * kk: Kazakh/east_slavic + */ +@SmallTest +public final class TestsKazakh extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("kk"); + private static final LayoutBase LAYOUT = new EastSlavic(new KazakhCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class KazakhCustomizer extends EastSlavicCustomizer { + KazakhCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0443: "у" CYRILLIC SMALL LETTER U + // U+04AF: "ү" CYRILLIC SMALL LETTER STRAIGHT U + // U+04B1: "ұ" CYRILLIC SMALL LETTER STRAIGHT U WITH STROKE + .setMoreKeysOf("\u0443", "\u04AF", "\u04B1") + // U+043A: "к" CYRILLIC SMALL LETTER KA + // U+049B: "қ" CYRILLIC SMALL LETTER KA WITH DESCENDER + .setMoreKeysOf("\u043A", "\u049B") + // U+0435: "е" CYRILLIC SMALL LETTER IE + // U+0451: "ё" CYRILLIC SMALL LETTER IO + .setMoreKeysOf("\u0435", "\u0451") + // U+043D: "н" CYRILLIC SMALL LETTER EN + // U+04A3: "ң" CYRILLIC SMALL LETTER EN WITH DESCENDER + .setMoreKeysOf("\u043D", "\u04A3") + // U+0433: "г" CYRILLIC SMALL LETTER GHE + // U+0493: "ғ" CYRILLIC SMALL LETTER GHE WITH STROKE + .setMoreKeysOf("\u0433", "\u0493") + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + .replaceKeyOfLabel(EastSlavic.ROW1_9, key("\u0449", additionalMoreKey("9"))) + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + // U+0456: "і" CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I + .replaceKeyOfLabel(EastSlavic.ROW2_2, key("\u044B", moreKey("\u0456"))) + // U+0430: "а" CYRILLIC SMALL LETTER A + // U+04D9: "ә" CYRILLIC SMALL LETTER SCHWA + .setMoreKeysOf("\u0430", "\u04D9") + // U+043E: "о" CYRILLIC SMALL LETTER O + // U+04E9: "ө" CYRILLIC SMALL LETTER BARRED O + .setMoreKeysOf("\u043E", "\u04E9") + // U+044D: "э" CYRILLIC SMALL LETTER E + // U+04BB: "һ" CYRILLIC SMALL LETTER SHHA + .replaceKeyOfLabel(EastSlavic.ROW2_11, key("\u044D", moreKey("\u04BB"))) + // U+0438: "и" CYRILLIC SMALL LETTER I + .replaceKeyOfLabel(EastSlavic.ROW3_5, "\u0438") + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + .setMoreKeysOf("\u044C", "\u044A"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKhmerKH.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKhmerKH.java new file mode 100644 index 000000000..9e28a1bf2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKhmerKH.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Khmer; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * km_KH: Khmer (Cambodia)/khmer + */ +@SmallTest +public final class TestsKhmerKH extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("km", "KH"); + private static final LayoutBase LAYOUT = new Khmer(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKyrgyz.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKyrgyz.java new file mode 100644 index 000000000..a60801cb5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsKyrgyz.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.EastSlavic; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * ky: Kyrgyz/east_slavic + */ +@SmallTest +public final class TestsKyrgyz extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ky"); + private static final LayoutBase LAYOUT = new EastSlavic(new KyrgyzCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class KyrgyzCustomizer extends EastSlavicCustomizer { + KyrgyzCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0443: "у" CYRILLIC SMALL LETTER U + // U+04AF: "ү" CYRILLIC SMALL LETTER STRAIGHT U + .setMoreKeysOf("\u0443", "\u04AF") + // U+0435: "е" CYRILLIC SMALL LETTER IE + // U+0451: "ё" CYRILLIC SMALL LETTER IO + .setMoreKeysOf("\u0435", "\u0451") + // U+043D: "н" CYRILLIC SMALL LETTER EN + // U+04A3: "ң" CYRILLIC SMALL LETTER EN WITH DESCENDER + .setMoreKeysOf("\u043D", "\u04A3") + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + .replaceKeyOfLabel(EastSlavic.ROW1_9, key("\u0449", additionalMoreKey("9"))) + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + .replaceKeyOfLabel(EastSlavic.ROW2_2, "\u044B") + // U+043E: "о" CYRILLIC SMALL LETTER O + // U+04E9: "ө" CYRILLIC SMALL LETTER BARRED O + .setMoreKeysOf("\u043E", "\u04E9") + // U+044D: "э" CYRILLIC SMALL LETTER E + .replaceKeyOfLabel(EastSlavic.ROW2_11, "\u044D") + // U+0438: "и" CYRILLIC SMALL LETTER I + .replaceKeyOfLabel(EastSlavic.ROW3_5, "\u0438") + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + .setMoreKeysOf("\u044C", "\u044A"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLaoLA.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLaoLA.java new file mode 100644 index 000000000..b6d06baf3 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLaoLA.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Lao; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * lo_LA: Lao (Laos)/lao + */ +@SmallTest +public final class TestsLaoLA extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("lo", "LA"); + private static final LayoutBase LAYOUT = new Lao(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLatvian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLatvian.java new file mode 100644 index 000000000..873a42ec5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLatvian.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * lv: Latvian/qwerty + */ +@SmallTest +public final class TestsLatvian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("lv"); + private static final LayoutBase LAYOUT = new Qwerty(new LatvianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class LatvianCustomizer extends LayoutCustomizer { + LatvianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + .setMoreKeysOf("e", + "\u0113", "\u0117", "\u00E8", "\u00E9", "\u00EA", "\u00EB", "\u0119", + "\u011B") + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + .setMoreKeysOf("r", "\u0157", "\u0159", "\u0155") + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + .setMoreKeysOf("t", "\u0163", "\u0165") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + .setMoreKeysOf("u", + "\u016B", "\u0173", "\u00F9", "\u00FA", "\u00FB", "\u00FC", "\u016F", + "\u0171") + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + .setMoreKeysOf("i", + "\u012B", "\u012F", "\u00EC", "\u00ED", "\u00EE", "\u00EF", "\u0131") + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .setMoreKeysOf("o", + "\u00F2", "\u00F3", "\u00F4", "\u00F5", "\u00F6", "\u0153", "\u0151", + "\u00F8") + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + .setMoreKeysOf("a", + "\u0101", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u00E4", "\u00E5", + "\u00E6", "\u0105") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B", "\u015F") + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u010F") + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + .setMoreKeysOf("g", "\u0123", "\u011F") + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + .setMoreKeysOf("k", "\u0137") + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + .setMoreKeysOf("l", "\u013C", "\u0142", "\u013A", "\u013E") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + .setMoreKeysOf("z", "\u017E", "\u017C", "\u017A") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u00E7", "\u0107") + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u0146", "\u00F1", "\u0144"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLithuanian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLithuanian.java new file mode 100644 index 000000000..6c9797ccb --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsLithuanian.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * lt: Lithuanian/qwerty + */ +@SmallTest +public final class TestsLithuanian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("lt"); + private static final LayoutBase LAYOUT = new Qwerty(new LithuanianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class LithuanianCustomizer extends LayoutCustomizer { + LithuanianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + .setMoreKeysOf("e", + "\u0117", "\u0119", "\u0113", "\u00E8", "\u00E9", "\u00EA", "\u00EB", + "\u011B") + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + .setMoreKeysOf("r", "\u0157", "\u0159", "\u0155") + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + .setMoreKeysOf("t", "\u0163", "\u0165") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + .setMoreKeysOf("u", + "\u016B", "\u0173", "\u00FC", "\u016B", "\u00F9", "\u00FA", "\u00FB", + "\u016F", "\u0171") + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + .setMoreKeysOf("i", + "\u012F", "\u012B", "\u00EC", "\u00ED", "\u00EE", "\u00EF", "\u0131") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .setMoreKeysOf("o", + "\u00F6", "\u00F5", "\u00F2", "\u00F3", "\u00F4", "\u0153", "\u0151", + "\u00F8") + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + .setMoreKeysOf("a", + "\u0105", "\u00E4", "\u0101", "\u00E0", "\u00E1", "\u00E2", "\u00E3", + "\u00E5", "\u00E6") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B", "\u015F") + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u010F") + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + .setMoreKeysOf("g", "\u0123", "\u011F") + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + .setMoreKeysOf("k", "\u0137") + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + .setMoreKeysOf("l", "\u013C", "\u0142", "\u013A", "\u013E") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + .setMoreKeysOf("z", "\u017E", "\u017C", "\u017A") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u00E7", "\u0107") + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u0146", "\u00F1", "\u0144"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMacedonian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMacedonian.java new file mode 100644 index 000000000..5970c15e5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMacedonian.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.SouthSlavic; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.SouthSlavicLayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * mk: Macedonian/south_slavic + */ +@SmallTest +public final class TestsMacedonian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("mk"); + private static final LayoutBase LAYOUT = new SouthSlavic(new MacedonianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class MacedonianCustomizer extends SouthSlavicLayoutCustomizer { + MacedonianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0435: "е" CYRILLIC SMALL LETTER IE + // U+0450: "ѐ" CYRILLIC SMALL LETTER IE WITH GRAVE + .setMoreKeysOf("\u0435", "\u0450") + // U+0455: "ѕ" CYRILLIC SMALL LETTER DZE + .replaceKeyOfLabel(SouthSlavic.ROW1_6, key("\u0455", additionalMoreKey("6"))) + // U+0438: "и" CYRILLIC SMALL LETTER I + // U+045D: "ѝ" CYRILLIC SMALL LETTER I WITH GRAVE + .setMoreKeysOf("\u0438", "\u045D") + // U+045C: "ќ" CYRILLIC SMALL LETTER KJE + .replaceKeyOfLabel(SouthSlavic.ROW2_11, "\u045C") + // U+0437: "з" CYRILLIC SMALL LETTER ZE + .replaceKeyOfLabel(SouthSlavic.ROW3_1, "\u0437") + // U+0453: "ѓ" CYRILLIC SMALL LETTER GJE + .replaceKeyOfLabel(SouthSlavic.ROW3_8, "\u0453"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMalayMY.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMalayMY.java new file mode 100644 index 000000000..6aa2a13ea --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMalayMY.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; + +import java.util.Locale; + +/** + * ms_MY: Malay (Malaysia)/qwerty + */ +@SmallTest +public final class TestsMalayMY extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ms", "MY"); + private static final LayoutBase LAYOUT = new Qwerty(new LayoutCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMalayalamIN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMalayalamIN.java new file mode 100644 index 000000000..4ab784650 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMalayalamIN.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Malayalam; + +import java.util.Locale; + +/** + * ml_IN: Malayalam (India)/malayalam + */ +@SmallTest +public final class TestsMalayalamIN extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ml", "IN"); + private static final LayoutBase LAYOUT = new Malayalam(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMarathiIN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMarathiIN.java new file mode 100644 index 000000000..e0ff90742 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMarathiIN.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Marathi; + +import java.util.Locale; + +/** + * mr_IN: Marathi (India)/marathi + */ +@SmallTest +public final class TestsMarathiIN extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("mr", "IN"); + private static final LayoutBase LAYOUT = new Marathi(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMongolianMN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMongolianMN.java new file mode 100644 index 000000000..0c94f6ec9 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsMongolianMN.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Mongolian; + +import java.util.Locale; + +/** + * mn_MN: Mongolian (Mongolia)/mongolian + */ +@SmallTest +public final class TestsMongolianMN extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("mn", "MN"); + private static final LayoutBase LAYOUT = new Mongolian(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNepaliRomanized.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNepaliRomanized.java new file mode 100644 index 000000000..ae57bec7a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNepaliRomanized.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.NepaliRomanized; + +import java.util.Locale; + +/** + * ne_NP: Nepali (Nepal) Romanized/nepali_romanized + */ +@SmallTest +public final class TestsNepaliRomanized extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ne", "NP"); + private static final LayoutBase LAYOUT = new NepaliRomanized(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNepaliTraditional.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNepaliTraditional.java new file mode 100644 index 000000000..17dee2b61 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNepaliTraditional.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.NepaliTraditional; + +import java.util.Locale; + +/** + * ne_NP: Nepali (Nepal) Traditional/nepali_traditional + */ +@SmallTest +public final class TestsNepaliTraditional extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ne", "NP"); + private static final LayoutBase LAYOUT = new NepaliTraditional(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguage.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguage.java new file mode 100644 index 000000000..09953ceed --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguage.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.NoLanguageCustomizer; + +import java.util.Locale; + +/** + * zz: Alphabet/qwerty + */ +@SmallTest +public final class TestsNoLanguage extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("zz"); + private static final LayoutBase LAYOUT = new Qwerty(new NoLanguageCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguageColemak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguageColemak.java new file mode 100644 index 000000000..25577eb92 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguageColemak.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Colemak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.NoLanguageCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * zz: Alphabet/colemak + */ +@SmallTest +public final class TestsNoLanguageColemak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("zz"); + private static final LayoutBase LAYOUT = new Colemak(new NoLanguageColemakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class NoLanguageColemakCustomizer extends LayoutCustomizer { + private final NoLanguageCustomizer mNoLanguageCustomizer; + + NoLanguageColemakCustomizer(final Locale locale) { + super(locale); + mNoLanguageCustomizer = new NoLanguageCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mNoLanguageCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguageDvorak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguageDvorak.java new file mode 100644 index 000000000..078f2a231 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguageDvorak.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Dvorak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.DvorakCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.NoLanguageCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * zz: Alphabet/dvorak + */ +@SmallTest +public final class TestsNoLanguageDvorak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("zz"); + private static final LayoutBase LAYOUT = new Dvorak(new NoLanguageDvorakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class NoLanguageDvorakCustomizer extends DvorakCustomizer { + private final NoLanguageCustomizer mNoLanguageCustomizer; + + NoLanguageDvorakCustomizer(final Locale locale) { + super(locale); + mNoLanguageCustomizer = new NoLanguageCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mNoLanguageCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguagePcQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguagePcQwerty.java new file mode 100644 index 000000000..ac5b5b571 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNoLanguagePcQwerty.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.PcQwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.NoLanguageCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.PcQwertyCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * zz: Alphabet/pcqwerty + */ +@SmallTest +public final class TestsNoLanguagePcQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("zz"); + private static final LayoutBase LAYOUT = new PcQwerty(new NoLanguagePcQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class NoLanguagePcQwertyCustomizer extends PcQwertyCustomizer { + private final NoLanguageCustomizer mNoLanguageCustomizer; + + NoLanguagePcQwertyCustomizer(final Locale locale) { + super(locale); + mNoLanguageCustomizer = new NoLanguageCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mNoLanguageCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNorwegian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNorwegian.java new file mode 100644 index 000000000..077af6daa --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNorwegian.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.customizer.NorwegianCustomizer; + +import java.util.Locale; + +/** + * nb: Norwegian Bokmål/nordic + */ +@SmallTest +public final class TestsNorwegian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("nb"); + private static final LayoutBase LAYOUT = new Nordic(new NorwegianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNorwegianColemak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNorwegianColemak.java new file mode 100644 index 000000000..10214573a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsNorwegianColemak.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Colemak; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.customizer.NorwegianCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * nb: Norwegian Bokmål/colemak + */ +@SmallTest +public final class TestsNorwegianColemak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("nb"); + private static final LayoutBase LAYOUT = new Colemak(new NorwegianColemakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class NorwegianColemakCustomizer extends NorwegianCustomizer { + NorwegianColemakCustomizer(final Locale locale) { super(locale); } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // Colemak layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E5", "\u00E6", "\u00E4", "\u00E0", "\u00E1", "\u00E2", + "\u00E3", "\u0101"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u00F6", "\u00F4", "\u00F2", "\u00F3", "\u00F5", + "\u0153", "\u014D"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPersian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPersian.java new file mode 100644 index 000000000..fb45a264e --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPersian.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.Farsi; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; + +import java.util.Locale; + +/** + * fa: Persian/farsi + */ +@SmallTest +public class TestsPersian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fa"); + private static final LayoutBase LAYOUT = new Farsi(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPolish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPolish.java new file mode 100644 index 000000000..e9fb37354 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPolish.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * pl: Polish/qwerty + */ +@SmallTest +public final class TestsPolish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("pl"); + private static final LayoutBase LAYOUT = new Qwerty(new PolishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class PolishCustomizer extends LayoutCustomizer { + PolishCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u0119", "\u00E8", "\u00E9", "\u00EA", "\u00EB", "\u0117", "\u0113") + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F3", "\u00F6", "\u00F4", "\u00F2", "\u00F5", "\u0153", "\u00F8", + "\u014D") + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u0105", "\u00E1", "\u00E0", "\u00E2", "\u00E4", "\u00E6", "\u00E3", + "\u00E5", "\u0101") + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u015B", "\u00DF", "\u0161") + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u0142") + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017C", "\u017A", "\u017E") + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u0107", "\u00E7", "\u010D") + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + .setMoreKeysOf("n", "\u0144", "\u00F1"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPortugueseBR.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPortugueseBR.java new file mode 100644 index 000000000..9dc5f2cf6 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPortugueseBR.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.PortugueseCustomizer; + +import java.util.Locale; + +/** + * pt_BR: Portuguese (Brazil)/qwerty + */ +@SmallTest +public class TestsPortugueseBR extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("pt", "BR"); + private static final LayoutBase LAYOUT = new Qwerty(new PortugueseCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPortuguesePT.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPortuguesePT.java new file mode 100644 index 000000000..44c0afa30 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsPortuguesePT.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.PortugueseCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * pt_PT: Portuguese (Portugal)/qwerty + */ +@SmallTest +public final class TestsPortuguesePT extends TestsPortugueseBR { + private static final Locale LOCALE = new Locale("pt", "PT"); + private static final LayoutBase LAYOUT = new Qwerty(new PortuguesePTCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class PortuguesePTCustomizer extends PortugueseCustomizer { + private final EuroCustomizer mEuroCustomizer; + + PortuguesePTCustomizer(final Locale locale) { + super(locale); + mEuroCustomizer = new EuroCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { return mEuroCustomizer.getCurrencyKey(); } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mEuroCustomizer.getOtherCurrencyKeys(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsQwertyEmail.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsQwertyEmail.java new file mode 100644 index 000000000..a30dccaed --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsQwertyEmail.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EnglishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * en_US: English (United States)/qwerty, email input field. + */ +@SmallTest +public class TestsQwertyEmail extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishEmailCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + @Override + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { + final EditorInfo emailField = new EditorInfo(); + emailField.inputType = + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; + return super.createKeyboardLayoutSet( + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); + } + + private static class EnglishEmailCustomizer extends EnglishCustomizer { + EnglishEmailCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getEnterKey(final boolean isPhone) { + return isPhone ? ENTER_KEY : super.getEnterKey(isPhone); + } + + @Override + public ExpectedKey getEmojiKey(final boolean isPhone) { + return DOMAIN_KEY; + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + return joinKeys(key("@", SETTINGS_KEY)); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsQwertyUrl.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsQwertyUrl.java new file mode 100644 index 000000000..8e9897df0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsQwertyUrl.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EnglishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * en_US: English (United States)/qwerty, URL input field. + */ +@SmallTest +public class TestsQwertyUrl extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishUrlCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + @Override + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { + final EditorInfo emailField = new EditorInfo(); + emailField.inputType = + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; + return super.createKeyboardLayoutSet( + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); + } + + private static class EnglishUrlCustomizer extends EnglishCustomizer { + EnglishUrlCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getEnterKey(final boolean isPhone) { + return isPhone ? ENTER_KEY : super.getEnterKey(isPhone); + } + + @Override + public ExpectedKey getEmojiKey(final boolean isPhone) { + return DOMAIN_KEY; + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + return joinKeys(key("/", SETTINGS_KEY)); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsRomanian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsRomanian.java new file mode 100644 index 000000000..fed99b1d9 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsRomanian.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * ro: Romanian/qwerty + */ +@SmallTest +public final class TestsRomanian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ro"); + private static final LayoutBase LAYOUT = new Qwerty(new RomanianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class RomanianCustomizer extends LayoutCustomizer { + RomanianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+021B: "ț" LATIN SMALL LETTER T WITH COMMA BELOW + .setMoreKeysOf("t", "\u021B") + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", "\u00EE", "\u00EF", "\u00EC", "\u00ED", "\u012F", "\u012B") + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u0103", "\u00E2", "\u00E3", "\u00E0", "\u00E1", "\u00E4", "\u00E6", + "\u00E5", "\u0101") + // U+0219: "ș" LATIN SMALL LETTER S WITH COMMA BELOW + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u0219", "\u00DF", "\u015B", "\u0161"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsRussian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsRussian.java new file mode 100644 index 000000000..57f2d7bd0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsRussian.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.EastSlavic; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * ru: Russian/east_slavic + */ +@SmallTest +public final class TestsRussian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ru"); + private static final LayoutBase LAYOUT = new EastSlavic(new RussianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class RussianCustomizer extends EastSlavicCustomizer { + RussianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0435: "е" CYRILLIC SMALL LETTER IE + // U+0451: "ё" CYRILLIC SMALL LETTER IO + .setMoreKeysOf("\u0435", "\u0451") + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + .replaceKeyOfLabel(EastSlavic.ROW1_9, key("\u0449", additionalMoreKey("9"))) + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + .replaceKeyOfLabel(EastSlavic.ROW2_2, "\u044B") + // U+044D: "э" CYRILLIC SMALL LETTER E + .replaceKeyOfLabel(EastSlavic.ROW2_11, "\u044D") + // U+0438: "и" CYRILLIC SMALL LETTER I + .replaceKeyOfLabel(EastSlavic.ROW3_5, "\u0438") + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + .setMoreKeysOf("\u044C", "\u044A"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbian.java new file mode 100644 index 000000000..cfbbcd9e1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbian.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.SouthSlavic; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.SouthSlavicLayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sr: Serbian/south_slavic + */ +@SmallTest +public final class TestsSerbian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sr"); + private static final LayoutBase LAYOUT = new SouthSlavic(new SerbianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SerbianCustomizer extends SouthSlavicLayoutCustomizer { + SerbianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0435: "е" CYRILLIC SMALL LETTER IE + // U+0450: "ѐ" CYRILLIC SMALL LETTER IE WITH GRAVE + .setMoreKeysOf("\u0435", "\u0450") + // U+0437: "з" CYRILLIC SMALL LETTER ZE + .replaceKeyOfLabel(SouthSlavic.ROW1_6, key("\u0437", additionalMoreKey("6"))) + // U+0438: "и" CYRILLIC SMALL LETTER I + // U+045D: "ѝ" CYRILLIC SMALL LETTER I WITH GRAVE + .setMoreKeysOf("\u0438", "\u045D") + // U+045B: "ћ" CYRILLIC SMALL LETTER TSHE + .replaceKeyOfLabel(SouthSlavic.ROW2_11, "\u045B") + // U+0455: "ѕ" CYRILLIC SMALL LETTER DZE + .replaceKeyOfLabel(SouthSlavic.ROW3_1, "\u0455") + // U+0452: "ђ" CYRILLIC SMALL LETTER DJE + .replaceKeyOfLabel(SouthSlavic.ROW3_8, "\u0452"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbianLatin.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbianLatin.java new file mode 100644 index 000000000..facef7aa8 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbianLatin.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.SerbianQwertz; +import org.kelar.inputmethod.keyboard.layout.customizer.SerbianLatinCustomizer; + +import java.util.Locale; + +/** + * sr_ZZ: Serbian (Latin)/serbian_qwertz + */ +@SmallTest +public final class TestsSerbianLatin extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sr", "ZZ"); + private static final LayoutBase LAYOUT = new SerbianQwertz(new SerbianLatinCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbianLatinQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbianLatinQwerty.java new file mode 100644 index 000000000..c4b9f5595 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSerbianLatinQwerty.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.SerbianLatinCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sr_ZZ: Serbian (Latin)/qwerty + */ +@SmallTest +public final class TestsSerbianLatinQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sr", "ZZ"); + private static final LayoutBase LAYOUT = new Qwerty(new SerbianLatinQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SerbianLatinQwertyCustomizer extends SerbianLatinCustomizer { + SerbianLatinQwertyCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS + : joinKeys(EXCLAMATION_AND_QUESTION_MARKS, SHIFT_KEY); + } + + @Override + protected void setSerbianKeys(final ExpectedKeyboardBuilder builder) { + // QWERTY layout doesn't have Serbian Latin Keys. + } + + @Override + protected void setMoreKeysOfS(final ExpectedKeyboardBuilder builder) { + builder + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u0161") + .setAdditionalMoreKeysPositionOf("s", 2); + } + + @Override + protected void setMoreKeysOfC(final ExpectedKeyboardBuilder builder) { + builder + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u0107") + .setAdditionalMoreKeysPositionOf("c", 3); + } + + @Override + protected void setMoreKeysOfD(final ExpectedKeyboardBuilder builder) { + builder + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .setMoreKeysOf("d", "\u0111") + .setAdditionalMoreKeysPositionOf("d", 2); + } + + @Override + protected void setMoreKeysOfZ(final ExpectedKeyboardBuilder builder) { + builder + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017E") + .setAdditionalMoreKeysPositionOf("z", 2); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSinhalaLK.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSinhalaLK.java new file mode 100644 index 000000000..c615f3bde --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSinhalaLK.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.Suppress; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Sinhala; + +import java.util.Locale; + +/** + * si_LK: Sinhala (Sri Lanka)/sinhala + */ +@Suppress +public final class TestsSinhalaLK extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("si", "LK"); + private static final LayoutBase LAYOUT = new Sinhala(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSlovak.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSlovak.java new file mode 100644 index 000000000..83ce1874d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSlovak.java @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sk: Slovak/qwerty + */ +@SmallTest +public final class TestsSlovak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sk"); + private static final LayoutBase LAYOUT = new Qwerty(new SlovakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SlovakCustomizer extends EuroCustomizer { + SlovakCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + .setMoreKeysOf("e", + "\u00E9", "\u011B", "\u0113", "\u0117", "\u00E8", "\u00EA", "\u00EB", + "\u0119") + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + .setMoreKeysOf("r", "\u0155", "\u0159", "\u0157") + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + .setMoreKeysOf("t", "\u0165", "\u0163") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + .setMoreKeysOf("u", + "\u00FA", "\u016F", "\u00FC", "\u016B", "\u0173", "\u00F9", "\u00FB", + "\u0171") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + .setMoreKeysOf("i", + "\u00ED", "\u012B", "\u012F", "\u00EC", "\u00EE", "\u00EF", "\u0131") + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .setMoreKeysOf("o", + "\u00F4", "\u00F3", "\u00F6", "\u00F2", "\u00F5", "\u0153", "\u0151", + "\u00F8") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + .setMoreKeysOf("a", + "\u00E1", "\u00E4", "\u0101", "\u00E0", "\u00E2", "\u00E3", "\u00E5", + "\u00E6", "\u0105") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B", "\u015F") + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u010F") + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + .setMoreKeysOf("g", "\u0123", "\u011F") + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + .setMoreKeysOf("k", "\u0137") + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u013E", "\u013A", "\u013C", "\u0142") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + .setMoreKeysOf("z", "\u017E", "\u017C", "\u017A") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u00E7", "\u0107") + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u0148", "\u0146", "\u00F1", "\u0144"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSlovenian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSlovenian.java new file mode 100644 index 000000000..6c7a4e7f2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSlovenian.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sl: Slovenian/qwerty + */ +@SmallTest +public final class TestsSlovenian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sl"); + private static final LayoutBase LAYOUT = new Qwerty(new SlovenianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SlovenianCustomizer extends EuroCustomizer { + SlovenianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u0161") + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .setMoreKeysOf("d", "\u0111") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017E") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u0107"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanish.java new file mode 100644 index 000000000..6ce6f22c0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanish.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.SpanishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * es: Spanish/spanish + */ +@SmallTest +public class TestsSpanish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("es"); + private static final LayoutBase LAYOUT = new Spanish(new SpanishESCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SpanishESCustomizer extends SpanishCustomizer { + private final EuroCustomizer mEuroCustomizer; + + SpanishESCustomizer(final Locale locale) { + super(locale); + mEuroCustomizer = new EuroCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { return mEuroCustomizer.getCurrencyKey(); } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mEuroCustomizer.getOtherCurrencyKeys(); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanish419.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanish419.java new file mode 100644 index 000000000..f37ad0052 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanish419.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.SpanishCustomizer; + +import java.util.Locale; + +/** + * es_419: Spanish (Latin America)/spanish + */ +@SmallTest +public class TestsSpanish419 extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("es", "419"); + private static final LayoutBase LAYOUT = new Spanish(new SpanishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanishUS.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanishUS.java new file mode 100644 index 000000000..eb9d80bdf --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSpanishUS.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.SpanishCustomizer; + +import java.util.Locale; + +/** + * es_US: Spanish (United States)/spanish + */ +@SmallTest +public class TestsSpanishUS extends TestsSpanish { + private static final Locale LOCALE = new Locale("es", "US"); + private static final LayoutBase LAYOUT = new Spanish(new SpanishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSplitLayoutQwertyEnglishUS.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSplitLayoutQwertyEnglishUS.java new file mode 100644 index 000000000..75385f643 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSplitLayoutQwertyEnglishUS.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.KeyboardLayoutSet; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EnglishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * en_US: English (United States)/qwerty - split layout + */ +@SmallTest +public class TestsSplitLayoutQwertyEnglishUS extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishSplitCustomizer(LOCALE)); + + @Override + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { + return super.createKeyboardLayoutSet(subtype, editorInfo, voiceInputKeyEnabled, + languageSwitchKeyEnabled, true /* splitLayoutEnabled */); + } + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class EnglishSplitCustomizer extends EnglishCustomizer { + EnglishSplitCustomizer(Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + if (isPhone) { + return super.getSpaceKeys(isPhone); + } + return joinKeys(LANGUAGE_SWITCH_KEY, SPACE_KEY, SPACE_KEY); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwahili.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwahili.java new file mode 100644 index 000000000..1ef382572 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwahili.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sw: Swahili/qwerty + */ +@SmallTest +public final class TestsSwahili extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sw"); + private static final LayoutBase LAYOUT = new Qwerty(new SwahiliCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SwahiliCustomizer extends LayoutCustomizer { + SwahiliCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", "\u00E8", "\u00E9", "\u00EA", "\u00EB", "\u0113") + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FB", "\u00FC", "\u00F9", "\u00FA", "\u016B") + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + .setMoreKeysOf("i", "\u00EE", "\u00EF", "\u00ED", "\u012B", "\u00EC") + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + .setMoreKeysOf("o", + "\u00F4", "\u00F6", "\u00F2", "\u00F3", "\u0153", "\u00F8", "\u014D", + "\u00F5") + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", + "\u00E0", "\u00E1", "\u00E2", "\u00E4", "\u00E6", "\u00E3", "\u00E5", + "\u0101") + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + .setMoreKeysOf("s", "\u00DF") + .setMoreKeysOf("g", "g'") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + .setMoreKeysOf("c", "\u00E7") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + .setMoreKeysOf("n", "\u00F1"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwedish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwedish.java new file mode 100644 index 000000000..faf9be6dc --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwedish.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Nordic; +import org.kelar.inputmethod.keyboard.layout.customizer.SwedishCustomizer; + +import java.util.Locale; + +/** + * sv: Swedish/nordic + */ +@SmallTest +public final class TestsSwedish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sv"); + private static final LayoutBase LAYOUT = new Nordic(new SwedishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwedishPcQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwedishPcQwerty.java new file mode 100644 index 000000000..b1cb06d60 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsSwedishPcQwerty.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.PcQwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.PcQwertyCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.SwedishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sv: Swedish/pcqwerty + */ +@SmallTest +public final class TestsSwedishPcQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sv"); + private static final LayoutBase LAYOUT = new PcQwerty(new SwedishPcQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SwedishPcQwertyCustomizer extends SwedishCustomizer { + private final LayoutCustomizer mPcQwertyCustomizer; + + SwedishPcQwertyCustomizer(final Locale locale) { + super(locale); + mPcQwertyCustomizer = new PcQwertyCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { + return mPcQwertyCustomizer.getCurrencyKey(); + } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mPcQwertyCustomizer.getOtherCurrencyKeys(); + } + + @Override + public int getNumberOfRows() { + return mPcQwertyCustomizer.getNumberOfRows(); + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return mPcQwertyCustomizer.getLeftShiftKeys(isPhone); + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return mPcQwertyCustomizer.getRightShiftKeys(isPhone); + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + return mPcQwertyCustomizer.getKeysLeftToSpacebar(isPhone); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + return mPcQwertyCustomizer.getKeysRightToSpacebar(isPhone); + } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // PC QWERTY layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + .setMoreKeysOf("a", "\u00E4", "\u00E5", "\u00E6", "\u00E1", "\u00E0", "\u00E2", + "\u0105", "\u00E3"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F8", "\u0153", "\u00F3", "\u00F2", "\u00F4", + "\u00F5", "\u014D"); + } + + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTagalog.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTagalog.java new file mode 100644 index 000000000..bd4956b8f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTagalog.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Spanish; +import org.kelar.inputmethod.keyboard.layout.customizer.SpanishCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * tl: Tagalog/spanish + */ +@SmallTest +public class TestsTagalog extends TestsSpanish { + private static final Locale LOCALE = new Locale("tl"); + private static final LayoutBase LAYOUT = new Spanish(new TagalogCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class TagalogCustomizer extends SpanishCustomizer { + TagalogCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getPunctuationMoreKeys(final boolean isPhone) { + return isPhone ? PHONE_PUNCTUATION_MORE_KEYS : TABLET_PUNCTUATION_MORE_KEYS; + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilIN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilIN.java new file mode 100644 index 000000000..02656aea2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilIN.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.Tamil; +import org.kelar.inputmethod.keyboard.layout.customizer.TamilCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * ta_IN: Tamil (India)/tamil + */ +@SmallTest +public final class TestsTamilIN extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ta", "IN"); + private static final LayoutBase LAYOUT = new Tamil(new TamilINCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class TamilINCustomizer extends TamilCustomizer { + TamilINCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilLK.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilLK.java new file mode 100644 index 000000000..dc3c16cee --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilLK.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.Suppress; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.Tamil; +import org.kelar.inputmethod.keyboard.layout.customizer.TamilCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * ta_LK: Tamil (Sri Lanka)/tamil + */ +@Suppress +public final class TestsTamilLK extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ta", "LK"); + private static final LayoutBase LAYOUT = new Tamil(new TamilLKCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class TamilLKCustomizer extends TamilCustomizer { + TamilLKCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + // U+0DBB/U+0DD4: "රු" SINHALA LETTER RAYANNA/SINHALA VOWEL SIGN KETTI PAA-PILLA + private static final ExpectedKey CURRENCY_RUPEE = key("\u0DBB\u0DD4", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilSG.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilSG.java new file mode 100644 index 000000000..8bd34fbfd --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTamilSG.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Tamil; +import org.kelar.inputmethod.keyboard.layout.customizer.TamilCustomizer; + +import java.util.Locale; + +/** + * ta_SG: Tamil (Singapore)/tamil + */ +@SmallTest +public final class TestsTamilSG extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("ta", "SG"); + private static final LayoutBase LAYOUT = new Tamil(new TamilCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTeluguIN.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTeluguIN.java new file mode 100644 index 000000000..eda1895f6 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTeluguIN.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Telugu; + +import java.util.Locale; + +/** + * te_IN: Telugu (India)/telugu + */ +@SmallTest +public final class TestsTeluguIN extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("te", "IN"); + private static final LayoutBase LAYOUT = new Telugu(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsThai.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsThai.java new file mode 100644 index 000000000..95475956a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsThai.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Thai; + +import java.util.Locale; + +/** + * th: Thai/thai + */ +@SmallTest +public final class TestsThai extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("th"); + private static final LayoutBase LAYOUT = new Thai(LOCALE); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTurkish.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTurkish.java new file mode 100644 index 000000000..511dca380 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsTurkish.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EuroCustomizer; +import org.kelar.inputmethod.keyboard.layout.customizer.TurkicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * tr: Turkish/qwerty + */ +@SmallTest +public final class TestsTurkish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("tr"); + private static final LayoutBase LAYOUT = new Qwerty(new TurkishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class TurkishCustomizer extends EuroCustomizer { + private final TurkicCustomizer mTurkicCustomizer; + + TurkishCustomizer(final Locale locale) { + super(locale); + mTurkicCustomizer = new TurkicCustomizer(locale); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return mTurkicCustomizer.setAccentedLetters(builder); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUkrainian.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUkrainian.java new file mode 100644 index 000000000..60fc97f29 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUkrainian.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.EastSlavic; +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.EastSlavicCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * uk: Ukrainian/east_slavic + */ +@SmallTest +public final class TestsUkrainian extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("uk"); + private static final LayoutBase LAYOUT = new EastSlavic(new UkrainianCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class UkrainianCustomizer extends EastSlavicCustomizer { + UkrainianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_HRYVNIA; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + // U+20B4: "₴" HRYVNIA SIGN + private static final ExpectedKey CURRENCY_HRYVNIA = key("\u20B4", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0433: "г" CYRILLIC SMALL LETTER GHE + // U+0491: "ґ" CYRILLIC SMALL LETTER GHE WITH UPTURN + .setMoreKeysOf("\u0433", "\u0491") + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + .replaceKeyOfLabel(EastSlavic.ROW1_9, key("\u0449", additionalMoreKey("9"))) + // U+0456: "і" CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I + // U+0457: "ї" CYRILLIC SMALL LETTER YI + .replaceKeyOfLabel(EastSlavic.ROW2_2, key("\u0456", moreKey("\u0457"))) + // U+0454: "є" CYRILLIC SMALL LETTER UKRAINIAN IE + .replaceKeyOfLabel(EastSlavic.ROW2_11, "\u0454") + // U+0438: "и" CYRILLIC SMALL LETTER I + .replaceKeyOfLabel(EastSlavic.ROW3_5, "\u0438") + // U+044C: "ь" CYRILLIC SMALL LETTER SOFT SIGN + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + .setMoreKeysOf("\u044C", "\u044A"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUzbek.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUzbek.java new file mode 100644 index 000000000..ad9ab8762 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUzbek.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Uzbek; +import org.kelar.inputmethod.keyboard.layout.customizer.UzbekCustomizer; + +import java.util.Locale; + +/** + * uz_UZ: Uzbek (Uzbekistan)/uzbek + */ +@SmallTest +public final class TestsUzbek extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("uz", "UZ"); + private static final LayoutBase LAYOUT = new Uzbek(new UzbekCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUzbekQwerty.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUzbekQwerty.java new file mode 100644 index 000000000..e795a5ed6 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsUzbekQwerty.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.UzbekCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * uz_UZ: Uzbek (Uzbekistan)/qwerty + */ +@SmallTest +public final class TestsUzbekQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("uz", "UZ"); + private static final LayoutBase LAYOUT = new Qwerty(new UzbekQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class UzbekQwertyCustomizer extends UzbekCustomizer { + UzbekQwertyCustomizer(final Locale locale) { super(locale); } + + @Override + protected void setUzbekKeys(final ExpectedKeyboardBuilder builder) { + // QWERTY layout doesn't have Uzebk keys. + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsVietnamese.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsVietnamese.java new file mode 100644 index 000000000..91e50dfd5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsVietnamese.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.Symbols; +import org.kelar.inputmethod.keyboard.layout.SymbolsShifted; +import org.kelar.inputmethod.keyboard.layout.customizer.LayoutCustomizer; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKey; +import org.kelar.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * vi: Vietnamese/qwerty + */ +@SmallTest +public final class TestsVietnamese extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("vi"); + private static final LayoutBase LAYOUT = new Qwerty(new VietnameseCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class VietnameseCustomizer extends LayoutCustomizer { + VietnameseCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_DONG; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + // U+20AB: "₫" DONG SIGN + private static final ExpectedKey CURRENCY_DONG = key("\u20AB", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+1EBB: "ẻ" LATIN SMALL LETTER E WITH HOOK ABOVE + // U+1EBD: "ẽ" LATIN SMALL LETTER E WITH TILDE + // U+1EB9: "ẹ" LATIN SMALL LETTER E WITH DOT BELOW + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+1EC1: "ề" LATIN SMALL LETTER E WITH CIRCUMFLEX AND GRAVE + // U+1EBF: "ế" LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE + // U+1EC3: "ể" LATIN SMALL LETTER E WITH CIRCUMFLEX AND HOOK ABOVE + // U+1EC5: "ễ" LATIN SMALL LETTER E WITH CIRCUMFLEX AND TILDE + // U+1EC7: "ệ" LATIN SMALL LETTER E WITH CIRCUMFLEX AND DOT BELOW + .setMoreKeysOf("e", + "\u00E8", "\u00E9", "\u1EBB", "\u1EBD", "\u1EB9", "\u00EA", "\u1EC1", + "\u1EBF", "\u1EC3", "\u1EC5", "\u1EC7") + // U+1EF3: "ỳ" LATIN SMALL LETTER Y WITH GRAVE + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+1EF7: "ỷ" LATIN SMALL LETTER Y WITH HOOK ABOVE + // U+1EF9: "ỹ" LATIN SMALL LETTER Y WITH TILDE + // U+1EF5: "ỵ" LATIN SMALL LETTER Y WITH DOT BELOW + .setMoreKeysOf("y", "\u1EF3", "\u00FD", "\u1EF7", "\u1EF9", "\u1EF5") + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+1EE7: "ủ" LATIN SMALL LETTER U WITH HOOK ABOVE + // U+0169: "ũ" LATIN SMALL LETTER U WITH TILDE + // U+1EE5: "ụ" LATIN SMALL LETTER U WITH DOT BELOW + // U+01B0: "ư" LATIN SMALL LETTER U WITH HORN + // U+1EEB: "ừ" LATIN SMALL LETTER U WITH HORN AND GRAVE + // U+1EE9: "ứ" LATIN SMALL LETTER U WITH HORN AND ACUTE + // U+1EED: "ử" LATIN SMALL LETTER U WITH HORN AND HOOK ABOVE + // U+1EEF: "ữ" LATIN SMALL LETTER U WITH HORN AND TILDE + // U+1EF1: "ự" LATIN SMALL LETTER U WITH HORN AND DOT BELOW + .setMoreKeysOf("u", + "\u00F9", "\u00FA", "\u1EE7", "\u0169", "\u1EE5", "\u01B0", "\u1EEB", + "\u1EE9", "\u1EED", "\u1EEF", "\u1EF1") + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+1EC9: "ỉ" LATIN SMALL LETTER I WITH HOOK ABOVE + // U+0129: "ĩ" LATIN SMALL LETTER I WITH TILDE + // U+1ECB: "ị" LATIN SMALL LETTER I WITH DOT BELOW + .setMoreKeysOf("i", "\u00EC", "\u00ED", "\u1EC9", "\u0129", "\u1ECB") + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+1ECF: "ỏ" LATIN SMALL LETTER O WITH HOOK ABOVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+1ECD: "ọ" LATIN SMALL LETTER O WITH DOT BELOW + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+1ED3: "ồ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND GRAVE + // U+1ED1: "ố" LATIN SMALL LETTER O WITH CIRCUMFLEX AND ACUTE + // U+1ED5: "ổ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND HOOK ABOVE + // U+1ED7: "ỗ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND TILDE + // U+1ED9: "ộ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND DOT BELOW + // U+01A1: "ơ" LATIN SMALL LETTER O WITH HORN + // U+1EDD: "ờ" LATIN SMALL LETTER O WITH HORN AND GRAVE + // U+1EDB: "ớ" LATIN SMALL LETTER O WITH HORN AND ACUTE + // U+1EDF: "ở" LATIN SMALL LETTER O WITH HORN AND HOOK ABOVE + // U+1EE1: "ỡ" LATIN SMALL LETTER O WITH HORN AND TILDE + // U+1EE3: "ợ" LATIN SMALL LETTER O WITH HORN AND DOT BELOW + .setMoreKeysOf("o", + "\u00F2", "\u00F3", "\u1ECF", "\u00F5", "\u1ECD", "\u00F4", "\u1ED3", + "\u1ED1", "\u1ED5", "\u1ED7", "\u1ED9", "\u01A1", "\u1EDD", "\u1EDB", + "\u1EDF", "\u1EE1", "\u1EE3") + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+1EA3: "ả" LATIN SMALL LETTER A WITH HOOK ABOVE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+1EA1: "ạ" LATIN SMALL LETTER A WITH DOT BELOW + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE + // U+1EB1: "ằ" LATIN SMALL LETTER A WITH BREVE AND GRAVE + // U+1EAF: "ắ" LATIN SMALL LETTER A WITH BREVE AND ACUTE + // U+1EB3: "ẳ" LATIN SMALL LETTER A WITH BREVE AND HOOK ABOVE + // U+1EB5: "ẵ" LATIN SMALL LETTER A WITH BREVE AND TILDE + // U+1EB7: "ặ" LATIN SMALL LETTER A WITH BREVE AND DOT BELOW + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+1EA7: "ầ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND GRAVE + // U+1EA5: "ấ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND ACUTE + // U+1EA9: "ẩ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND HOOK ABOVE + // U+1EAB: "ẫ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND TILDE + // U+1EAD: "ậ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND DOT BELOW + .setMoreKeysOf("a", + "\u00E0", "\u00E1", "\u1EA3", "\u00E3", "\u1EA1", "\u0103", "\u1EB1", + "\u1EAF", "\u1EB3", "\u1EB5", "\u1EB7", "\u00E2", "\u1EA7", "\u1EA5", + "\u1EA9", "\u1EAB", "\u1EAD") + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .setMoreKeysOf("d", "\u0111"); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsZulu.java b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsZulu.java new file mode 100644 index 000000000..d745d9956 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/keyboard/layout/tests/TestsZulu.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.keyboard.layout.tests; + +import androidx.test.filters.SmallTest; + +import org.kelar.inputmethod.keyboard.layout.LayoutBase; +import org.kelar.inputmethod.keyboard.layout.Qwerty; +import org.kelar.inputmethod.keyboard.layout.customizer.EnglishCustomizer; + +import java.util.Locale; + +/** + * zu: Zulu/qwerty + */ +@SmallTest +public final class TestsZulu extends TestsEnglishUS { + private static final Locale LOCALE = new Locale("zu"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/org/kelar/inputmethod/latin/AppWorkaroundsTests.java b/tests/src/org/kelar/inputmethod/latin/AppWorkaroundsTests.java new file mode 100644 index 000000000..038b38735 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/AppWorkaroundsTests.java @@ -0,0 +1,75 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.Build.VERSION_CODES; +import android.view.inputmethod.EditorInfo; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.settings.Settings; + +@LargeTest +public class AppWorkaroundsTests extends InputTestsBase { + String packageNameOfAppBeforeJellyBean; + String packageNameOfAppAfterJellyBean; + + @Override + protected void setUp() throws Exception { + // NOTE: this will fail if there is no app installed that targets an SDK + // before Jelly Bean. For the moment, it's fine. + final PackageManager pm = getContext().getPackageManager(); + for (ApplicationInfo ai : pm.getInstalledApplications(0 /* flags */)) { + if (ai.targetSdkVersion < VERSION_CODES.JELLY_BEAN) { + packageNameOfAppBeforeJellyBean = ai.packageName; + } else { + packageNameOfAppAfterJellyBean = ai.packageName; + } + } + super.setUp(); + } + + // We want to test if the app package info is correctly retrieved by LatinIME. Since it + // asks this information to the package manager from the package name, and that it takes + // the package name from the EditorInfo, all we have to do it put the correct package + // name in the editor info. + // To this end, our base class InputTestsBase offers a hook for us to touch the EditorInfo. + // We override this hook to write the package name that we need. + @Override + protected EditorInfo enrichEditorInfo(final EditorInfo ei) { + if ("testBeforeJellyBeanTrue".equals(getName())) { + ei.packageName = packageNameOfAppBeforeJellyBean; + } else if ("testBeforeJellyBeanFalse".equals(getName())) { + ei.packageName = packageNameOfAppAfterJellyBean; + } + return ei; + } + + public void testBeforeJellyBeanTrue() { + assertTrue("Couldn't successfully detect this app targets < Jelly Bean (package is " + + packageNameOfAppBeforeJellyBean + ")", + Settings.getInstance().getCurrent().isBeforeJellyBean()); + } + + public void testBeforeJellyBeanFalse() { + assertFalse("Couldn't successfully detect this app targets >= Jelly Bean (package is " + + packageNameOfAppAfterJellyBean + ")", + Settings.getInstance().getCurrent().isBeforeJellyBean()); + } +}
\ No newline at end of file diff --git a/tests/src/org/kelar/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/org/kelar/inputmethod/latin/BinaryDictionaryTests.java new file mode 100644 index 000000000..a44c0bce7 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/BinaryDictionaryTests.java @@ -0,0 +1,913 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import android.text.TextUtils; +import android.util.Pair; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.NgramContext.WordInfo; +import org.kelar.inputmethod.latin.common.CodePointUtils; +import org.kelar.inputmethod.latin.common.FileUtils; +import org.kelar.inputmethod.latin.makedict.DictionaryHeader; +import org.kelar.inputmethod.latin.makedict.FormatSpec; +import org.kelar.inputmethod.latin.makedict.WeightedString; +import org.kelar.inputmethod.latin.makedict.WordProperty; +import org.kelar.inputmethod.latin.utils.BinaryDictionaryUtils; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Random; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class BinaryDictionaryTests { + private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; + private static final String TEST_LOCALE = "test"; + private static final String DICTIONARY_ID = "TestBinaryDictionary"; + + private HashSet<File> mDictFilesToBeDeleted = new HashSet<>(); + + @Before + public void setUp() throws Exception { + mDictFilesToBeDeleted.clear(); + } + + @After + public void tearDown() throws Exception { + for (final File dictFile : mDictFilesToBeDeleted) { + dictFile.delete(); + } + mDictFilesToBeDeleted.clear(); + } + + private File createEmptyDictionaryAndGetFile(final int formatVersion) { + return createEmptyDictionaryWithAttributesAndGetFile(formatVersion, + new HashMap<String, String>()); + } + + private File createEmptyDictionaryWithAttributesAndGetFile(final int formatVersion, + final HashMap<String, String> attributeMap) { + try { + final File dictFile = createEmptyVer4DictionaryAndGetFile(formatVersion, + attributeMap); + mDictFilesToBeDeleted.add(dictFile); + return dictFile; + } catch (final IOException e) { + fail(e.toString()); + } + return null; + } + + private File createEmptyVer4DictionaryAndGetFile(final int formatVersion, + final HashMap<String, String> attributeMap) throws IOException { + final File file = File.createTempFile(DICTIONARY_ID, TEST_DICT_FILE_EXTENSION, + InstrumentationRegistry.getTargetContext().getCacheDir()); + file.delete(); + file.mkdir(); + if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), formatVersion, + Locale.ENGLISH, attributeMap)) { + return file; + } + throw new IOException("Empty dictionary " + file.getAbsolutePath() + + " cannot be created. Format version: " + formatVersion); + } + + private static BinaryDictionary getBinaryDictionary(final File dictFile) { + return new BinaryDictionary(dictFile.getAbsolutePath(), + 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, + Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); + } + + private BinaryDictionary getEmptyBinaryDictionary(final int formatVersion) { + final File dictFile = createEmptyDictionaryAndGetFile(formatVersion); + return new BinaryDictionary(dictFile.getAbsolutePath(), + 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, + Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); + } + + @Test + public void testIsValidDictionary() { + final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); + BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); + assertTrue("binaryDictionary must be valid for existing valid dictionary file.", + binaryDictionary.isValidDictionary()); + binaryDictionary.close(); + assertFalse("binaryDictionary must be invalid after closing.", + binaryDictionary.isValidDictionary()); + FileUtils.deleteRecursively(dictFile); + binaryDictionary = getBinaryDictionary(dictFile); + assertFalse("binaryDictionary must be invalid for not existing dictionary file.", + binaryDictionary.isValidDictionary()); + binaryDictionary.close(); + } + + @Test + public void testConstructingDictionaryOnMemory() { + final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); + FileUtils.deleteRecursively(dictFile); + assertFalse(dictFile.exists()); + final BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(), + true /* useFullEditDistance */, Locale.getDefault(), TEST_LOCALE, + FormatSpec.VERSION403, new HashMap<String, String>()); + assertTrue(binaryDictionary.isValidDictionary()); + assertEquals(FormatSpec.VERSION403, binaryDictionary.getFormatVersion()); + final int probability = 100; + addUnigramWord(binaryDictionary, "word", probability); + assertEquals(probability, binaryDictionary.getFrequency("word")); + assertFalse(dictFile.exists()); + binaryDictionary.flush(); + assertTrue(dictFile.exists()); + assertTrue(binaryDictionary.isValidDictionary()); + assertEquals(FormatSpec.VERSION403, binaryDictionary.getFormatVersion()); + assertEquals(probability, binaryDictionary.getFrequency("word")); + binaryDictionary.close(); + } + + @Test + public void testAddTooLongWord() { + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + final StringBuffer stringBuilder = new StringBuffer(); + for (int i = 0; i < BinaryDictionary.DICTIONARY_MAX_WORD_LENGTH; i++) { + stringBuilder.append('a'); + } + final String validLongWord = stringBuilder.toString(); + stringBuilder.append('a'); + final String invalidLongWord = stringBuilder.toString(); + final int probability = 100; + addUnigramWord(binaryDictionary, "aaa", probability); + addUnigramWord(binaryDictionary, validLongWord, probability); + addUnigramWord(binaryDictionary, invalidLongWord, probability); + // Too long short cut. + binaryDictionary.addUnigramEntry("a", probability, false /* isBeginningOfSentence */, + false /* isNotAWord */, false /* isPossiblyOffensive */, + BinaryDictionary.NOT_A_VALID_TIMESTAMP); + addUnigramWord(binaryDictionary, "abc", probability); + final int updatedProbability = 200; + // Update. + addUnigramWord(binaryDictionary, validLongWord, updatedProbability); + addUnigramWord(binaryDictionary, invalidLongWord, updatedProbability); + addUnigramWord(binaryDictionary, "abc", updatedProbability); + + assertEquals(probability, binaryDictionary.getFrequency("aaa")); + assertEquals(updatedProbability, binaryDictionary.getFrequency(validLongWord)); + assertEquals(Dictionary.NOT_A_PROBABILITY, binaryDictionary.getFrequency(invalidLongWord)); + assertEquals(updatedProbability, binaryDictionary.getFrequency("abc")); + } + + private static void addUnigramWord(final BinaryDictionary binaryDictionary, final String word, + final int probability) { + binaryDictionary.addUnigramEntry(word, probability, + false /* isBeginningOfSentence */, false /* isNotAWord */, + false /* isPossiblyOffensive */, + BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); + } + + private static void addBigramWords(final BinaryDictionary binaryDictionary, final String word0, + final String word1, final int probability) { + binaryDictionary.addNgramEntry(new NgramContext(new WordInfo(word0)), word1, probability, + BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); + } + + private static void addTrigramEntry(final BinaryDictionary binaryDictionary, final String word0, + final String word1, final String word2, final int probability) { + binaryDictionary.addNgramEntry( + new NgramContext(new WordInfo(word1), new WordInfo(word0)), word2, + probability, BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); + } + + private static boolean isValidBigram(final BinaryDictionary binaryDictionary, + final String word0, final String word1) { + return binaryDictionary.isValidNgram(new NgramContext(new WordInfo(word0)), word1); + } + + private static int getBigramProbability(final BinaryDictionary binaryDictionary, + final String word0, final String word1) { + return binaryDictionary.getNgramProbability(new NgramContext(new WordInfo(word0)), word1); + } + + private static int getTrigramProbability(final BinaryDictionary binaryDictionary, + final String word0, final String word1, final String word2) { + return binaryDictionary.getNgramProbability( + new NgramContext(new WordInfo(word1), new WordInfo(word0)), word2); + } + + @Test + public void testAddUnigramWord() { + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + final int probability = 100; + addUnigramWord(binaryDictionary, "aaa", probability); + // Reallocate and create. + addUnigramWord(binaryDictionary, "aab", probability); + // Insert into children. + addUnigramWord(binaryDictionary, "aac", probability); + // Make terminal. + addUnigramWord(binaryDictionary, "aa", probability); + // Create children. + addUnigramWord(binaryDictionary, "aaaa", probability); + // Reallocate and make termianl. + addUnigramWord(binaryDictionary, "a", probability); + + final int updatedProbability = 200; + // Update. + addUnigramWord(binaryDictionary, "aaa", updatedProbability); + + assertEquals(probability, binaryDictionary.getFrequency("aab")); + assertEquals(probability, binaryDictionary.getFrequency("aac")); + assertEquals(probability, binaryDictionary.getFrequency("aa")); + assertEquals(probability, binaryDictionary.getFrequency("aaaa")); + assertEquals(probability, binaryDictionary.getFrequency("a")); + assertEquals(updatedProbability, binaryDictionary.getFrequency("aaa")); + } + + @Test + public void testRandomlyAddUnigramWord() { + final int wordCount = 1000; + final int codePointSetSize = 50; + final long seed = System.currentTimeMillis(); + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + + final HashMap<String, Integer> probabilityMap = new HashMap<>(); + // Test a word that isn't contained within the dictionary. + final Random random = new Random(seed); + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + for (int i = 0; i < wordCount; ++i) { + final String word = CodePointUtils.generateWord(random, codePointSet); + probabilityMap.put(word, random.nextInt(0xFF)); + } + for (String word : probabilityMap.keySet()) { + addUnigramWord(binaryDictionary, word, probabilityMap.get(word)); + } + for (String word : probabilityMap.keySet()) { + assertEquals(word, (int)probabilityMap.get(word), binaryDictionary.getFrequency(word)); + } + } + + @Test + public void testAddBigramWords() { + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + + final int unigramProbability = 100; + final int bigramProbability = 150; + final int updatedBigramProbability = 200; + addUnigramWord(binaryDictionary, "aaa", unigramProbability); + addUnigramWord(binaryDictionary, "abb", unigramProbability); + addUnigramWord(binaryDictionary, "bcc", unigramProbability); + addBigramWords(binaryDictionary, "aaa", "abb", bigramProbability); + addBigramWords(binaryDictionary, "aaa", "bcc", bigramProbability); + addBigramWords(binaryDictionary, "abb", "aaa", bigramProbability); + addBigramWords(binaryDictionary, "abb", "bcc", bigramProbability); + + assertTrue(isValidBigram(binaryDictionary, "aaa", "abb")); + assertTrue(isValidBigram(binaryDictionary, "aaa", "bcc")); + assertTrue(isValidBigram(binaryDictionary, "abb", "aaa")); + assertTrue(isValidBigram(binaryDictionary, "abb", "bcc")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "aaa", "abb")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "aaa", "bcc")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "abb", "aaa")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "abb", "bcc")); + + addBigramWords(binaryDictionary, "aaa", "abb", updatedBigramProbability); + assertEquals(updatedBigramProbability, + getBigramProbability(binaryDictionary, "aaa", "abb")); + + assertFalse(isValidBigram(binaryDictionary, "bcc", "aaa")); + assertFalse(isValidBigram(binaryDictionary, "bcc", "bbc")); + assertFalse(isValidBigram(binaryDictionary, "aaa", "aaa")); + assertEquals(Dictionary.NOT_A_PROBABILITY, + getBigramProbability(binaryDictionary, "bcc", "aaa")); + assertEquals(Dictionary.NOT_A_PROBABILITY, + getBigramProbability(binaryDictionary, "bcc", "bbc")); + assertEquals(Dictionary.NOT_A_PROBABILITY, + getBigramProbability(binaryDictionary, "aaa", "aaa")); + + // Testing bigram link. + addUnigramWord(binaryDictionary, "abcde", unigramProbability); + addUnigramWord(binaryDictionary, "fghij", unigramProbability); + addBigramWords(binaryDictionary, "abcde", "fghij", bigramProbability); + addUnigramWord(binaryDictionary, "fgh", unigramProbability); + addUnigramWord(binaryDictionary, "abc", unigramProbability); + addUnigramWord(binaryDictionary, "f", unigramProbability); + + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "abcde", "fghij")); + assertEquals(Dictionary.NOT_A_PROBABILITY, + getBigramProbability(binaryDictionary, "abcde", "fgh")); + addBigramWords(binaryDictionary, "abcde", "fghij", updatedBigramProbability); + assertEquals(updatedBigramProbability, + getBigramProbability(binaryDictionary, "abcde", "fghij")); + } + + @Test + public void testRandomlyAddBigramWords() { + final int wordCount = 100; + final int bigramCount = 1000; + final int codePointSetSize = 50; + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + + final ArrayList<String> words = new ArrayList<>(); + final ArrayList<Pair<String, String>> bigramWords = new ArrayList<>(); + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + final HashMap<String, Integer> unigramProbabilities = new HashMap<>(); + final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>(); + + for (int i = 0; i < wordCount; ++i) { + final String word = CodePointUtils.generateWord(random, codePointSet); + words.add(word); + final int unigramProbability = random.nextInt(0xFF); + unigramProbabilities.put(word, unigramProbability); + addUnigramWord(binaryDictionary, word, unigramProbability); + } + + for (int i = 0; i < bigramCount; i++) { + final String word0 = words.get(random.nextInt(wordCount)); + final String word1 = words.get(random.nextInt(wordCount)); + if (TextUtils.equals(word0, word1)) { + continue; + } + final Pair<String, String> bigram = new Pair<>(word0, word1); + bigramWords.add(bigram); + final int unigramProbability = unigramProbabilities.get(word1); + final int bigramProbability = + unigramProbability + random.nextInt(0xFF - unigramProbability); + bigramProbabilities.put(bigram, bigramProbability); + addBigramWords(binaryDictionary, word0, word1, bigramProbability); + } + + for (final Pair<String, String> bigram : bigramWords) { + final int bigramProbability = bigramProbabilities.get(bigram); + assertEquals(bigramProbability != Dictionary.NOT_A_PROBABILITY, + isValidBigram(binaryDictionary, bigram.first, bigram.second)); + assertEquals(bigramProbability, + getBigramProbability(binaryDictionary, bigram.first, bigram.second)); + } + } + + @Test + public void testAddTrigramWords() { + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + final int unigramProbability = 100; + final int trigramProbability = 150; + final int updatedTrigramProbability = 200; + addUnigramWord(binaryDictionary, "aaa", unigramProbability); + addUnigramWord(binaryDictionary, "abb", unigramProbability); + addUnigramWord(binaryDictionary, "bcc", unigramProbability); + + addBigramWords(binaryDictionary, "abb", "bcc", 10); + addBigramWords(binaryDictionary, "abb", "aaa", 10); + + addTrigramEntry(binaryDictionary, "aaa", "abb", "bcc", trigramProbability); + addTrigramEntry(binaryDictionary, "bcc", "abb", "aaa", trigramProbability); + + assertEquals(trigramProbability, + getTrigramProbability(binaryDictionary, "aaa", "abb", "bcc")); + assertEquals(trigramProbability, + getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa")); + assertFalse(isValidBigram(binaryDictionary, "aaa", "abb")); + + addTrigramEntry(binaryDictionary, "bcc", "abb", "aaa", updatedTrigramProbability); + assertEquals(updatedTrigramProbability, + getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa")); + } + + @Test + public void testFlushDictionary() { + final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); + BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); + + final int probability = 100; + addUnigramWord(binaryDictionary, "aaa", probability); + addUnigramWord(binaryDictionary, "abcd", probability); + // Close without flushing. + binaryDictionary.close(); + + binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(), + 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, + Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); + + assertEquals(Dictionary.NOT_A_PROBABILITY, binaryDictionary.getFrequency("aaa")); + assertEquals(Dictionary.NOT_A_PROBABILITY, binaryDictionary.getFrequency("abcd")); + + addUnigramWord(binaryDictionary, "aaa", probability); + addUnigramWord(binaryDictionary, "abcd", probability); + binaryDictionary.flush(); + binaryDictionary.close(); + + binaryDictionary = getBinaryDictionary(dictFile); + assertEquals(probability, binaryDictionary.getFrequency("aaa")); + assertEquals(probability, binaryDictionary.getFrequency("abcd")); + addUnigramWord(binaryDictionary, "bcde", probability); + binaryDictionary.flush(); + binaryDictionary.close(); + + binaryDictionary = getBinaryDictionary(dictFile); + assertEquals(probability, binaryDictionary.getFrequency("bcde")); + binaryDictionary.close(); + } + + @Test + public void testFlushWithGCDictionary() { + final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); + BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); + final int unigramProbability = 100; + final int bigramProbability = 150; + addUnigramWord(binaryDictionary, "aaa", unigramProbability); + addUnigramWord(binaryDictionary, "abb", unigramProbability); + addUnigramWord(binaryDictionary, "bcc", unigramProbability); + addBigramWords(binaryDictionary, "aaa", "abb", bigramProbability); + addBigramWords(binaryDictionary, "aaa", "bcc", bigramProbability); + addBigramWords(binaryDictionary, "abb", "aaa", bigramProbability); + addBigramWords(binaryDictionary, "abb", "bcc", bigramProbability); + binaryDictionary.flushWithGC(); + binaryDictionary.close(); + + binaryDictionary = getBinaryDictionary(dictFile); + assertEquals(unigramProbability, binaryDictionary.getFrequency("aaa")); + assertEquals(unigramProbability, binaryDictionary.getFrequency("abb")); + assertEquals(unigramProbability, binaryDictionary.getFrequency("bcc")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "aaa", "abb")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "aaa", "bcc")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "abb", "aaa")); + assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "abb", "bcc")); + assertFalse(isValidBigram(binaryDictionary, "bcc", "aaa")); + assertFalse(isValidBigram(binaryDictionary, "bcc", "bbc")); + assertFalse(isValidBigram(binaryDictionary, "aaa", "aaa")); + binaryDictionary.flushWithGC(); + binaryDictionary.close(); + } + + @Test + public void testAddBigramWordsAndFlashWithGC() { + final int wordCount = 100; + final int bigramCount = 1000; + final int codePointSetSize = 30; + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + + final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); + BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); + + final ArrayList<String> words = new ArrayList<>(); + final ArrayList<Pair<String, String>> bigramWords = new ArrayList<>(); + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + final HashMap<String, Integer> unigramProbabilities = new HashMap<>(); + final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>(); + + for (int i = 0; i < wordCount; ++i) { + final String word = CodePointUtils.generateWord(random, codePointSet); + words.add(word); + final int unigramProbability = random.nextInt(0xFF); + unigramProbabilities.put(word, unigramProbability); + addUnigramWord(binaryDictionary, word, unigramProbability); + } + + for (int i = 0; i < bigramCount; i++) { + final String word0 = words.get(random.nextInt(wordCount)); + final String word1 = words.get(random.nextInt(wordCount)); + if (TextUtils.equals(word0, word1)) { + continue; + } + final Pair<String, String> bigram = new Pair<>(word0, word1); + bigramWords.add(bigram); + final int unigramProbability = unigramProbabilities.get(word1); + final int bigramProbability = + unigramProbability + random.nextInt(0xFF - unigramProbability); + bigramProbabilities.put(bigram, bigramProbability); + addBigramWords(binaryDictionary, word0, word1, bigramProbability); + } + + binaryDictionary.flushWithGC(); + binaryDictionary.close(); + binaryDictionary = getBinaryDictionary(dictFile); + + for (final Pair<String, String> bigram : bigramWords) { + final int bigramProbability = bigramProbabilities.get(bigram); + assertEquals(bigramProbability != Dictionary.NOT_A_PROBABILITY, + isValidBigram(binaryDictionary, bigram.first, bigram.second)); + assertEquals(bigramProbability, + getBigramProbability(binaryDictionary, bigram.first, bigram.second)); + } + } + + @Test + public void testRandomOperationsAndFlashWithGC() { + final int maxUnigramCount = 5000; + final int maxBigramCount = 10000; + final HashMap<String, String> attributeMap = new HashMap<>(); + attributeMap.put(DictionaryHeader.MAX_UNIGRAM_COUNT_KEY, String.valueOf(maxUnigramCount)); + attributeMap.put(DictionaryHeader.MAX_BIGRAM_COUNT_KEY, String.valueOf(maxBigramCount)); + + final int flashWithGCIterationCount = 50; + final int operationCountInEachIteration = 200; + final int initialUnigramCount = 100; + final float addUnigramProb = 0.5f; + final float addBigramProb = 0.8f; + final int codePointSetSize = 30; + + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + final File dictFile = createEmptyDictionaryWithAttributesAndGetFile(FormatSpec.VERSION403, + attributeMap); + BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); + + final ArrayList<String> words = new ArrayList<>(); + final ArrayList<Pair<String, String>> bigramWords = new ArrayList<>(); + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + final HashMap<String, Integer> unigramProbabilities = new HashMap<>(); + final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>(); + for (int i = 0; i < initialUnigramCount; ++i) { + final String word = CodePointUtils.generateWord(random, codePointSet); + words.add(word); + final int unigramProbability = random.nextInt(0xFF); + unigramProbabilities.put(word, unigramProbability); + addUnigramWord(binaryDictionary, word, unigramProbability); + } + binaryDictionary.flushWithGC(); + binaryDictionary.close(); + + for (int gcCount = 0; gcCount < flashWithGCIterationCount; gcCount++) { + binaryDictionary = getBinaryDictionary(dictFile); + for (int opCount = 0; opCount < operationCountInEachIteration; opCount++) { + // Add unigram. + if (random.nextFloat() < addUnigramProb) { + final String word = CodePointUtils.generateWord(random, codePointSet); + words.add(word); + final int unigramProbability = random.nextInt(0xFF); + unigramProbabilities.put(word, unigramProbability); + addUnigramWord(binaryDictionary, word, unigramProbability); + } + // Add bigram. + if (random.nextFloat() < addBigramProb && words.size() > 2) { + final int word0Index = random.nextInt(words.size()); + int word1Index = random.nextInt(words.size() - 1); + if (word0Index <= word1Index) { + word1Index++; + } + final String word0 = words.get(word0Index); + final String word1 = words.get(word1Index); + if (TextUtils.equals(word0, word1)) { + continue; + } + final int unigramProbability = unigramProbabilities.get(word1); + final int bigramProbability = + unigramProbability + random.nextInt(0xFF - unigramProbability); + final Pair<String, String> bigram = new Pair<>(word0, word1); + bigramWords.add(bigram); + bigramProbabilities.put(bigram, bigramProbability); + addBigramWords(binaryDictionary, word0, word1, bigramProbability); + } + } + + // Test whether the all unigram operations are collectlly handled. + for (int i = 0; i < words.size(); i++) { + final String word = words.get(i); + final int unigramProbability = unigramProbabilities.get(word); + assertEquals(word, unigramProbability, binaryDictionary.getFrequency(word)); + } + // Test whether the all bigram operations are collectlly handled. + for (int i = 0; i < bigramWords.size(); i++) { + final Pair<String, String> bigram = bigramWords.get(i); + final int probability; + if (bigramProbabilities.containsKey(bigram)) { + probability = bigramProbabilities.get(bigram); + } else { + probability = Dictionary.NOT_A_PROBABILITY; + } + + assertEquals(probability, + getBigramProbability(binaryDictionary, bigram.first, bigram.second)); + assertEquals(probability != Dictionary.NOT_A_PROBABILITY, + isValidBigram(binaryDictionary, bigram.first, bigram.second)); + } + binaryDictionary.flushWithGC(); + binaryDictionary.close(); + } + } + + @Test + public void testAddManyUnigramsAndFlushWithGC() { + final int flashWithGCIterationCount = 3; + final int codePointSetSize = 50; + + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + + final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); + + final ArrayList<String> words = new ArrayList<>(); + final HashMap<String, Integer> unigramProbabilities = new HashMap<>(); + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + + BinaryDictionary binaryDictionary; + for (int i = 0; i < flashWithGCIterationCount; i++) { + binaryDictionary = getBinaryDictionary(dictFile); + while(!binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { + final String word = CodePointUtils.generateWord(random, codePointSet); + words.add(word); + final int unigramProbability = random.nextInt(0xFF); + unigramProbabilities.put(word, unigramProbability); + addUnigramWord(binaryDictionary, word, unigramProbability); + } + + for (int j = 0; j < words.size(); j++) { + final String word = words.get(j); + final int unigramProbability = unigramProbabilities.get(word); + assertEquals(word, unigramProbability, binaryDictionary.getFrequency(word)); + } + + binaryDictionary.flushWithGC(); + binaryDictionary.close(); + } + } + + @Test + public void testUnigramAndBigramCount() { + final int maxUnigramCount = 5000; + final int maxBigramCount = 10000; + final HashMap<String, String> attributeMap = new HashMap<>(); + attributeMap.put(DictionaryHeader.MAX_UNIGRAM_COUNT_KEY, String.valueOf(maxUnigramCount)); + attributeMap.put(DictionaryHeader.MAX_BIGRAM_COUNT_KEY, String.valueOf(maxBigramCount)); + + final int flashWithGCIterationCount = 10; + final int codePointSetSize = 50; + final int unigramCountPerIteration = 1000; + final int bigramCountPerIteration = 2000; + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + final File dictFile = createEmptyDictionaryWithAttributesAndGetFile(FormatSpec.VERSION403, + attributeMap); + + final ArrayList<String> words = new ArrayList<>(); + final HashSet<Pair<String, String>> bigrams = new HashSet<>(); + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + + BinaryDictionary binaryDictionary; + for (int i = 0; i < flashWithGCIterationCount; i++) { + binaryDictionary = getBinaryDictionary(dictFile); + for (int j = 0; j < unigramCountPerIteration; j++) { + final String word = CodePointUtils.generateWord(random, codePointSet); + words.add(word); + final int unigramProbability = random.nextInt(0xFF); + addUnigramWord(binaryDictionary, word, unigramProbability); + } + for (int j = 0; j < bigramCountPerIteration; j++) { + final String word0 = words.get(random.nextInt(words.size())); + final String word1 = words.get(random.nextInt(words.size())); + if (TextUtils.equals(word0, word1)) { + continue; + } + bigrams.add(new Pair<>(word0, word1)); + final int bigramProbability = random.nextInt(0xF); + addBigramWords(binaryDictionary, word0, word1, bigramProbability); + } + assertEquals(new HashSet<>(words).size(), Integer.parseInt( + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.UNIGRAM_COUNT_QUERY))); + assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt( + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.BIGRAM_COUNT_QUERY))); + binaryDictionary.flushWithGC(); + assertEquals(new HashSet<>(words).size(), Integer.parseInt( + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.UNIGRAM_COUNT_QUERY))); + assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt( + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.BIGRAM_COUNT_QUERY))); + binaryDictionary.close(); + } + } + + @Test + public void testGetWordProperties() { + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + final int UNIGRAM_COUNT = 1000; + final int BIGRAM_COUNT = 1000; + final int codePointSetSize = 20; + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); + final BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); + + final WordProperty invalidWordProperty = binaryDictionary.getWordProperty("dummyWord", + false /* isBeginningOfSentence */); + assertFalse(invalidWordProperty.isValid()); + + final ArrayList<String> words = new ArrayList<>(); + final HashMap<String, Integer> wordProbabilities = new HashMap<>(); + final HashMap<String, HashSet<String>> bigrams = new HashMap<>(); + final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>(); + + for (int i = 0; i < UNIGRAM_COUNT; i++) { + final String word = CodePointUtils.generateWord(random, codePointSet); + final int unigramProbability = random.nextInt(0xFF); + final boolean isNotAWord = random.nextBoolean(); + final boolean isPossiblyOffensive = random.nextBoolean(); + // TODO: Add tests for historical info. + binaryDictionary.addUnigramEntry(word, unigramProbability, + false /* isBeginningOfSentence */, isNotAWord, isPossiblyOffensive, + BinaryDictionary.NOT_A_VALID_TIMESTAMP); + if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) { + binaryDictionary.flushWithGC(); + } + words.add(word); + wordProbabilities.put(word, unigramProbability); + final WordProperty wordProperty = binaryDictionary.getWordProperty(word, + false /* isBeginningOfSentence */); + assertEquals(word, wordProperty.mWord); + assertTrue(wordProperty.isValid()); + assertEquals(isNotAWord, wordProperty.mIsNotAWord); + assertEquals(isPossiblyOffensive, wordProperty.mIsPossiblyOffensive); + assertEquals(false, wordProperty.mHasNgrams); + assertEquals(unigramProbability, wordProperty.mProbabilityInfo.mProbability); + } + + for (int i = 0; i < BIGRAM_COUNT; i++) { + final int word0Index = random.nextInt(wordProbabilities.size()); + final int word1Index = random.nextInt(wordProbabilities.size()); + if (word0Index == word1Index) { + continue; + } + final String word0 = words.get(word0Index); + final String word1 = words.get(word1Index); + final int unigramProbability = wordProbabilities.get(word1); + final int bigramProbability = + unigramProbability + random.nextInt(0xFF - unigramProbability); + addBigramWords(binaryDictionary, word0, word1, bigramProbability); + if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) { + binaryDictionary.flushWithGC(); + } + if (!bigrams.containsKey(word0)) { + final HashSet<String> bigramWord1s = new HashSet<>(); + bigrams.put(word0, bigramWord1s); + } + bigrams.get(word0).add(word1); + bigramProbabilities.put(new Pair<>(word0, word1), bigramProbability); + } + + for (int i = 0; i < words.size(); i++) { + final String word0 = words.get(i); + if (!bigrams.containsKey(word0)) { + continue; + } + final HashSet<String> bigramWord1s = bigrams.get(word0); + final WordProperty wordProperty = binaryDictionary.getWordProperty(word0, + false /* isBeginningOfSentence */); + assertEquals(bigramWord1s.size(), wordProperty.mNgrams.size()); + // TODO: Support ngram. + for (final WeightedString bigramTarget : wordProperty.getBigrams()) { + final String word1 = bigramTarget.mWord; + assertTrue(bigramWord1s.contains(word1)); + final int bigramProbability = bigramProbabilities.get(new Pair<>(word0, word1)); + assertEquals(bigramProbability, bigramTarget.getProbability()); + } + } + } + + @Test + public void testIterateAllWords() { + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + final int UNIGRAM_COUNT = 1000; + final int BIGRAM_COUNT = 1000; + final int codePointSetSize = 20; + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + + final WordProperty invalidWordProperty = binaryDictionary.getWordProperty("dummyWord", + false /* isBeginningOfSentence */); + assertFalse(invalidWordProperty.isValid()); + + final ArrayList<String> words = new ArrayList<>(); + final HashMap<String, Integer> wordProbabilitiesToCheckLater = new HashMap<>(); + final HashMap<String, HashSet<String>> bigrams = new HashMap<>(); + final HashMap<Pair<String, String>, Integer> bigramProbabilitiesToCheckLater = + new HashMap<>(); + + for (int i = 0; i < UNIGRAM_COUNT; i++) { + final String word = CodePointUtils.generateWord(random, codePointSet); + final int unigramProbability = random.nextInt(0xFF); + addUnigramWord(binaryDictionary, word, unigramProbability); + if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) { + binaryDictionary.flushWithGC(); + } + words.add(word); + wordProbabilitiesToCheckLater.put(word, unigramProbability); + } + + for (int i = 0; i < BIGRAM_COUNT; i++) { + final int word0Index = random.nextInt(wordProbabilitiesToCheckLater.size()); + final int word1Index = random.nextInt(wordProbabilitiesToCheckLater.size()); + if (word0Index == word1Index) { + continue; + } + final String word0 = words.get(word0Index); + final String word1 = words.get(word1Index); + final int unigramProbability = wordProbabilitiesToCheckLater.get(word1); + final int bigramProbability = + unigramProbability + random.nextInt(0xFF - unigramProbability); + addBigramWords(binaryDictionary, word0, word1, bigramProbability); + if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) { + binaryDictionary.flushWithGC(); + } + if (!bigrams.containsKey(word0)) { + final HashSet<String> bigramWord1s = new HashSet<>(); + bigrams.put(word0, bigramWord1s); + } + bigrams.get(word0).add(word1); + bigramProbabilitiesToCheckLater.put(new Pair<>(word0, word1), bigramProbability); + } + + final HashSet<String> wordSet = new HashSet<>(words); + final HashSet<Pair<String, String>> bigramSet = + new HashSet<>(bigramProbabilitiesToCheckLater.keySet()); + int token = 0; + do { + final BinaryDictionary.GetNextWordPropertyResult result = + binaryDictionary.getNextWordProperty(token); + final WordProperty wordProperty = result.mWordProperty; + final String word0 = wordProperty.mWord; + assertEquals((int)wordProbabilitiesToCheckLater.get(word0), + wordProperty.mProbabilityInfo.mProbability); + wordSet.remove(word0); + final HashSet<String> bigramWord1s = bigrams.get(word0); + // TODO: Support ngram. + if (wordProperty.mHasNgrams) { + for (final WeightedString bigramTarget : wordProperty.getBigrams()) { + final String word1 = bigramTarget.mWord; + assertTrue(bigramWord1s.contains(word1)); + final Pair<String, String> bigram = new Pair<>(word0, word1); + final int bigramProbability = bigramProbabilitiesToCheckLater.get(bigram); + assertEquals(bigramProbability, bigramTarget.getProbability()); + bigramSet.remove(bigram); + } + } + token = result.mNextToken; + } while (token != 0); + assertTrue(wordSet.isEmpty()); + assertTrue(bigramSet.isEmpty()); + } + + @Test + public void testPossiblyOffensiveAttributeMaintained() { + final BinaryDictionary binaryDictionary = + getEmptyBinaryDictionary(FormatSpec.VERSION403); + binaryDictionary.addUnigramEntry("ddd", 100, false, true, true, 0); + WordProperty wordProperty = binaryDictionary.getWordProperty("ddd", false); + assertEquals(true, wordProperty.mIsPossiblyOffensive); + } + + @Test + public void testBeginningOfSentence() { + final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); + final int dummyProbability = 0; + final NgramContext beginningOfSentenceContext = NgramContext.BEGINNING_OF_SENTENCE; + final int bigramProbability = 200; + addUnigramWord(binaryDictionary, "aaa", dummyProbability); + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "aaa", bigramProbability, + BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); + assertEquals(bigramProbability, + binaryDictionary.getNgramProbability(beginningOfSentenceContext, "aaa")); + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "aaa", bigramProbability, + BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); + addUnigramWord(binaryDictionary, "bbb", dummyProbability); + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "bbb", bigramProbability, + BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); + binaryDictionary.flushWithGC(); + assertEquals(bigramProbability, + binaryDictionary.getNgramProbability(beginningOfSentenceContext, "aaa")); + assertEquals(bigramProbability, + binaryDictionary.getNgramProbability(beginningOfSentenceContext, "bbb")); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/BlueUnderlineTests.java b/tests/src/org/kelar/inputmethod/latin/BlueUnderlineTests.java new file mode 100644 index 000000000..7835f4497 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/BlueUnderlineTests.java @@ -0,0 +1,128 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import android.text.style.SuggestionSpan; +import android.text.style.UnderlineSpan; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.common.Constants; + +@LargeTest +public class BlueUnderlineTests extends InputTestsBase { + + public void testBlueUnderline() { + final String STRING_TO_TYPE = "tgis"; + final int EXPECTED_SPAN_START = 0; + final int EXPECTED_SPAN_END = 4; + type(STRING_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + assertEquals("show blue underline, span start", EXPECTED_SPAN_START, span.mStart); + assertEquals("show blue underline, span end", EXPECTED_SPAN_END, span.mEnd); + assertEquals("show blue underline, span color", true, span.isAutoCorrectionIndicator()); + } + + public void testBlueUnderlineDisappears() { + final String STRING_1_TO_TYPE = "tqis"; + final String STRING_2_TO_TYPE = "g"; + final int EXPECTED_SPAN_START = 0; + final int EXPECTED_SPAN_END = 5; + type(STRING_1_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + type(STRING_2_TO_TYPE); + // We haven't have time to look into the dictionary yet, so the line should still be + // blue to avoid any flicker. + final SpanGetter spanBefore = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + assertEquals("extend blue underline, span start", EXPECTED_SPAN_START, spanBefore.mStart); + assertEquals("extend blue underline, span end", EXPECTED_SPAN_END, spanBefore.mEnd); + assertTrue("extend blue underline, span color", spanBefore.isAutoCorrectionIndicator()); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + // Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span + final SpanGetter spanAfter = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + assertNull("hide blue underline", spanAfter.mSpan); + } + + public void testBlueUnderlineOnBackspace() { + final String STRING_TO_TYPE = "tgis"; + final int typedLength = STRING_TO_TYPE.length(); + final int EXPECTED_UNDERLINE_SPAN_START = 0; + final int EXPECTED_UNDERLINE_SPAN_END = 3; + type(STRING_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + type(Constants.CODE_SPACE); + // typedLength + 1 because we also typed a space + mLatinIME.onUpdateSelection(0, 0, typedLength + 1, typedLength + 1, -1, -1); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + type(Constants.CODE_DELETE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + type(Constants.CODE_DELETE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + assertFalse("show no blue underline after backspace, span should not be the auto-" + + "correction indicator", suggestionSpan.isAutoCorrectionIndicator()); + final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class); + assertEquals("should be composing, so should have an underline span", + EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart); + assertEquals("should be composing, so should have an underline span", + EXPECTED_UNDERLINE_SPAN_END, underlineSpan.mEnd); + } + + public void testBlueUnderlineDisappearsWhenCursorMoved() { + final String STRING_TO_TYPE = "tgis"; + final int typedLength = STRING_TO_TYPE.length(); + final int NEW_CURSOR_POSITION = 0; + type(STRING_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + // Simulate the onUpdateSelection() event + mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1); + runMessages(); + // Here the blue underline has been set. testBlueUnderline() is testing for this already, + // so let's not test it here again. + // Now simulate the user moving the cursor. + mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION); + mLatinIME.onUpdateSelection(typedLength, typedLength, + NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + assertFalse("blue underline removed when cursor is moved", + span.isAutoCorrectionIndicator()); + } + + public void testComposingStopsOnSpace() { + final String STRING_TO_TYPE = "this "; + type(STRING_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + // Simulate the onUpdateSelection() event + mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); + runMessages(); + // Here the blue underline has been set. testBlueUnderline() is testing for this already, + // so let's not test it here again. + // Now simulate the user moving the cursor. + SpanGetter span = new SpanGetter(mEditText.getText(), UnderlineSpan.class); + assertNull("should not be composing, so should not have an underline span", span.mSpan); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/ContactsContentObserverTest.java b/tests/src/org/kelar/inputmethod/latin/ContactsContentObserverTest.java new file mode 100644 index 000000000..8e21324cb --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/ContactsContentObserverTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.validateMockitoUsage; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.provider.ContactsContract.Contacts; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.ArrayList; + +/** + * Tests for {@link ContactsContentObserver}. + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class ContactsContentObserverTest { + private static final int UPDATED_CONTACT_COUNT = 10; + private static final int STALE_CONTACT_COUNT = 8; + private static final ArrayList<String> STALE_NAMES_LIST = new ArrayList<>(); + private static final ArrayList<String> UPDATED_NAMES_LIST = new ArrayList<>(); + + static { + STALE_NAMES_LIST.add("Larry Page"); + STALE_NAMES_LIST.add("Roger Federer"); + UPDATED_NAMES_LIST.add("Larry Page"); + UPDATED_NAMES_LIST.add("Roger Federer"); + UPDATED_NAMES_LIST.add("Barak Obama"); + } + + @Mock private ContactsManager mMockManager; + @Mock private Context mContext; + + private ContactsContentObserver mObserver; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + mObserver = new ContactsContentObserver(mMockManager, mContext); + } + + @After + public void tearDown() { + validateMockitoUsage(); + } + + @Test + public void testHaveContentsChanged_NoChange() { + when(mMockManager.getContactCount()).thenReturn(STALE_CONTACT_COUNT); + when(mMockManager.getContactCountAtLastRebuild()).thenReturn(STALE_CONTACT_COUNT); + when(mMockManager.getValidNames(eq(Contacts.CONTENT_URI))).thenReturn(STALE_NAMES_LIST); + when(mMockManager.getHashCodeAtLastRebuild()).thenReturn(STALE_NAMES_LIST.hashCode()); + assertFalse(mObserver.haveContentsChanged()); + } + @Test + public void testHaveContentsChanged_UpdatedCount() { + when(mMockManager.getContactCount()).thenReturn(UPDATED_CONTACT_COUNT); + when(mMockManager.getContactCountAtLastRebuild()).thenReturn(STALE_CONTACT_COUNT); + assertTrue(mObserver.haveContentsChanged()); + } + + @Test + public void testHaveContentsChanged_HashUpdate() { + when(mMockManager.getContactCount()).thenReturn(STALE_CONTACT_COUNT); + when(mMockManager.getContactCountAtLastRebuild()).thenReturn(STALE_CONTACT_COUNT); + when(mMockManager.getValidNames(eq(Contacts.CONTENT_URI))).thenReturn(UPDATED_NAMES_LIST); + when(mMockManager.getHashCodeAtLastRebuild()).thenReturn(STALE_NAMES_LIST.hashCode()); + assertTrue(mObserver.haveContentsChanged()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/ContactsDictionaryUtilsTest.java b/tests/src/org/kelar/inputmethod/latin/ContactsDictionaryUtilsTest.java new file mode 100644 index 000000000..79f13a979 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/ContactsDictionaryUtilsTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +/** + * Tests for {@link ContactsDictionaryUtils} + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class ContactsDictionaryUtilsTest { + + @Test + public void testGetWordEndPosition() { + final String testString1 = "Larry Page"; + assertEquals(5, ContactsDictionaryUtils.getWordEndPosition( + testString1, testString1.length(), 0 /* startIndex */)); + + assertEquals(10, ContactsDictionaryUtils.getWordEndPosition( + testString1, testString1.length(), 6 /* startIndex */)); + + final String testString2 = "Larry-Page"; + assertEquals(10, ContactsDictionaryUtils.getWordEndPosition( + testString2, testString1.length(), 0 /* startIndex */)); + + final String testString3 = "Larry'Page"; + assertEquals(10, ContactsDictionaryUtils.getWordEndPosition( + testString3, testString1.length(), 0 /* startIndex */)); + } + + @Test + public void testUseFirstLastBigramsForLocale() { + assertTrue(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.ENGLISH)); + assertTrue(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.US)); + assertTrue(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.UK)); + assertFalse(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.CHINA)); + assertFalse(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.GERMAN)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/ContactsManagerTest.java b/tests/src/org/kelar/inputmethod/latin/ContactsManagerTest.java new file mode 100644 index 000000000..d912ec266 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/ContactsManagerTest.java @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.content.ContentResolver; +import android.content.Context; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.net.Uri; +import android.provider.ContactsContract; +import android.provider.ContactsContract.Contacts; +import android.test.RenamingDelegatingContext; +import android.test.mock.MockContentProvider; +import android.test.mock.MockContentResolver; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + +/** + * Tests for {@link ContactsManager} + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class ContactsManagerTest { + + private ContactsManager mManager; + private FakeContactsContentProvider mFakeContactsContentProvider; + private MatrixCursor mMatrixCursor; + + private final static float EPSILON = 0.00001f; + + @Before + public void setUp() throws Exception { + // Fake content provider + mFakeContactsContentProvider = new FakeContactsContentProvider(); + mMatrixCursor = new MatrixCursor(ContactsDictionaryConstants.PROJECTION); + // Add the fake content provider to fake content resolver. + final MockContentResolver contentResolver = new MockContentResolver(); + contentResolver.addProvider(ContactsContract.AUTHORITY, mFakeContactsContentProvider); + // Add the fake content resolver to a fake context. + final ContextWithMockContentResolver context = + new ContextWithMockContentResolver(InstrumentationRegistry.getTargetContext()); + context.setContentResolver(contentResolver); + + mManager = new ContactsManager(context); + } + + @Test + public void testGetValidNames() { + final String contactName1 = "firstname last-name"; + final String contactName2 = "larry"; + mMatrixCursor.addRow(new Object[] { 1, contactName1, 0, 0, 0 }); + mMatrixCursor.addRow(new Object[] { 2, null /* null name */, 0, 0, 0 }); + mMatrixCursor.addRow(new Object[] { 3, contactName2, 0, 0, 0 }); + mMatrixCursor.addRow(new Object[] { 4, "floopy@example.com" /* invalid name */, 0, 0, 0 }); + mMatrixCursor.addRow(new Object[] { 5, "news-group" /* invalid name */, 0, 0, 0 }); + mFakeContactsContentProvider.addQueryResult(Contacts.CONTENT_URI, mMatrixCursor); + + final ArrayList<String> validNames = mManager.getValidNames(Contacts.CONTENT_URI); + assertEquals(2, validNames.size()); + assertEquals(contactName1, validNames.get(0)); + assertEquals(contactName2, validNames.get(1)); + } + + @Test + public void testGetValidNamesAffinity() { + final long now = System.currentTimeMillis(); + final long month_ago = now - TimeUnit.MILLISECONDS.convert(31, TimeUnit.DAYS); + for (int i = 0; i < ContactsManager.MAX_CONTACT_NAMES + 10; ++i) { + mMatrixCursor.addRow(new Object[] { i, "name" + i, i, now, 1 }); + } + mFakeContactsContentProvider.addQueryResult(Contacts.CONTENT_URI, mMatrixCursor); + + final ArrayList<String> validNames = mManager.getValidNames(Contacts.CONTENT_URI); + assertEquals(ContactsManager.MAX_CONTACT_NAMES, validNames.size()); + for (int i = 0; i < 10; ++i) { + assertFalse(validNames.contains("name" + i)); + } + for (int i = 10; i < ContactsManager.MAX_CONTACT_NAMES + 10; ++i) { + assertTrue(validNames.contains("name" + i)); + } + } + + @Test + public void testComputeAffinity() { + final long now = System.currentTimeMillis(); + final long month_ago = now - TimeUnit.MILLISECONDS.convert(31, TimeUnit.DAYS); + mMatrixCursor.addRow(new Object[] { 1, "name", 1, month_ago, 1 }); + mFakeContactsContentProvider.addQueryResult(Contacts.CONTENT_URI, mMatrixCursor); + + Cursor cursor = mFakeContactsContentProvider.query(Contacts.CONTENT_URI, + ContactsDictionaryConstants.PROJECTION_ID_ONLY, null, null, null); + cursor.moveToFirst(); + ContactsManager.RankedContact contact = new ContactsManager.RankedContact(cursor); + contact.computeAffinity(1, month_ago); + assertEquals(contact.getAffinity(), 1.0f, EPSILON); + contact.computeAffinity(2, now); + assertEquals(contact.getAffinity(), (2.0f/3.0f + (float)Math.pow(0.5, 3) + 1.0f) / 3, + EPSILON); + } + + @Test + public void testGetCount() { + mMatrixCursor.addRow(new Object[] { 1, "firstname", 0, 0, 0 }); + mMatrixCursor.addRow(new Object[] { 2, null /* null name */, 0, 0, 0 }); + mMatrixCursor.addRow(new Object[] { 3, "larry", 0, 0, 0 }); + mMatrixCursor.addRow(new Object[] { 4, "floopy@example.com" /* invalid name */, 0, 0, 0 }); + mFakeContactsContentProvider.addQueryResult(Contacts.CONTENT_URI, mMatrixCursor); + assertEquals(4, mManager.getContactCount()); + } + + + static class ContextWithMockContentResolver extends RenamingDelegatingContext { + private ContentResolver contentResolver; + + public void setContentResolver(final ContentResolver contentResolver) { + this.contentResolver = contentResolver; + } + + public ContextWithMockContentResolver(final Context targetContext) { + super(targetContext, "test"); + } + + @Override + public ContentResolver getContentResolver() { + return contentResolver; + } + } + + static class FakeContactsContentProvider extends MockContentProvider { + private final HashMap<String, MatrixCursor> mQueryCursorMapForTestExpectations = + new HashMap<>(); + + @Override + public Cursor query(final Uri uri, final String[] projection, final String selection, + final String[] selectionArgs, final String sortOrder) { + return mQueryCursorMapForTestExpectations.get(uri.toString()); + } + + public void reset() { + mQueryCursorMapForTestExpectations.clear(); + } + + public void addQueryResult(final Uri uri, final MatrixCursor cursor) { + mQueryCursorMapForTestExpectations.put(uri.toString(), cursor); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java b/tests/src/org/kelar/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java new file mode 100644 index 000000000..ed9928a65 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class DictionaryFacilitatorLruCacheTests { + + @Test + public void testGetFacilitator() { + final DictionaryFacilitatorLruCache cache = + new DictionaryFacilitatorLruCache(InstrumentationRegistry.getTargetContext(), ""); + + final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US); + assertNotNull(dictionaryFacilitatorEnUs); + assertTrue(dictionaryFacilitatorEnUs.isForLocale(Locale.US)); + + final DictionaryFacilitator dictionaryFacilitatorFr = cache.get(Locale.FRENCH); + assertNotNull(dictionaryFacilitatorEnUs); + assertTrue(dictionaryFacilitatorFr.isForLocale(Locale.FRENCH)); + + final DictionaryFacilitator dictionaryFacilitatorDe = cache.get(Locale.GERMANY); + assertNotNull(dictionaryFacilitatorDe); + assertTrue(dictionaryFacilitatorDe.isForLocale(Locale.GERMANY)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/InputLogicTests.java b/tests/src/org/kelar/inputmethod/latin/InputLogicTests.java new file mode 100644 index 000000000..689ee88bb --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/InputLogicTests.java @@ -0,0 +1,786 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import static android.test.MoreAsserts.assertNotEqual; + +import android.text.TextUtils; +import android.view.inputmethod.BaseInputConnection; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.define.DecoderSpecificConstants; +import org.kelar.inputmethod.latin.settings.Settings; + +@LargeTest +public class InputLogicTests extends InputTestsBase { + + private boolean mNextWordPrediction; + + @Override + public void setUp() throws Exception { + super.setUp(); + mNextWordPrediction = getBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, true); + } + + @Override + public void tearDown() throws Exception { + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mNextWordPrediction, true); + super.tearDown(); + } + + public void testTypeWord() { + final String WORD_TO_TYPE = "abcd"; + type(WORD_TO_TYPE); + assertEquals("type word", WORD_TO_TYPE, mEditText.getText().toString()); + } + + public void testPickSuggestionThenBackspace() { + final String WORD_TO_TYPE = "this"; + final String EXPECTED_RESULT = "thi"; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + sendUpdateForCursorMoveTo(WORD_TO_TYPE.length()); + type(Constants.CODE_DELETE); + assertEquals("press suggestion then backspace", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testPickAutoCorrectionThenBackspace() { + final String WORD_TO_TYPE = "tgis"; + final String WORD_TO_PICK = "this"; + final String EXPECTED_RESULT = "thi"; + type(WORD_TO_TYPE); + // Choose the auto-correction. For "tgis", the auto-correction should be "this". + pickSuggestionManually(WORD_TO_PICK); + sendUpdateForCursorMoveTo(WORD_TO_TYPE.length()); + assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK, + mEditText.getText().toString()); + type(Constants.CODE_DELETE); + assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testPickTypedWordOverAutoCorrectionThenBackspace() { + final String WORD_TO_TYPE = "tgis"; + final String EXPECTED_RESULT = "tgi"; + type(WORD_TO_TYPE); + // Choose the typed word. + pickSuggestionManually(WORD_TO_TYPE); + sendUpdateForCursorMoveTo(WORD_TO_TYPE.length()); + assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE, + mEditText.getText().toString()); + type(Constants.CODE_DELETE); + assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testPickDifferentSuggestionThenBackspace() { + final String WORD_TO_TYPE = "tgis"; + final String WORD_TO_PICK = "thus"; + final String EXPECTED_RESULT = "thu"; + type(WORD_TO_TYPE); + // Choose the second suggestion, which should be "thus" when "tgis" is typed. + pickSuggestionManually(WORD_TO_PICK); + sendUpdateForCursorMoveTo(WORD_TO_TYPE.length()); + assertEquals("pick different suggestion then backspace", WORD_TO_PICK, + mEditText.getText().toString()); + type(Constants.CODE_DELETE); + assertEquals("pick different suggestion then backspace", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeleteSelection() { + final String STRING_TO_TYPE = "some text delete me some text"; + final int typedLength = STRING_TO_TYPE.length(); + final int SELECTION_START = 10; + final int SELECTION_END = 19; + final String EXPECTED_RESULT = "some text some text"; + type(STRING_TO_TYPE); + // Don't use the sendUpdateForCursorMove* family of methods here because they + // don't handle selections. + // Send once to simulate the cursor actually responding to the move caused by typing. + // This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor + // move with a move triggered by LatinIME inputting stuff. + mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1); + mInputConnection.setSelection(SELECTION_START, SELECTION_END); + // And now we simulate the user actually selecting some text. + mLatinIME.onUpdateSelection(typedLength, typedLength, + SELECTION_START, SELECTION_END, -1, -1); + type(Constants.CODE_DELETE); + assertEquals("delete selection", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testDeleteSelectionTwice() { + final String STRING_TO_TYPE = "some text delete me some text"; + final int typedLength = STRING_TO_TYPE.length(); + final int SELECTION_START = 10; + final int SELECTION_END = 19; + final String EXPECTED_RESULT = "some text some text"; + type(STRING_TO_TYPE); + // Don't use the sendUpdateForCursorMove* family of methods here because they + // don't handle selections. + // Send once to simulate the cursor actually responding to the move caused by typing. + // This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor + // move with a move triggered by LatinIME inputting stuff. + mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1); + mInputConnection.setSelection(SELECTION_START, SELECTION_END); + // And now we simulate the user actually selecting some text. + mLatinIME.onUpdateSelection(typedLength, typedLength, + SELECTION_START, SELECTION_END, -1, -1); + type(Constants.CODE_DELETE); + type(Constants.CODE_DELETE); + assertEquals("delete selection twice", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoCorrect() { + final String STRING_TO_TYPE = "tgis "; + final String EXPECTED_RESULT = "this "; + type(STRING_TO_TYPE); + assertEquals("simple auto-correct", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoCorrectWithQuote() { + final String STRING_TO_TYPE = "didn' "; + final String EXPECTED_RESULT = "didn't "; + type(STRING_TO_TYPE); + assertEquals("auto-correct with quote", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoCorrectWithPeriod() { + final String STRING_TO_TYPE = "tgis."; + final String EXPECTED_RESULT = "this."; + type(STRING_TO_TYPE); + assertEquals("auto-correct with period", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoCorrectWithPeriodThenRevert() { + final String STRING_TO_TYPE = "tgis."; + final String EXPECTED_RESULT = "tgis."; + type(STRING_TO_TYPE); + sendUpdateForCursorMoveTo(STRING_TO_TYPE.length()); + type(Constants.CODE_DELETE); + assertEquals("auto-correct with period then revert", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testAutoCorrectWithSpaceThenRevert() { + // Backspacing to cancel the "tgis"->"this" autocorrection should result in + // a "phantom space": if the user presses space immediately after, + // only one space will be inserted in total. + final String STRING_TO_TYPE = "tgis "; + final String EXPECTED_RESULT = "tgis"; + type(STRING_TO_TYPE); + sendUpdateForCursorMoveTo(STRING_TO_TYPE.length()); + type(Constants.CODE_DELETE); + assertEquals("auto-correct with space then revert", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testAutoCorrectWithSpaceThenRevertThenTypeMore() { + final String STRING_TO_TYPE_FIRST = "tgis "; + final String STRING_TO_TYPE_SECOND = "a"; + final String EXPECTED_RESULT = "tgis a"; + type(STRING_TO_TYPE_FIRST); + sendUpdateForCursorMoveTo(STRING_TO_TYPE_FIRST.length()); + type(Constants.CODE_DELETE); + + type(STRING_TO_TYPE_SECOND); + sendUpdateForCursorMoveTo(STRING_TO_TYPE_FIRST.length() - 1 + + STRING_TO_TYPE_SECOND.length()); + assertEquals("auto-correct with space then revert then type more", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testAutoCorrectToSelfDoesNotRevert() { + final String STRING_TO_TYPE = "this "; + final String EXPECTED_RESULT = "this"; + type(STRING_TO_TYPE); + sendUpdateForCursorMoveTo(STRING_TO_TYPE.length()); + type(Constants.CODE_DELETE); + assertEquals("auto-correct with space does not revert", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDoubleSpace() { + // U+1F607 is an emoji + final String[] STRINGS_TO_TYPE = + new String[] { "this ", "a+ ", "\u1F607 ", ".. ", ") ", "( ", "% " }; + final String[] EXPECTED_RESULTS = + new String[] { "this. ", "a+. ", "\u1F607. ", ".. ", "). ", "( ", "%. " }; + verifyDoubleSpace(STRINGS_TO_TYPE, EXPECTED_RESULTS); + } + + public void testDoubleSpaceHindi() { + changeLanguage("hi"); + // U+1F607 is an emoji + final String[] STRINGS_TO_TYPE = + new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; + final String[] EXPECTED_RESULTS = + new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; + verifyDoubleSpace(STRINGS_TO_TYPE, EXPECTED_RESULTS); + } + + private void verifyDoubleSpace(String[] stringsToType, String[] expectedResults) { + // Set default pref just in case + setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); + for (int i = 0; i < stringsToType.length; ++i) { + mEditText.setText(""); + type(stringsToType[i]); + assertEquals("double space processing", expectedResults[i], + mEditText.getText().toString()); + } + } + + public void testCancelDoubleSpaceEnglish() { + final String STRING_TO_TYPE = "this "; + final String EXPECTED_RESULT = "this "; + type(STRING_TO_TYPE); + type(Constants.CODE_DELETE); + assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testCancelDoubleSpaceHindi() { + changeLanguage("hi"); + final String STRING_TO_TYPE = "this "; + final String EXPECTED_RESULT = "this "; + type(STRING_TO_TYPE); + type(Constants.CODE_DELETE); + assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); + } + + private void testDoubleSpacePeriodWithSettings(final boolean expectsPeriod, + final Object... settingsKeysValues) { + final Object[] oldSettings = new Object[settingsKeysValues.length / 2]; + final String STRING_WITHOUT_PERIOD = "this "; + final String STRING_WITH_PERIOD = "this. "; + final String EXPECTED_RESULT = expectsPeriod ? STRING_WITH_PERIOD : STRING_WITHOUT_PERIOD; + try { + for (int i = 0; i < settingsKeysValues.length; i += 2) { + if (settingsKeysValues[i + 1] instanceof String) { + oldSettings[i / 2] = setStringPreference((String)settingsKeysValues[i], + (String)settingsKeysValues[i + 1], "0"); + } else { + oldSettings[i / 2] = setBooleanPreference((String)settingsKeysValues[i], + (Boolean)settingsKeysValues[i + 1], false); + } + } + mLatinIME.loadSettings(); + mEditText.setText(""); + type(STRING_WITHOUT_PERIOD); + assertEquals("double-space-to-period with specific settings " + + TextUtils.join(" ", settingsKeysValues), + EXPECTED_RESULT, mEditText.getText().toString()); + } finally { + // Restore old settings + for (int i = 0; i < settingsKeysValues.length; i += 2) { + if (null == oldSettings[i / 2]) { + break; + } if (oldSettings[i / 2] instanceof String) { + setStringPreference((String)settingsKeysValues[i], (String)oldSettings[i / 2], + ""); + } else { + setBooleanPreference((String)settingsKeysValues[i], (Boolean)oldSettings[i / 2], + false); + } + } + } + } + + public void testDoubleSpacePeriod() { + // Reset settings to default, else these tests will go flaky. + setBooleanPreference(Settings.PREF_SHOW_SUGGESTIONS, true, true); + setBooleanPreference(Settings.PREF_AUTO_CORRECTION, true, true); + setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); + testDoubleSpacePeriodWithSettings(true); + // "Suggestion visibility" to off + testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false); + // "Suggestion visibility" to on + testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, true); + + // "Double-space period" to "off" + testDoubleSpacePeriodWithSettings(false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); + + // "Auto-correction" to "off" + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, false); + // "Auto-correction" to "on" + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, true); + + // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" + testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false, + Settings.PREF_AUTO_CORRECTION, false); + // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" + testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS, false, + Settings.PREF_AUTO_CORRECTION, false, + Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); + } + + public void testBackspaceAtStartAfterAutocorrect() { + final String STRING_TO_TYPE = "tgis "; + final int typedLength = STRING_TO_TYPE.length(); + final String EXPECTED_RESULT = "this "; + final int NEW_CURSOR_POSITION = 0; + type(STRING_TO_TYPE); + sendUpdateForCursorMoveTo(typedLength); + mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION); + sendUpdateForCursorMoveTo(NEW_CURSOR_POSITION); + type(Constants.CODE_DELETE); + assertEquals("auto correct then move cursor to start of line then backspace", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoCorrectThenMoveCursorThenBackspace() { + final String STRING_TO_TYPE = "and tgis "; + final int typedLength = STRING_TO_TYPE.length(); + final String EXPECTED_RESULT = "andthis "; + final int NEW_CURSOR_POSITION = STRING_TO_TYPE.indexOf('t'); + type(STRING_TO_TYPE); + sendUpdateForCursorMoveTo(typedLength); + mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION); + sendUpdateForCursorMoveTo(NEW_CURSOR_POSITION); + type(Constants.CODE_DELETE); + assertEquals("auto correct then move cursor then backspace", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testNoSpaceAfterManualPick() { + final String WORD_TO_TYPE = "this"; + final String EXPECTED_RESULT = WORD_TO_TYPE; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + assertEquals("no space after manual pick", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManualPickThenType() { + final String WORD1_TO_TYPE = "this"; + final String WORD2_TO_TYPE = "is"; + final String EXPECTED_RESULT = "this is"; + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("manual pick then type", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testManualPickThenSeparator() { + final String WORD1_TO_TYPE = "this"; + final String WORD2_TO_TYPE = "!"; + final String EXPECTED_RESULT = "this!"; + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("manual pick then separator", EXPECTED_RESULT, mEditText.getText().toString()); + } + + // This test matches testClusteringPunctuationForFrench. + // In some non-English languages, ! and ? are clustering punctuation signs. + public void testClusteringPunctuation() { + final String WORD1_TO_TYPE = "test"; + final String WORD2_TO_TYPE = "!!?!:!"; + final String EXPECTED_RESULT = "test!!?!:!"; + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("clustering punctuation", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testManualPickThenStripperThenPick() { + final String WORD_TO_TYPE = "this"; + final String STRIPPER = "\n"; + final String EXPECTED_RESULT = "this\nthis"; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + type(STRIPPER); + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + assertEquals("manual pick then \\n then manual pick", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManualPickThenSpaceThenType() { + final String WORD1_TO_TYPE = "this"; + final String WORD2_TO_TYPE = " is"; + final String EXPECTED_RESULT = "this is"; + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("manual pick then space then type", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManualPickThenManualPick() { + final String WORD1_TO_TYPE = "this"; + final String WORD2_TO_PICK = "is"; + final String EXPECTED_RESULT = "this is"; + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + // Here we fake picking a word through bigram prediction. + pickSuggestionManually(WORD2_TO_PICK); + assertEquals("manual pick then manual pick", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeleteWholeComposingWord() { + final String WORD_TO_TYPE = "this"; + type(WORD_TO_TYPE); + for (int i = 0; i < WORD_TO_TYPE.length(); ++i) { + type(Constants.CODE_DELETE); + } + assertEquals("delete whole composing word", "", mEditText.getText().toString()); + } + + public void testResumeSuggestionOnBackspace() { + final String STRING_TO_TYPE = "and this "; + final int typedLength = STRING_TO_TYPE.length(); + type(STRING_TO_TYPE); + assertEquals("resume suggestion on backspace", -1, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("resume suggestion on backspace", -1, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + sendUpdateForCursorMoveTo(typedLength); + type(Constants.CODE_DELETE); + assertEquals("resume suggestion on backspace", 4, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("resume suggestion on backspace", 8, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + } + + private void helperTestComposing(final String wordToType, final boolean shouldBeComposing) { + mEditText.setText(""); + type(wordToType); + assertEquals("start composing inside text", shouldBeComposing ? 0 : -1, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("start composing inside text", shouldBeComposing ? wordToType.length() : -1, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + } + + public void testStartComposing() { + // Should start composing on a letter + helperTestComposing("a", true); + type(" "); // To reset the composing state + // Should not start composing on quote + helperTestComposing("'", false); + type(" "); + helperTestComposing("'-", false); + type(" "); + // Should not start composing on dash + helperTestComposing("-", false); + type(" "); + helperTestComposing("-'", false); + type(" "); + helperTestComposing("a-", true); + type(" "); + helperTestComposing("a'", true); + } + + // TODO: Add some tests for non-BMP characters + + public void testAutoCorrectByUserHistory() { + type("qpmz"); + type(Constants.CODE_SPACE); + + int startIndex = mEditText.getText().length(); + type("qpmx"); + type(Constants.CODE_SPACE); + int endIndex = mEditText.getText().length(); + assertEquals("auto-corrected by user history", + "qpmz ", mEditText.getText().subSequence(startIndex, endIndex).toString()); + } + + public void testPredictionsAfterSpace() { + final String WORD_TO_TYPE = "Barack "; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + // Test the first prediction is displayed + final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("predictions after space", "Obama", + suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + } + + public void testPredictionsWithDoubleSpaceToPeriod() { + mLatinIME.clearPersonalizedDictionariesForTest(); + final String WORD_TO_TYPE = "Barack "; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + + type(Constants.CODE_DELETE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + + SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("predictions after cancel double-space-to-period", "Obama", + mLatinIME.getSuggestedWordsForTest().getWord(0)); + } + + public void testPredictionsAfterManualPick() { + final String WORD_TO_TYPE = "Barack"; + type(WORD_TO_TYPE); + // Choose the auto-correction. For "Barack", the auto-correction should be "Barack". + pickSuggestionManually(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + // Test the first prediction is displayed + final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("predictions after manual pick", "Obama", + suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + } + + public void testPredictionsAfterPeriod() { + mLatinIME.clearPersonalizedDictionariesForTest(); + final String WORD_TO_TYPE = "Barack. "; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + + SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertFalse(mLatinIME.getSuggestedWordsForTest().isEmpty()); + } + + public void testPredictionsAfterRecorrection() { + final String PREFIX = "A "; + final String WORD_TO_TYPE = "Barack"; + final String FIRST_NON_TYPED_SUGGESTION = "Barrack"; + final int endOfPrefix = PREFIX.length(); + final int endOfWord = endOfPrefix + WORD_TO_TYPE.length(); + final int endOfSuggestion = endOfPrefix + FIRST_NON_TYPED_SUGGESTION.length(); + final int indexForManualCursor = endOfPrefix + 3; // +3 because it's after "Bar" in "Barack" + type(PREFIX); + sendUpdateForCursorMoveTo(endOfPrefix); + type(WORD_TO_TYPE); + pickSuggestionManually(FIRST_NON_TYPED_SUGGESTION); + sendUpdateForCursorMoveTo(endOfSuggestion); + runMessages(); + type(" "); + sendUpdateForCursorMoveBy(1); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + // Simulate a manual cursor move + mInputConnection.setSelection(indexForManualCursor, indexForManualCursor); + sendUpdateForCursorMoveTo(indexForManualCursor); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + pickSuggestionManually(WORD_TO_TYPE); + sendUpdateForCursorMoveTo(endOfWord); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + // Test the first prediction is displayed + final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("predictions after recorrection", "Obama", + suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + } + + public void testComposingMultipleBackspace() { + final String WORD_TO_TYPE = "radklro"; + final int TIMES_TO_TYPE = 3; + final int TIMES_TO_BACKSPACE = 8; + type(WORD_TO_TYPE); + type(Constants.CODE_DELETE); + type(Constants.CODE_DELETE); + type(Constants.CODE_DELETE); + type(WORD_TO_TYPE); + type(Constants.CODE_DELETE); + type(Constants.CODE_DELETE); + type(WORD_TO_TYPE); + type(Constants.CODE_DELETE); + type(Constants.CODE_DELETE); + type(Constants.CODE_DELETE); + assertEquals("composing with multiple backspace", + WORD_TO_TYPE.length() * TIMES_TO_TYPE - TIMES_TO_BACKSPACE, + mEditText.getText().length()); + } + + public void testManySingleQuotes() { + final String WORD_TO_AUTOCORRECT = "i"; + final String WORD_AUTOCORRECTED = "I"; + final String QUOTES = "''''''''''''''''''''"; + final String WORD_TO_TYPE = WORD_TO_AUTOCORRECT + QUOTES + " "; + final String EXPECTED_RESULT = WORD_AUTOCORRECTED + QUOTES + " "; + type(WORD_TO_TYPE); + assertEquals("auto-correct with many trailing single quotes", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManySingleQuotesOneByOne() { + final String WORD_TO_AUTOCORRECT = "i"; + final String WORD_AUTOCORRECTED = "I"; + final String QUOTES = "''''''''''''''''''''"; + final String WORD_TO_TYPE = WORD_TO_AUTOCORRECT + QUOTES + " "; + final String EXPECTED_RESULT = WORD_AUTOCORRECTED + QUOTES + " "; + + for (int i = 0; i < WORD_TO_TYPE.length(); ++i) { + type(WORD_TO_TYPE.substring(i, i+1)); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + } + assertEquals("type many trailing single quotes one by one", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testTypingSingleQuotesOneByOne() { + final String WORD_TO_TYPE = "it's "; + final String EXPECTED_RESULT = WORD_TO_TYPE; + for (int i = 0; i < WORD_TO_TYPE.length(); ++i) { + type(WORD_TO_TYPE.substring(i, i+1)); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + } + assertEquals("type words letter by letter", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testBasicGesture() { + gesture("this"); + assertEquals("this", mEditText.getText().toString()); + } + + public void testGestureGesture() { + gesture("got"); + gesture("milk"); + assertEquals("got milk", mEditText.getText().toString()); + } + + public void testGestureBackspaceGestureAgain() { + gesture("this"); + type(Constants.CODE_DELETE); + assertEquals("gesture then backspace", "", mEditText.getText().toString()); + gesture("this"); + if (DecoderSpecificConstants.SHOULD_REMOVE_PREVIOUSLY_REJECTED_SUGGESTION) { + assertNotEqual("this", mEditText.getText().toString()); + } else { + assertEquals("this", mEditText.getText().toString()); + } + } + + private void typeOrGestureWordAndPutCursorInside(final boolean gesture, final String word, + final int startPos) { + final int END_OF_WORD = startPos + word.length(); + final int NEW_CURSOR_POSITION = startPos + word.length() / 2; + if (gesture) { + gesture(word); + } else { + type(word); + } + sendUpdateForCursorMoveTo(END_OF_WORD); + runMessages(); + sendUpdateForCursorMoveTo(NEW_CURSOR_POSITION); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + } + + private void typeWordAndPutCursorInside(final String word, final int startPos) { + typeOrGestureWordAndPutCursorInside(false /* gesture */, word, startPos); + } + + private void gestureWordAndPutCursorInside(final String word, final int startPos) { + typeOrGestureWordAndPutCursorInside(true /* gesture */, word, startPos); + } + + private void ensureComposingSpanPos(final String message, final int from, final int to) { + assertEquals(message, from, BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals(message, to, BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + } + + public void testTypeWithinComposing() { + final String WORD_TO_TYPE = "something"; + final String EXPECTED_RESULT = "some thing"; + typeWordAndPutCursorInside(WORD_TO_TYPE, 0 /* startPos */); + type(" "); + ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1); + assertEquals("space in the middle of a composing word", EXPECTED_RESULT, + mEditText.getText().toString()); + int cursorPos = sendUpdateForCursorMoveToEndOfLine(); + runMessages(); + type(" "); + assertEquals("mbo", "some thing ", mEditText.getText().toString()); + typeWordAndPutCursorInside(WORD_TO_TYPE, cursorPos + 1 /* startPos */); + type(Constants.CODE_DELETE); + ensureComposingSpanPos("delete while in the middle of a word cancels composition", -1, -1); + } + + public void testTypeWithinGestureComposing() { + final String WORD_TO_TYPE = "something"; + final String EXPECTED_RESULT = "some thing"; + gestureWordAndPutCursorInside(WORD_TO_TYPE, 0 /* startPos */); + type(" "); + ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1); + assertEquals("space in the middle of a composing word", EXPECTED_RESULT, + mEditText.getText().toString()); + int cursorPos = sendUpdateForCursorMoveToEndOfLine(); + runMessages(); + type(" "); + typeWordAndPutCursorInside(WORD_TO_TYPE, cursorPos + 1 /* startPos */); + type(Constants.CODE_DELETE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + ensureComposingSpanPos("delete while in the middle of a word cancels composition", -1, -1); + } + + public void testManualPickThenSeparatorForFrench() { + final String WORD1_TO_TYPE = "test"; + final String WORD2_TO_TYPE = "!"; + final String EXPECTED_RESULT = "test !"; + changeLanguage("fr"); + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("manual pick then separator for French", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testClusteringPunctuationForFrench() { + final String WORD1_TO_TYPE = "test"; + final String WORD2_TO_TYPE = "!!?!:!"; + // In English, the expected result would be "test!!?!:!" + final String EXPECTED_RESULT = "test !!?! : !"; + changeLanguage("fr"); + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("clustering punctuation for French", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testWordThenSpaceThenPunctuationFromStripTwice() { + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, false, true); + + final String WORD_TO_TYPE = "test "; + final String PUNCTUATION_FROM_STRIP = "!"; + final String EXPECTED_RESULT = "test!! "; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + assertTrue("type word then type space should display punctuation strip", + mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + assertEquals(EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testWordThenSpaceDisplaysPredictions() { + final String WORD_TO_TYPE = "Barack "; + final String EXPECTED_RESULT = "Obama"; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("type word then type space yields predictions for French", + EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/InputLogicTestsDeadKeys.java b/tests/src/org/kelar/inputmethod/latin/InputLogicTestsDeadKeys.java new file mode 100644 index 000000000..0c4662b1f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/InputLogicTestsDeadKeys.java @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.event.Event; +import org.kelar.inputmethod.latin.common.Constants; + +import java.util.ArrayList; + +@LargeTest +public class InputLogicTestsDeadKeys extends InputTestsBase { + // A helper class for readability + static class EventList extends ArrayList<Event> { + public EventList addCodePoint(final int codePoint, final boolean isDead) { + final Event event; + if (isDead) { + event = Event.createDeadEvent(codePoint, Event.NOT_A_KEY_CODE, null /* next */); + } else { + event = Event.createSoftwareKeypressEvent(codePoint, Event.NOT_A_KEY_CODE, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */); + } + add(event); + return this; + } + + public EventList addKey(final int keyCode) { + add(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT, keyCode, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */)); + return this; + } + } + + public void testDeadCircumflexSimple() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final String EXPECTED_RESULT = "aê"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint('e', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("simple dead circumflex", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testDeadCircumflexBackspace() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final String EXPECTED_RESULT = "ae"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('e', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex backspace", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testDeadCircumflexFeedback() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final String EXPECTED_RESULT = "a\u02C6"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex gives feedback", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadDiaeresisSpace() { + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "a\u00A8e\u00A8i"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint(Constants.CODE_SPACE, false) + .addCodePoint('e', false) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint(Constants.CODE_ENTER, false) + .addCodePoint('i', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead diaeresis space commits the dead char", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadAcuteLetterBackspace() { + final int MODIFIER_LETTER_ACUTE = 0xB4; + final String EXPECTED_RESULT1 = "aá"; + final String EXPECTED_RESULT2 = "a"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_ACUTE, true) + .addCodePoint('a', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead acute on a typed", EXPECTED_RESULT1, mEditText.getText().toString()); + mLatinIME.onEvent(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT, + Constants.CODE_DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */)); + assertEquals("a with acute deleted", EXPECTED_RESULT2, mEditText.getText().toString()); + } + + public void testFinnishStroke() { + final int MODIFIER_LETTER_STROKE = '-'; + final String EXPECTED_RESULT = "x\u0110\u0127"; + final EventList events = new EventList() + .addCodePoint('x', false) + .addCodePoint(MODIFIER_LETTER_STROKE, true) + .addCodePoint('D', false) + .addCodePoint(MODIFIER_LETTER_STROKE, true) + .addCodePoint('h', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("Finnish dead stroke", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDoubleDeadOgonek() { + final int MODIFIER_LETTER_OGONEK = 0x02DB; + final String EXPECTED_RESULT = "txǫs\u02DBfk"; + final EventList events = new EventList() + .addCodePoint('t', false) + .addCodePoint('x', false) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint('o', false) + .addCodePoint('s', false) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint('f', false) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('k', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("double dead ogonek, and backspace", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadCircumflexDeadDiaeresis() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "r̂̈"; + + final EventList events = new EventList() + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint('r', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("both circumflex and diaeresis on r", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadCircumflexDeadDiaeresisBackspace() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "û"; + + final EventList events = new EventList() + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('u', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex, dead diaeresis, backspace, u", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadCircumflexDoubleDeadDiaeresisBackspace() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "\u02C6u"; + + final EventList events = new EventList() + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('u', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex, double dead diaeresis, backspace, u", EXPECTED_RESULT, + mEditText.getText().toString()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java b/tests/src/org/kelar/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java new file mode 100644 index 000000000..9b4e661be --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java @@ -0,0 +1,135 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import android.view.inputmethod.BaseInputConnection; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.common.Constants; + +@LargeTest +public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase { + public void testAutoCorrectForLanguageWithoutSpaces() { + final String STRING_TO_TYPE = "tgis is"; + final String EXPECTED_RESULT = "thisis"; + changeKeyboardLocaleAndDictLocale("th", "en_US"); + type(STRING_TO_TYPE); + assertEquals("simple auto-correct for language without spaces", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testRevertAutoCorrectForLanguageWithoutSpaces() { + final String STRING_TO_TYPE = "tgis "; + final String EXPECTED_INTERMEDIATE_RESULT = "this"; + final String EXPECTED_FINAL_RESULT = "tgis"; + changeKeyboardLocaleAndDictLocale("th", "en_US"); + type(STRING_TO_TYPE); + assertEquals("simple auto-correct for language without spaces", + EXPECTED_INTERMEDIATE_RESULT, mEditText.getText().toString()); + type(Constants.CODE_DELETE); + assertEquals("simple auto-correct for language without spaces", + EXPECTED_FINAL_RESULT, mEditText.getText().toString()); + // Check we are back to composing the word + assertEquals("don't resume suggestion on backspace", 0, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("don't resume suggestion on backspace", 4, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + } + + public void testDontResumeSuggestionOnBackspace() { + final String WORD_TO_TYPE = "and this "; + changeKeyboardLocaleAndDictLocale("th", "en_US"); + type(WORD_TO_TYPE); + assertEquals("don't resume suggestion on backspace", -1, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("don't resume suggestion on backspace", -1, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + type(" "); + type(Constants.CODE_DELETE); + assertEquals("don't resume suggestion on backspace", -1, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("don't resume suggestion on backspace", -1, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + } + + public void testStartComposingInsideText() { + final String WORD_TO_TYPE = "abcdefgh "; + final int typedLength = WORD_TO_TYPE.length() - 1; // -1 because space gets eaten + final int CURSOR_POS = 4; + changeKeyboardLocaleAndDictLocale("th", "en_US"); + type(WORD_TO_TYPE); + mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1); + mInputConnection.setSelection(CURSOR_POS, CURSOR_POS); + mLatinIME.onUpdateSelection(typedLength, typedLength, + CURSOR_POS, CURSOR_POS, -1, -1); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + assertEquals("start composing inside text", -1, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("start composing inside text", -1, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + type("xxxx"); + assertEquals("start composing inside text", 4, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("start composing inside text", 8, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + } + + public void testMovingCursorInsideWordAndType() { + final String WORD_TO_TYPE = "abcdefgh"; + final int typedLength = WORD_TO_TYPE.length(); + final int CURSOR_POS = 4; + changeKeyboardLocaleAndDictLocale("th", "en_US"); + type(WORD_TO_TYPE); + mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, 0, typedLength); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + mInputConnection.setSelection(CURSOR_POS, CURSOR_POS); + mLatinIME.onUpdateSelection(typedLength, typedLength, + CURSOR_POS, CURSOR_POS, 0, typedLength); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + assertEquals("move cursor inside text", 0, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("move cursor inside text", typedLength, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + type("x"); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + assertEquals("start typing while cursor inside composition", CURSOR_POS, + BaseInputConnection.getComposingSpanStart(mEditText.getText())); + assertEquals("start typing while cursor inside composition", CURSOR_POS + 1, + BaseInputConnection.getComposingSpanEnd(mEditText.getText())); + } + + public void testPredictions() { + final String WORD_TO_TYPE = "Barack "; + changeKeyboardLocaleAndDictLocale("th", "en_US"); + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + // Make sure there is no space + assertEquals("predictions in lang without spaces", "Barack", + mEditText.getText().toString()); + // Test the first prediction is displayed + final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("predictions in lang without spaces", "Obama", + suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/InputTestsBase.java b/tests/src/org/kelar/inputmethod/latin/InputTestsBase.java new file mode 100644 index 000000000..e57b6823f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/InputTestsBase.java @@ -0,0 +1,463 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import android.content.Context; +import android.content.SharedPreferences; +import android.graphics.Point; +import android.os.Looper; +import android.preference.PreferenceManager; +import android.test.ServiceTestCase; +import android.text.InputType; +import android.text.SpannableStringBuilder; +import android.text.style.CharacterStyle; +import android.text.style.SuggestionSpan; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputMethodSubtype; +import android.widget.EditText; +import android.widget.FrameLayout; + +import org.kelar.inputmethod.compat.InputMethodSubtypeCompatUtils; +import org.kelar.inputmethod.event.Event; +import org.kelar.inputmethod.keyboard.Key; +import org.kelar.inputmethod.keyboard.Keyboard; +import org.kelar.inputmethod.latin.Dictionary.PhonyDictionary; +import org.kelar.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.common.InputPointers; +import org.kelar.inputmethod.latin.common.LocaleUtils; +import org.kelar.inputmethod.latin.common.StringUtils; +import org.kelar.inputmethod.latin.settings.DebugSettings; +import org.kelar.inputmethod.latin.settings.Settings; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Locale; +import java.util.concurrent.TimeUnit; + +public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { + private static final String TAG = InputTestsBase.class.getSimpleName(); + + // Default value for auto-correction threshold. This is the string representation of the + // index in the resources array of auto-correction threshold settings. + private static final boolean DEFAULT_AUTO_CORRECTION = true; + + // The message that sets the underline is posted with a 500 ms delay + protected static final int DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS = 500; + // The message that sets predictions is posted with a 200 ms delay + protected static final int DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS = 200; + // We wait for gesture computation for this delay + protected static final int DELAY_TO_WAIT_FOR_GESTURE_MILLIS = 200; + // If a dictionary takes longer to load, we could have serious problems. + private final int TIMEOUT_TO_WAIT_FOR_LOADING_MAIN_DICTIONARY_IN_SECONDS = 5; + + // Type for a test phony dictionary + private static final String TYPE_TEST = "test"; + private static final PhonyDictionary DICTIONARY_TEST = new PhonyDictionary(TYPE_TEST); + + protected LatinIME mLatinIME; + protected Keyboard mKeyboard; + protected MyEditText mEditText; + protected View mInputView; + protected InputConnection mInputConnection; + private boolean mPreviousAutoCorrectSetting; + private boolean mPreviousBigramPredictionSettings; + + // A helper class to ease span tests + public static class SpanGetter { + final SpannableStringBuilder mInputText; + final CharacterStyle mSpan; + final int mStart; + final int mEnd; + // The supplied CharSequence should be an instance of SpannableStringBuilder, + // and it should contain exactly zero or one span. Otherwise, an exception + // is thrown. + public SpanGetter(final CharSequence inputText, + final Class<? extends CharacterStyle> spanType) { + mInputText = (SpannableStringBuilder)inputText; + final CharacterStyle[] spans = + mInputText.getSpans(0, mInputText.length(), spanType); + if (0 == spans.length) { + mSpan = null; + mStart = -1; + mEnd = -1; + } else if (1 == spans.length) { + mSpan = spans[0]; + mStart = mInputText.getSpanStart(mSpan); + mEnd = mInputText.getSpanEnd(mSpan); + } else { + throw new RuntimeException("Expected one span, found " + spans.length); + } + } + public SuggestionSpan getSpan() { + return (SuggestionSpan) mSpan; + } + public boolean isAutoCorrectionIndicator() { + return (mSpan instanceof SuggestionSpan) && + 0 != (SuggestionSpan.FLAG_AUTO_CORRECTION & getSpan().getFlags()); + } + public String[] getSuggestions() { + return getSpan().getSuggestions(); + } + } + + // A helper class to increase control over the EditText + public static class MyEditText extends EditText { + public Locale mCurrentLocale; + public MyEditText(final Context c) { + super(c); + } + + @Override + public void onAttachedToWindow() { + // Make onAttachedToWindow "public" + super.onAttachedToWindow(); + } + + // overriding hidden API in EditText + public Locale getTextServicesLocale() { + // This method is necessary because EditText is asking this method for the language + // to check the spell in. If we don't override this, the spell checker will run in + // whatever language the keyboard is currently set on the test device, ignoring any + // settings we do inside the tests. + return mCurrentLocale; + } + + // overriding hidden API in EditText + public Locale getSpellCheckerLocale() { + // This method is necessary because EditText is asking this method for the language + // to check the spell in. If we don't override this, the spell checker will run in + // whatever language the keyboard is currently set on the test device, ignoring any + // settings we do inside the tests. + return mCurrentLocale; + } + + } + + public InputTestsBase() { + super(LatinIMEForTests.class); + } + + protected boolean setBooleanPreference(final String key, final boolean value, + final boolean defaultValue) { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME); + final boolean previousSetting = prefs.getBoolean(key, defaultValue); + final SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(key, value); + editor.apply(); + return previousSetting; + } + + protected boolean getBooleanPreference(final String key, final boolean defaultValue) { + return PreferenceManager.getDefaultSharedPreferences(mLatinIME) + .getBoolean(key, defaultValue); + } + + protected String setStringPreference(final String key, final String value, + final String defaultValue) { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME); + final String previousSetting = prefs.getString(key, defaultValue); + final SharedPreferences.Editor editor = prefs.edit(); + editor.putString(key, value); + editor.apply(); + return previousSetting; + } + + protected void setDebugMode(final boolean value) { + setBooleanPreference(DebugSettings.PREF_DEBUG_MODE, value, false); + setBooleanPreference(Settings.PREF_KEY_IS_INTERNAL, value, false); + } + + protected EditorInfo enrichEditorInfo(final EditorInfo ei) { + // Some tests that inherit from us need to add some data in the EditorInfo (see + // AppWorkaroundsTests#enrichEditorInfo() for a concrete example of this). Since we + // control the EditorInfo, we supply a hook here for children to override. + return ei; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mEditText = new MyEditText(getContext()); + final int inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT + | InputType.TYPE_TEXT_FLAG_MULTI_LINE; + mEditText.setInputType(inputType); + mEditText.setEnabled(true); + mLastCursorPos = 0; + if (null == Looper.myLooper()) { + Looper.prepare(); + } + setupService(); + mLatinIME = getService(); + setDebugMode(true); + mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, + true, true /* defaultValue */); + mPreviousAutoCorrectSetting = setBooleanPreference(Settings.PREF_AUTO_CORRECTION, + DEFAULT_AUTO_CORRECTION, DEFAULT_AUTO_CORRECTION); + mLatinIME.onCreate(); + EditorInfo ei = new EditorInfo(); + final InputConnection ic = mEditText.onCreateInputConnection(ei); + final LayoutInflater inflater = + (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + final ViewGroup vg = new FrameLayout(getContext()); + mInputView = inflater.inflate(R.layout.input_view, vg); + ei = enrichEditorInfo(ei); + mLatinIME.onCreateInputMethodInterface().startInput(ic, ei); + mLatinIME.setInputView(mInputView); + mLatinIME.onBindInput(); + mLatinIME.onCreateInputView(); + mLatinIME.onStartInputView(ei, false); + mInputConnection = ic; + changeLanguage("en_US"); + // Run messages to avoid the messages enqueued by startInputView() and its friends + // to run on a later call and ruin things. We need to wait first because some of them + // can be posted with a delay (notably, MSG_RESUME_SUGGESTIONS) + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + } + + @Override + protected void tearDown() throws Exception { + mLatinIME.onFinishInputView(true); + mLatinIME.onFinishInput(); + runMessages(); + mLatinIME.mHandler.removeAllMessages(); + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings, + true /* defaultValue */); + setBooleanPreference(Settings.PREF_AUTO_CORRECTION, mPreviousAutoCorrectSetting, + DEFAULT_AUTO_CORRECTION); + setDebugMode(false); + mLatinIME.recycle(); + super.tearDown(); + mLatinIME = null; + } + + // We need to run the messages added to the handler from LatinIME. The only way to do + // that is to call Looper#loop() on the right looper, so we're going to get the looper + // object and call #loop() here. The messages in the handler actually run on the UI + // thread of the keyboard by design of the handler, so we want to call it synchronously + // on the same thread that the tests are running on to mimic the actual environment as + // closely as possible. + // Now, Looper#loop() never exits in normal operation unless the Looper#quit() method + // is called, which has a lot of bad side effects. We can however just throw an exception + // in the runnable which will unwind the stack and allow us to exit. + final class InterruptRunMessagesException extends RuntimeException { + // Empty class + } + protected void runMessages() { + mLatinIME.mHandler.post(new Runnable() { + @Override + public void run() { + throw new InterruptRunMessagesException(); + } + }); + try { + Looper.loop(); + } catch (InterruptRunMessagesException e) { + // Resume normal operation + } + } + + // type(int) and type(String): helper methods to send a code point resp. a string to LatinIME. + protected void typeInternal(final int codePoint, final boolean isKeyRepeat) { + // onPressKey and onReleaseKey are explicitly deactivated here, but they do happen in the + // code (although multitouch/slide input and other factors make the sequencing complicated). + // They are supposed to be entirely deconnected from the input logic from LatinIME point of + // view and only delegates to the parts of the code that care. So we don't include them here + // to keep these tests as pinpoint as possible and avoid bringing it too many dependencies, + // but keep them in mind if something breaks. Commenting them out as is should work. + //mLatinIME.onPressKey(codePoint, 0 /* repeatCount */, true /* isSinglePointer */); + final Key key = mKeyboard.getKey(codePoint); + final Event event; + if (key == null) { + event = Event.createSoftwareKeypressEvent(codePoint, Event.NOT_A_KEY_CODE, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, isKeyRepeat); + } else { + final int x = key.getX() + key.getWidth() / 2; + final int y = key.getY() + key.getHeight() / 2; + event = LatinIME.createSoftwareKeypressEvent(codePoint, x, y, isKeyRepeat); + } + mLatinIME.onEvent(event); + // Also see the comment at the top of this function about onReleaseKey + //mLatinIME.onReleaseKey(codePoint, false /* withSliding */); + } + + protected void type(final int codePoint) { + typeInternal(codePoint, false /* isKeyRepeat */); + } + + protected void repeatKey(final int codePoint) { + typeInternal(codePoint, true /* isKeyRepeat */); + } + + protected void type(final String stringToType) { + for (int i = 0; i < stringToType.length(); i = stringToType.offsetByCodePoints(i, 1)) { + type(stringToType.codePointAt(i)); + } + } + + protected Point getXY(final int codePoint) { + final Key key = mKeyboard.getKey(codePoint); + if (key == null) { + throw new RuntimeException("Code point not on the keyboard"); + } + return new Point(key.getX() + key.getWidth() / 2, key.getY() + key.getHeight() / 2); + } + + protected void gesture(final String stringToGesture) { + if (StringUtils.codePointCount(stringToGesture) < 2) { + throw new RuntimeException("Can't gesture strings less than 2 chars long"); + } + + mLatinIME.onStartBatchInput(); + final int startCodePoint = stringToGesture.codePointAt(0); + Point oldPoint = getXY(startCodePoint); + int timestamp = 0; // In milliseconds since the start of the gesture + final InputPointers pointers = new InputPointers(Constants.DEFAULT_GESTURE_POINTS_CAPACITY); + pointers.addPointer(oldPoint.x, oldPoint.y, 0 /* pointerId */, timestamp); + + for (int i = Character.charCount(startCodePoint); i < stringToGesture.length(); + i = stringToGesture.offsetByCodePoints(i, 1)) { + final Point newPoint = getXY(stringToGesture.codePointAt(i)); + // Arbitrarily 0.5s between letters and 0.1 between events. Refine this later if needed. + final int STEPS = 5; + for (int j = 0; j < STEPS; ++j) { + timestamp += 100; + pointers.addPointer(oldPoint.x + ((newPoint.x - oldPoint.x) * j) / STEPS, + oldPoint.y + ((newPoint.y - oldPoint.y) * j) / STEPS, + 0 /* pointerId */, timestamp); + } + oldPoint.x = newPoint.x; + oldPoint.y = newPoint.y; + mLatinIME.onUpdateBatchInput(pointers); + } + mLatinIME.onEndBatchInput(pointers); + sleep(DELAY_TO_WAIT_FOR_GESTURE_MILLIS); + runMessages(); + } + + protected void waitForDictionariesToBeLoaded() { + try { + mLatinIME.waitForLoadingDictionaries( + TIMEOUT_TO_WAIT_FOR_LOADING_MAIN_DICTIONARY_IN_SECONDS, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Log.e(TAG, "Interrupted during waiting for loading main dictionary.", e); + } + } + + protected void changeLanguage(final String locale) { + changeLanguage(locale, null); + } + + protected void changeLanguage(final String locale, final String combiningSpec) { + changeLanguageWithoutWait(locale, combiningSpec); + waitForDictionariesToBeLoaded(); + } + + protected void changeLanguageWithoutWait(final String locale, final String combiningSpec) { + mEditText.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); + // TODO: this is forcing a QWERTY keyboard for all locales, which is wrong. + // It's still better than using whatever keyboard is the current one, but we + // should actually use the default keyboard for this locale. + // TODO: Use {@link InputMethodSubtype.InputMethodSubtypeBuilder} directly or indirectly so + // that {@link InputMethodSubtype#isAsciiCapable} can return the correct value. + final String EXTRA_VALUE_FOR_TEST = + "KeyboardLayoutSet=" + SubtypeLocaleUtils.QWERTY + + "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE + + "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE + + "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE + + null == combiningSpec ? "" : ("," + combiningSpec); + final InputMethodSubtype subtype = InputMethodSubtypeCompatUtils.newInputMethodSubtype( + R.string.subtype_no_language_qwerty, + R.drawable.ic_ime_switcher_dark, + locale, + Constants.Subtype.KEYBOARD_MODE, + EXTRA_VALUE_FOR_TEST, + false /* isAuxiliary */, + false /* overridesImplicitlyEnabledSubtype */, + 0 /* id */); + RichInputMethodManager.forceSubtype(subtype); + mLatinIME.onCurrentInputMethodSubtypeChanged(subtype); + runMessages(); + mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); + mLatinIME.clearPersonalizedDictionariesForTest(); + } + + protected void changeKeyboardLocaleAndDictLocale(final String keyboardLocale, + final String dictLocale) { + changeLanguage(keyboardLocale); + if (!keyboardLocale.equals(dictLocale)) { + mLatinIME.replaceDictionariesForTest(LocaleUtils.constructLocaleFromString(dictLocale)); + } + waitForDictionariesToBeLoaded(); + } + + protected void pickSuggestionManually(final String suggestion) { + mLatinIME.pickSuggestionManually(new SuggestedWordInfo(suggestion, + "" /* prevWordsContext */, 1 /* score */, + SuggestedWordInfo.KIND_CORRECTION, DICTIONARY_TEST, + SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, + SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */)); + } + + // Helper to avoid writing the try{}catch block each time + protected static void sleep(final int milliseconds) { + try { + Thread.sleep(milliseconds); + } catch (InterruptedException e) {} + } + + // Some helper methods to manage the mock cursor position + // DO NOT CALL LatinIME#onUpdateSelection IF YOU WANT TO USE THOSE + int mLastCursorPos = 0; + /** + * Move the cached cursor position to the passed position and send onUpdateSelection to LatinIME + */ + protected int sendUpdateForCursorMoveTo(final int position) { + mInputConnection.setSelection(position, position); + mLatinIME.onUpdateSelection(mLastCursorPos, mLastCursorPos, position, position, -1, -1); + mLastCursorPos = position; + return position; + } + + /** + * Move the cached cursor position by the passed amount and send onUpdateSelection to LatinIME + */ + protected int sendUpdateForCursorMoveBy(final int offset) { + final int lastPos = mEditText.getText().length(); + final int requestedPosition = mLastCursorPos + offset; + if (requestedPosition < 0) { + return sendUpdateForCursorMoveTo(0); + } else if (requestedPosition > lastPos) { + return sendUpdateForCursorMoveTo(lastPos); + } else { + return sendUpdateForCursorMoveTo(requestedPosition); + } + } + + /** + * Move the cached cursor position to the end of the line and send onUpdateSelection to LatinIME + */ + protected int sendUpdateForCursorMoveToEndOfLine() { + final int lastPos = mEditText.getText().length(); + return sendUpdateForCursorMoveTo(lastPos); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/LatinIMEForTests.java b/tests/src/org/kelar/inputmethod/latin/LatinIMEForTests.java new file mode 100644 index 000000000..f9e975556 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/LatinIMEForTests.java @@ -0,0 +1,36 @@ +/* + * 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 org.kelar.inputmethod.latin; + +public class LatinIMEForTests extends LatinIME { + @Override + public boolean isInputViewShown() { + return true; + } + + private boolean deallocateMemoryWasPerformed = false; + + @Override + protected void deallocateMemory() { + super.deallocateMemory(); + deallocateMemoryWasPerformed = true; + } + + public boolean getDeallocateMemoryWasPerformed() { + return deallocateMemoryWasPerformed; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/LatinImeStressTests.java b/tests/src/org/kelar/inputmethod/latin/LatinImeStressTests.java new file mode 100644 index 000000000..6b9f65931 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/LatinImeStressTests.java @@ -0,0 +1,62 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.common.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[] codePointSet = CodePointUtils.LATIN_ALPHABETS_LOWER; + for (int i = 0; i < switchCount; ++i) { + changeLanguageWithoutWait(locales[random.nextInt(locales.length)], + null /* combiningSpec */); + final int wordCount = random.nextInt(maxWordCountToTypeInEachIteration); + for (int j = 0; j < wordCount; ++j) { + final String word = CodePointUtils.generateWord(random, codePointSet); + type(word); + } + } + } + public void testSwitchLanguagesAndInputRandomCodePoints() { + 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)], + null /* combiningSpec */); + 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/org/kelar/inputmethod/latin/LatinImeTests.java b/tests/src/org/kelar/inputmethod/latin/LatinImeTests.java new file mode 100644 index 000000000..5d3d04783 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/LatinImeTests.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import androidx.test.filters.LargeTest; + +@LargeTest +public class LatinImeTests extends InputTestsBase { + public void testDeferredDeallocation_doesntHappenBeforeTimeout() { + mLatinIME.mHandler.onFinishInputView(true); + runMessages(); + sleep(1000); // 1s + runMessages(); + assertFalse("memory deallocation performed before timeout passed", + ((LatinIMEForTests)mLatinIME).getDeallocateMemoryWasPerformed()); + } + + public void testDeferredDeallocation_doesHappenAfterTimeout() { + mLatinIME.mHandler.onFinishInputView(true); + runMessages(); + sleep(11000); // 11s (timeout is at 10s) + runMessages(); + assertTrue("memory deallocation not performed although timeout passed", + ((LatinIMEForTests)mLatinIME).getDeallocateMemoryWasPerformed()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/NgramContextTests.java b/tests/src/org/kelar/inputmethod/latin/NgramContextTests.java new file mode 100644 index 000000000..07b66271d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/NgramContextTests.java @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.NgramContext.WordInfo; +import org.kelar.inputmethod.latin.settings.SpacingAndPunctuations; +import org.kelar.inputmethod.latin.utils.NgramContextUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class NgramContextTests { + + @Test + public void testConstruct() { + assertEquals(new NgramContext(new WordInfo("a")), new NgramContext(new WordInfo("a"))); + assertEquals(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO), + new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO)); + assertEquals(new NgramContext(WordInfo.EMPTY_WORD_INFO), + new NgramContext(WordInfo.EMPTY_WORD_INFO)); + assertEquals(new NgramContext(WordInfo.EMPTY_WORD_INFO), + new NgramContext(WordInfo.EMPTY_WORD_INFO)); + } + + @Test + public void testIsBeginningOfSentenceContext() { + assertFalse(new NgramContext().isBeginningOfSentenceContext()); + assertTrue(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO) + .isBeginningOfSentenceContext()); + assertTrue(NgramContext.BEGINNING_OF_SENTENCE.isBeginningOfSentenceContext()); + assertFalse(new NgramContext(new WordInfo("a")).isBeginningOfSentenceContext()); + assertFalse(new NgramContext(new WordInfo("")).isBeginningOfSentenceContext()); + assertFalse(new NgramContext(WordInfo.EMPTY_WORD_INFO).isBeginningOfSentenceContext()); + assertTrue(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO, new WordInfo("a")) + .isBeginningOfSentenceContext()); + assertFalse(new NgramContext(new WordInfo("a"), WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO) + .isBeginningOfSentenceContext()); + assertFalse(new NgramContext( + WordInfo.EMPTY_WORD_INFO, WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO) + .isBeginningOfSentenceContext()); + } + + @Test + public void testGetNextNgramContext() { + final NgramContext ngramContext_a = new NgramContext(new WordInfo("a")); + final NgramContext ngramContext_b_a = + ngramContext_a.getNextNgramContext(new WordInfo("b")); + assertEquals("b", ngramContext_b_a.getNthPrevWord(1)); + assertEquals("a", ngramContext_b_a.getNthPrevWord(2)); + final NgramContext ngramContext_bos_b = + ngramContext_b_a.getNextNgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); + assertTrue(ngramContext_bos_b.isBeginningOfSentenceContext()); + assertEquals("b", ngramContext_bos_b.getNthPrevWord(2)); + final NgramContext ngramContext_c_bos = + ngramContext_b_a.getNextNgramContext(new WordInfo("c")); + assertEquals("c", ngramContext_c_bos.getNthPrevWord(1)); + } + + @Test + public void testExtractPrevWordsContextTest() { + final NgramContext ngramContext_bos = + new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); + assertEquals("<S>", ngramContext_bos.extractPrevWordsContext()); + final NgramContext ngramContext_a = new NgramContext(new WordInfo("a")); + final NgramContext ngramContext_b_a = + ngramContext_a.getNextNgramContext(new WordInfo("b")); + assertEquals("b", ngramContext_b_a.getNthPrevWord(1)); + assertEquals("a", ngramContext_b_a.getNthPrevWord(2)); + assertEquals("a b", ngramContext_b_a.extractPrevWordsContext()); + + final NgramContext ngramContext_bos_b = + ngramContext_b_a.getNextNgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); + assertTrue(ngramContext_bos_b.isBeginningOfSentenceContext()); + assertEquals("b", ngramContext_bos_b.getNthPrevWord(2)); + assertEquals("a b <S>", ngramContext_bos_b.extractPrevWordsContext()); + + final NgramContext ngramContext_empty = new NgramContext(WordInfo.EMPTY_WORD_INFO); + assertEquals("", ngramContext_empty.extractPrevWordsContext()); + final NgramContext ngramContext_a_empty = + ngramContext_empty.getNextNgramContext(new WordInfo("a")); + assertEquals("a", ngramContext_a_empty.getNthPrevWord(1)); + assertEquals("a", ngramContext_a_empty.extractPrevWordsContext()); + } + + @Test + public void testExtractPrevWordsContextArray() { + final NgramContext ngramContext_bos = + new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); + assertEquals("<S>", ngramContext_bos.extractPrevWordsContext()); + assertEquals(1, ngramContext_bos.extractPrevWordsContextArray().length); + final NgramContext ngramContext_a = new NgramContext(new WordInfo("a")); + final NgramContext ngramContext_b_a = + ngramContext_a.getNextNgramContext(new WordInfo("b")); + assertEquals(2, ngramContext_b_a.extractPrevWordsContextArray().length); + assertEquals("b", ngramContext_b_a.getNthPrevWord(1)); + assertEquals("a", ngramContext_b_a.getNthPrevWord(2)); + assertEquals("a", ngramContext_b_a.extractPrevWordsContextArray()[0]); + assertEquals("b", ngramContext_b_a.extractPrevWordsContextArray()[1]); + + final NgramContext ngramContext_bos_b = + ngramContext_b_a.getNextNgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); + assertTrue(ngramContext_bos_b.isBeginningOfSentenceContext()); + assertEquals(3, ngramContext_bos_b.extractPrevWordsContextArray().length); + assertEquals("b", ngramContext_bos_b.getNthPrevWord(2)); + assertEquals("a", ngramContext_bos_b.extractPrevWordsContextArray()[0]); + assertEquals("b", ngramContext_bos_b.extractPrevWordsContextArray()[1]); + assertEquals("<S>", ngramContext_bos_b.extractPrevWordsContextArray()[2]); + + final NgramContext ngramContext_empty = new NgramContext(WordInfo.EMPTY_WORD_INFO); + assertEquals(0, ngramContext_empty.extractPrevWordsContextArray().length); + final NgramContext ngramContext_a_empty = + ngramContext_empty.getNextNgramContext(new WordInfo("a")); + assertEquals(1, ngramContext_a_empty.extractPrevWordsContextArray().length); + assertEquals("a", ngramContext_a_empty.extractPrevWordsContextArray()[0]); + } + + @Test + public void testGetNgramContextFromNthPreviousWord() { + SpacingAndPunctuations spacingAndPunctuations = new SpacingAndPunctuations( + InstrumentationRegistry.getTargetContext().getResources()); + assertEquals("<S>", NgramContextUtils.getNgramContextFromNthPreviousWord("", + spacingAndPunctuations, 1).extractPrevWordsContext()); + assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a. b ", + spacingAndPunctuations, 1).extractPrevWordsContext()); + assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a? b ", + spacingAndPunctuations, 1).extractPrevWordsContext()); + assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a! b ", + spacingAndPunctuations, 1).extractPrevWordsContext()); + assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a\nb ", + spacingAndPunctuations, 1).extractPrevWordsContext()); + assertEquals("<S> a b", NgramContextUtils.getNgramContextFromNthPreviousWord("a b ", + spacingAndPunctuations, 1).extractPrevWordsContext()); + assertFalse(NgramContextUtils + .getNgramContextFromNthPreviousWord("a b c d e", spacingAndPunctuations, 1) + .extractPrevWordsContext().startsWith("<S>")); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/PunctuationTests.java b/tests/src/org/kelar/inputmethod/latin/PunctuationTests.java new file mode 100644 index 000000000..c8337430d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/PunctuationTests.java @@ -0,0 +1,199 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import android.provider.Settings.Secure; + +import androidx.test.filters.LargeTest; + +@LargeTest +public class PunctuationTests extends InputTestsBase { + + final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; + + public void testWordThenSpaceThenPunctuationFromStripTwice() { + final String WORD_TO_TYPE = "this "; + final String PUNCTUATION_FROM_STRIP = "!"; + final String EXPECTED_RESULT = "this!! "; + final boolean defaultNextWordPredictionOption = + mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); + final boolean previousNextWordPredictionOption = + setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false, + defaultNextWordPredictionOption); + try { + mLatinIME.loadSettings(); + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + assertTrue("type word then type space should display punctuation strip", + mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + assertEquals("type word then type space then punctuation from strip twice", + EXPECTED_RESULT, mEditText.getText().toString()); + } finally { + setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption, + defaultNextWordPredictionOption); + } + } + + public void testWordThenSpaceThenPunctuationFromKeyboardTwice() { + final String WORD_TO_TYPE = "this !!"; + final String EXPECTED_RESULT = "this !!"; + type(WORD_TO_TYPE); + assertEquals("manual pick then space then punctuation from keyboard twice", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManualPickThenPunctuationFromStripTwiceThenType() { + final String WORD1_TO_TYPE = "this"; + final String WORD2_TO_TYPE = "is"; + final String PUNCTUATION_FROM_STRIP = "!"; + final String EXPECTED_RESULT = "this!! is"; + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + type(WORD2_TO_TYPE); + assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManualPickThenManualPickWithPunctAtStart() { + final String WORD1_TO_TYPE = "this"; + final String WORD2_TO_PICK = "!is"; + final String EXPECTED_RESULT = "this!is"; + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + pickSuggestionManually(WORD2_TO_PICK); + assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManuallyPickedWordThenColon() { + final String WORD_TO_TYPE = "this"; + final String PUNCTUATION = ":"; + final String EXPECTED_RESULT = "this:"; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + type(PUNCTUATION); + assertEquals("manually pick word then colon", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testManuallyPickedWordThenOpenParen() { + final String WORD_TO_TYPE = "this"; + final String PUNCTUATION = "("; + final String EXPECTED_RESULT = "this ("; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + type(PUNCTUATION); + assertEquals("manually pick word then open paren", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testManuallyPickedWordThenCloseParen() { + final String WORD_TO_TYPE = "this"; + final String PUNCTUATION = ")"; + final String EXPECTED_RESULT = "this)"; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + type(PUNCTUATION); + assertEquals("manually pick word then close paren", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testManuallyPickedWordThenSmiley() { + final String WORD_TO_TYPE = "this"; + final String SPECIAL_KEY = ":-)"; + final String EXPECTED_RESULT = "this :-)"; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + mLatinIME.onTextInput(SPECIAL_KEY); + assertEquals("manually pick word then press the smiley key", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testManuallyPickedWordThenDotCom() { + final String WORD_TO_TYPE = "this"; + final String SPECIAL_KEY = ".com"; + final String EXPECTED_RESULT = "this.com"; + type(WORD_TO_TYPE); + pickSuggestionManually(WORD_TO_TYPE); + mLatinIME.onTextInput(SPECIAL_KEY); + assertEquals("manually pick word then press the .com key", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testTypeWordTypeDotThenPressDotCom() { + final String WORD_TO_TYPE = "this."; + final String SPECIAL_KEY = ".com"; + final String EXPECTED_RESULT = "this.com"; + type(WORD_TO_TYPE); + mLatinIME.onTextInput(SPECIAL_KEY); + assertEquals("type word type dot then press the .com key", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoCorrectionWithSingleQuoteInside() { + final String WORD_TO_TYPE = "you'f "; + final String EXPECTED_RESULT = "you'd "; + type(WORD_TO_TYPE); + assertEquals("auto-correction with single quote inside. ID = " + + Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID) + + " ; Suggestions = " + mLatinIME.getSuggestedWordsForTest(), + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoCorrectionWithSingleQuotesAround() { + final String WORD_TO_TYPE = "'tgis' "; + final String EXPECTED_RESULT = "'this' "; + type(WORD_TO_TYPE); + assertEquals("auto-correction with single quotes around. ID = " + + Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID) + + " ; Suggestions = " + mLatinIME.getSuggestedWordsForTest(), + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testAutoSpaceWithDoubleQuotes() { + final String STRING_TO_TYPE = "He said\"hello\"to me. I replied,\"hi\"." + + "Then, 5\"passed. He said\"bye\"and left."; + final String EXPECTED_RESULT = "He said \"hello\" to me. I replied, \"hi\". " + + "Then, 5\" passed. He said \"bye\" and left. \""; + // Split by double quote, so that we can type the double quotes individually. + for (final String partToType : STRING_TO_TYPE.split("\"")) { + // Split at word boundaries. This regexp means "anywhere that is preceded + // by a word character but not followed by a word character, OR that is not + // preceded by a word character but followed by a word character". + // We need to input word by word because auto-spaces are only active when + // manually picking or gesturing (which we can't simulate yet), but only words + // can be picked. + final String[] wordsToType = partToType.split("(?<=\\w)(?!\\w)|(?<!\\w)(?=\\w)"); + for (final String wordToType : wordsToType) { + type(wordToType); + if (wordToType.matches("^\\w+$")) { + // Only pick selection if that was a word, because if that was not a word, + // then we don't have a composition. + pickSuggestionManually(wordToType); + } + } + type("\""); + } + assertEquals("auto-space with double quotes", + EXPECTED_RESULT, mEditText.getText().toString()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/org/kelar/inputmethod/latin/RichInputConnectionAndTextRangeTests.java new file mode 100644 index 000000000..cf4a349d5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/RichInputConnectionAndTextRangeTests.java @@ -0,0 +1,465 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.content.res.Resources; +import android.inputmethodservice.InputMethodService; +import android.os.Parcel; +import android.text.SpannableString; +import android.text.TextUtils; +import android.text.style.SuggestionSpan; +import android.view.inputmethod.ExtractedText; +import android.view.inputmethod.ExtractedTextRequest; +import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputConnectionWrapper; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.common.StringUtils; +import org.kelar.inputmethod.latin.settings.SpacingAndPunctuations; +import org.kelar.inputmethod.latin.utils.NgramContextUtils; +import org.kelar.inputmethod.latin.utils.RunInLocale; +import org.kelar.inputmethod.latin.utils.ScriptUtils; +import org.kelar.inputmethod.latin.utils.TextRange; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class RichInputConnectionAndTextRangeTests { + + // The following is meant to be a reasonable default for + // the "word_separators" resource. + private SpacingAndPunctuations mSpacingAndPunctuations; + + @Before + public void setUp() throws Exception { + final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() { + @Override + protected SpacingAndPunctuations job(final Resources res) { + return new SpacingAndPunctuations(res); + } + }; + final Resources res = InstrumentationRegistry.getTargetContext().getResources(); + mSpacingAndPunctuations = job.runInLocale(res, Locale.ENGLISH); + } + + private class MockConnection extends InputConnectionWrapper { + final CharSequence mTextBefore; + final CharSequence mTextAfter; + final ExtractedText mExtractedText; + + public MockConnection(final CharSequence text, final int cursorPosition) { + super(null, false); + // Interaction of spans with Parcels is completely non-trivial, but in the actual case + // the CharSequences do go through Parcels because they go through IPC. There + // are some significant differences between the behavior of Spanned objects that + // have and that have not gone through parceling, so it's much easier to simulate + // the environment with Parcels than try to emulate things by hand. + final Parcel p = Parcel.obtain(); + TextUtils.writeToParcel(text.subSequence(0, cursorPosition), p, 0 /* flags */); + TextUtils.writeToParcel(text.subSequence(cursorPosition, text.length()), p, + 0 /* flags */); + final byte[] marshalled = p.marshall(); + p.unmarshall(marshalled, 0, marshalled.length); + p.setDataPosition(0); + mTextBefore = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p); + mTextAfter = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p); + mExtractedText = null; + p.recycle(); + } + + public MockConnection(String textBefore, String textAfter, ExtractedText extractedText) { + super(null, false); + mTextBefore = textBefore; + mTextAfter = textAfter; + mExtractedText = extractedText; + } + + public int cursorPos() { + return mTextBefore.length(); + } + + /* (non-Javadoc) + * @see android.view.inputmethod.InputConnectionWrapper#getTextBeforeCursor(int, int) + */ + @Override + public CharSequence getTextBeforeCursor(int n, int flags) { + return mTextBefore; + } + + /* (non-Javadoc) + * @see android.view.inputmethod.InputConnectionWrapper#getTextAfterCursor(int, int) + */ + @Override + public CharSequence getTextAfterCursor(int n, int flags) { + return mTextAfter; + } + + /* (non-Javadoc) + * @see android.view.inputmethod.InputConnectionWrapper#getExtractedText( + * ExtractedTextRequest, int) + */ + @Override + public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) { + return mExtractedText; + } + + @Override + public boolean beginBatchEdit() { + return true; + } + + @Override + public boolean endBatchEdit() { + return true; + } + + @Override + public boolean finishComposingText() { + return true; + } + } + + static class MockInputMethodService extends InputMethodService { + private MockConnection mMockConnection; + public void setInputConnection(final MockConnection mockConnection) { + mMockConnection = mockConnection; + } + public int cursorPos() { + return mMockConnection.cursorPos(); + } + @Override + public InputConnection getCurrentInputConnection() { + return mMockConnection; + } + } + + /************************** Tests ************************/ + + /** + * Test for getting previous word (for bigram suggestions) + */ + @Test + public void testGetPreviousWord() { + // If one of the following cases breaks, the bigram suggestions won't work. + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 2).getNthPrevWord(1), "abc"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc. def", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE); + + assertFalse(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 2).isBeginningOfSentenceContext()); + assertTrue(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc", mSpacingAndPunctuations, 2).isBeginningOfSentenceContext()); + + // For n-gram + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 1).getNthPrevWord(1), "def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 1).getNthPrevWord(2), "abc"); + assertTrue(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 2).isNthPrevWordBeginningOfSentence(2)); + + // The following tests reflect the current behavior of the function + // RichInputConnection#getNthPreviousWord. + // TODO: However at this time, the code does never go + // into such a path, so it should be safe to change the behavior of + // this function if needed - especially since it does not seem very + // logical. These tests are just there to catch any unintentional + // changes in the behavior of the RichInputConnection#getPreviousWord method. + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def ", mSpacingAndPunctuations, 2).getNthPrevWord(1), "abc"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def.", mSpacingAndPunctuations, 2).getNthPrevWord(1), "abc"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def .", mSpacingAndPunctuations, 2).getNthPrevWord(1), "def"); + assertTrue(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc ", mSpacingAndPunctuations, 2).isBeginningOfSentenceContext()); + + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 1).getNthPrevWord(1), "def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def ", mSpacingAndPunctuations, 1).getNthPrevWord(1), "def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc 'def", mSpacingAndPunctuations, 1).getNthPrevWord(1), "'def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def.", mSpacingAndPunctuations, 1), NgramContext.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def .", mSpacingAndPunctuations, 1), NgramContext.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc, def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); + // question mark is treated as the end of the sentence. Hence, beginning of the + // sentence is expected. + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc? def", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE); + // Exclamation mark is treated as the end of the sentence. Hence, beginning of the + // sentence is expected. + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc! def", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc 'def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); + } + + @Test + public void testGetWordRangeAtCursor() { + /** + * Test logic in getting the word range at the cursor. + */ + final SpacingAndPunctuations SPACE = new SpacingAndPunctuations( + mSpacingAndPunctuations, new int[] { Constants.CODE_SPACE }); + final SpacingAndPunctuations TAB = new SpacingAndPunctuations( + mSpacingAndPunctuations, new int[] { Constants.CODE_TAB }); + // A character that needs surrogate pair to represent its code point (U+2008A). + final String SUPPLEMENTARY_CHAR_STRING = "\uD840\uDC8A"; + final SpacingAndPunctuations SUPPLEMENTARY_CHAR = new SpacingAndPunctuations( + mSpacingAndPunctuations, StringUtils.toSortedCodePointArray( + SUPPLEMENTARY_CHAR_STRING)); + final String HIRAGANA_WORD = "\u3042\u3044\u3046\u3048\u304A"; // あいうえお + final String GREEK_WORD = "\u03BA\u03B1\u03B9"; // και + + ExtractedText et = new ExtractedText(); + final MockInputMethodService mockInputMethodService = new MockInputMethodService(); + final RichInputConnection ic = new RichInputConnection(mockInputMethodService); + mockInputMethodService.setInputConnection(new MockConnection("word wo", "rd", et)); + et.startOffset = 0; + et.selectionStart = 7; + TextRange r; + + ic.beginBatchEdit(); + // basic case + r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); + assertTrue(TextUtils.equals("word", r.mWord)); + + // tab character instead of space + mockInputMethodService.setInputConnection(new MockConnection("one\tword\two", "rd", et)); + ic.beginBatchEdit(); + r = ic.getWordRangeAtCursor(TAB, ScriptUtils.SCRIPT_LATIN); + ic.endBatchEdit(); + assertTrue(TextUtils.equals("word", r.mWord)); + + // splitting on supplementary character + mockInputMethodService.setInputConnection( + new MockConnection("one word" + SUPPLEMENTARY_CHAR_STRING + "wo", "rd", et)); + ic.beginBatchEdit(); + r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_LATIN); + ic.endBatchEdit(); + assertTrue(TextUtils.equals("word", r.mWord)); + + // split on chars outside the specified script + mockInputMethodService.setInputConnection( + new MockConnection(HIRAGANA_WORD + "wo", "rd" + GREEK_WORD, et)); + ic.beginBatchEdit(); + r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_LATIN); + ic.endBatchEdit(); + assertTrue(TextUtils.equals("word", r.mWord)); + + // likewise for greek + mockInputMethodService.setInputConnection( + new MockConnection("text" + GREEK_WORD, "text", et)); + ic.beginBatchEdit(); + r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_GREEK); + ic.endBatchEdit(); + assertTrue(TextUtils.equals(GREEK_WORD, r.mWord)); + } + + /** + * Test logic in getting the word range at the cursor. + */ + @Test + public void testGetSuggestionSpansAtWord() { + helpTestGetSuggestionSpansAtWord(10); + helpTestGetSuggestionSpansAtWord(12); + helpTestGetSuggestionSpansAtWord(15); + helpTestGetSuggestionSpansAtWord(16); + } + + private void helpTestGetSuggestionSpansAtWord(final int cursorPos) { + final SpacingAndPunctuations SPACE = new SpacingAndPunctuations( + mSpacingAndPunctuations, new int[] { Constants.CODE_SPACE }); + final MockInputMethodService mockInputMethodService = new MockInputMethodService(); + final RichInputConnection ic = new RichInputConnection(mockInputMethodService); + + final String[] SUGGESTIONS1 = { "swing", "strong" }; + final String[] SUGGESTIONS2 = { "storing", "strung" }; + + // Test the usual case. + SpannableString text = new SpannableString("This is a string for test"); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0 /* flags */), + 10 /* start */, 16 /* end */, 0 /* flags */); + mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos)); + TextRange r; + SuggestionSpan[] suggestions; + + r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); + suggestions = r.getSuggestionSpansAtWord(); + assertEquals(suggestions.length, 1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + + // Test the case with 2 suggestion spans in the same place. + text = new SpannableString("This is a string for test"); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0 /* flags */), + 10 /* start */, 16 /* end */, 0 /* flags */); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0 /* flags */), + 10 /* start */, 16 /* end */, 0 /* flags */); + mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos)); + r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); + suggestions = r.getSuggestionSpansAtWord(); + assertEquals(suggestions.length, 2); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2); + + // Test a case with overlapping spans, 2nd extending past the start of the word + text = new SpannableString("This is a string for test"); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0 /* flags */), + 10 /* start */, 16 /* end */, 0 /* flags */); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0 /* flags */), + 5 /* start */, 16 /* end */, 0 /* flags */); + mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos)); + r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); + suggestions = r.getSuggestionSpansAtWord(); + assertEquals(suggestions.length, 1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + + // Test a case with overlapping spans, 2nd extending past the end of the word + text = new SpannableString("This is a string for test"); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0 /* flags */), + 10 /* start */, 16 /* end */, 0 /* flags */); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0 /* flags */), + 10 /* start */, 20 /* end */, 0 /* flags */); + mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos)); + r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); + suggestions = r.getSuggestionSpansAtWord(); + assertEquals(suggestions.length, 1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + + // Test a case with overlapping spans, 2nd extending past both ends of the word + text = new SpannableString("This is a string for test"); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0 /* flags */), + 10 /* start */, 16 /* end */, 0 /* flags */); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0 /* flags */), + 5 /* start */, 20 /* end */, 0 /* flags */); + mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos)); + r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); + suggestions = r.getSuggestionSpansAtWord(); + assertEquals(suggestions.length, 1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + + // Test a case with overlapping spans, none right on the word + text = new SpannableString("This is a string for test"); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0 /* flags */), + 5 /* start */, 16 /* end */, 0 /* flags */); + text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0 /* flags */), + 5 /* start */, 20 /* end */, 0 /* flags */); + mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos)); + r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); + suggestions = r.getSuggestionSpansAtWord(); + assertEquals(suggestions.length, 0); + } + + @Test + public void testCursorTouchingWord() { + final MockInputMethodService ims = new MockInputMethodService(); + final RichInputConnection ic = new RichInputConnection(ims); + final SpacingAndPunctuations sap = mSpacingAndPunctuations; + + ims.setInputConnection(new MockConnection("users", 5)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true /* checkTextAfter */)); + + ims.setInputConnection(new MockConnection("users'", 5)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("users'", 6)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("'users'", 6)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("'users'", 7)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("users '", 6)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("users '", 7)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("re-", 3)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("re--", 4)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("-", 1)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection("--", 2)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection(" -", 2)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection(" --", 3)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection(" users '", 1)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection(" users '", 3)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection(" users '", 7)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection(" users are", 7)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertTrue(ic.isCursorTouchingWord(sap, true)); + + ims.setInputConnection(new MockConnection(" users 'are", 7)); + ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true); + assertFalse(ic.isCursorTouchingWord(sap, true)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/RichInputMethodSubtypeTests.java b/tests/src/org/kelar/inputmethod/latin/RichInputMethodSubtypeTests.java new file mode 100644 index 000000000..f28ba53cd --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/RichInputMethodSubtypeTests.java @@ -0,0 +1,334 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.content.res.Resources; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.utils.AdditionalSubtypeUtils; +import org.kelar.inputmethod.latin.utils.RunInLocale; +import org.kelar.inputmethod.latin.utils.SubtypeLocaleUtils; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class RichInputMethodSubtypeTests { + // All input method subtypes of LatinIME. + private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>(); + + private RichInputMethodManager mRichImm; + private Resources mRes; + private InputMethodSubtype mSavedAddtionalSubtypes[]; + + RichInputMethodSubtype EN_US; + RichInputMethodSubtype EN_GB; + RichInputMethodSubtype ES_US; + RichInputMethodSubtype FR; + RichInputMethodSubtype FR_CA; + RichInputMethodSubtype FR_CH; + RichInputMethodSubtype DE; + RichInputMethodSubtype DE_CH; + RichInputMethodSubtype HI; + RichInputMethodSubtype SR; + RichInputMethodSubtype ZZ; + RichInputMethodSubtype DE_QWERTY; + RichInputMethodSubtype FR_QWERTZ; + RichInputMethodSubtype EN_US_AZERTY; + RichInputMethodSubtype EN_UK_DVORAK; + RichInputMethodSubtype ES_US_COLEMAK; + RichInputMethodSubtype ZZ_AZERTY; + RichInputMethodSubtype ZZ_PC; + + // 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; + + @Before + public void setUp() throws Exception { + final Context context = InstrumentationRegistry.getTargetContext(); + mRes = context.getResources(); + RichInputMethodManager.init(context); + mRichImm = RichInputMethodManager.getInstance(); + + // Save and reset additional subtypes + mSavedAddtionalSubtypes = mRichImm.getAdditionalSubtypes(); + 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(); + for (int index = 0; index < subtypeCount; index++) { + final InputMethodSubtype subtype = imi.getSubtypeAt(index); + mSubtypesList.add(new RichInputMethodSubtype(subtype)); + } + + EN_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.US.toString(), "qwerty")); + EN_GB = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.UK.toString(), "qwerty")); + ES_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "es_US", "spanish")); + FR = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.FRENCH.toString(), "azerty")); + FR_CA = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.CANADA_FRENCH.toString(), "qwerty")); + FR_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "fr_CH", "swiss")); + DE = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + 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( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.GERMAN.toString(), "qwerty")); + FR_QWERTZ = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.FRENCH.toString(), "qwertz")); + EN_US_AZERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.US.toString(), "azerty")); + EN_UK_DVORAK = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.UK.toString(), "dvorak")); + ES_US_COLEMAK = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + "es_US", "colemak")); + ZZ_AZERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + SubtypeLocaleUtils.NO_LANGUAGE, "azerty")); + ZZ_PC = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty")); + + final InputMethodSubtype hiLatn = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "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")); + } + } + + @After + public void tearDown() throws Exception { + // Restore additional subtypes. + mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes); + } + + @Test + public void testAllFullDisplayNameForSpacebar() { + for (final RichInputMethodSubtype subtype : mSubtypesList) { + final String subtypeName = SubtypeLocaleUtils + .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype()); + final String spacebarText = subtype.getFullDisplayName(); + final String languageName = SubtypeLocaleUtils + .getSubtypeLocaleDisplayName(subtype.getLocale().toString()); + if (subtype.isNoLanguage()) { + assertFalse(subtypeName, spacebarText.contains(languageName)); + } else { + assertTrue(subtypeName, spacebarText.contains(languageName)); + } + } + } + + @Test + public void testAllMiddleDisplayNameForSpacebar() { + for (final RichInputMethodSubtype subtype : mSubtypesList) { + final String subtypeName = SubtypeLocaleUtils + .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype()); + final Locale locale = subtype.getLocale(); + 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 Hinglish). + continue; + } + final String spacebarText = subtype.getMiddleDisplayName(); + if (subtype.isNoLanguage()) { + assertEquals(subtypeName, SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName( + subtype.getRawSubtype()), spacebarText); + } else { + assertEquals(subtypeName, + 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 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 + protected Void job(final Resources res) { + assertEquals("en_US", "English (US)", EN_US.getFullDisplayName()); + assertEquals("en_GB", "English (UK)", EN_GB.getFullDisplayName()); + assertEquals("es_US", "Español (EE.UU.)", ES_US.getFullDisplayName()); + assertEquals("fr", "Français", FR.getFullDisplayName()); + assertEquals("fr_CA", "Français (Canada)", FR_CA.getFullDisplayName()); + 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()); + + assertEquals("en_US", "English", EN_US.getMiddleDisplayName()); + assertEquals("en_GB", "English", EN_GB.getMiddleDisplayName()); + assertEquals("es_US", "Español", ES_US.getMiddleDisplayName()); + assertEquals("fr", "Français", FR.getMiddleDisplayName()); + assertEquals("fr_CA", "Français", FR_CA.getMiddleDisplayName()); + assertEquals("fr_CH", "Français", FR_CH.getMiddleDisplayName()); + assertEquals("de", "Deutsch", DE.getMiddleDisplayName()); + assertEquals("de_CH", "Deutsch", DE_CH.getMiddleDisplayName()); + assertEquals("zz", "QWERTY", ZZ.getMiddleDisplayName()); + + // 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; + } + }; + + private final RunInLocale<Void> testsAdditionalSubtypesForSpacebar = new RunInLocale<Void>() { + @Override + protected Void job(final Resources res) { + assertEquals("fr qwertz", "Français", FR_QWERTZ.getFullDisplayName()); + assertEquals("de qwerty", "Deutsch", DE_QWERTY.getFullDisplayName()); + assertEquals("en_US azerty", "English (US)", EN_US_AZERTY.getFullDisplayName()); + assertEquals("en_UK dvorak", "English (UK)", EN_UK_DVORAK.getFullDisplayName()); + assertEquals("es_US colemak", "Español (EE.UU.)", ES_US_COLEMAK.getFullDisplayName()); + assertEquals("zz azerty", "AZERTY", ZZ_AZERTY.getFullDisplayName()); + assertEquals("zz pc", "PC", ZZ_PC.getFullDisplayName()); + + assertEquals("fr qwertz", "Français", FR_QWERTZ.getMiddleDisplayName()); + assertEquals("de qwerty", "Deutsch", DE_QWERTY.getMiddleDisplayName()); + assertEquals("en_US azerty", "English", EN_US_AZERTY.getMiddleDisplayName()); + assertEquals("en_UK dvorak", "English", EN_UK_DVORAK.getMiddleDisplayName()); + 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; + } + }; + + @Test + public void testPredefinedSubtypesForSpacebarInEnglish() { + testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); + } + + @Test + public void testAdditionalSubtypeForSpacebarInEnglish() { + testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); + } + + @Test + public void testPredefinedSubtypesForSpacebarInFrench() { + testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); + } + + @Test + public void testAdditionalSubtypeForSpacebarInFrench() { + testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); + } + + @Test + public void testRichInputMethodSubtypeForNullInputMethodSubtype() { + RichInputMethodSubtype subtype = RichInputMethodSubtype.getRichInputMethodSubtype(null); + assertNotNull(subtype); + assertEquals("zz", subtype.getRawSubtype().getLocale()); + assertEquals("keyboard", subtype.getRawSubtype().getMode()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/ShiftModeTests.java b/tests/src/org/kelar/inputmethod/latin/ShiftModeTests.java new file mode 100644 index 000000000..a036e5d7d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/ShiftModeTests.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin; + +import android.text.TextUtils; +import android.view.inputmethod.EditorInfo; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.common.Constants; + +@LargeTest +public class ShiftModeTests extends InputTestsBase { + + @Override + protected EditorInfo enrichEditorInfo(final EditorInfo ei) { + ei.inputType |= TextUtils.CAP_MODE_SENTENCES; + ei.initialCapsMode = TextUtils.CAP_MODE_SENTENCES; + return ei; + } + + private boolean isCapsModeAutoShifted() { + return mLatinIME.mKeyboardSwitcher.getKeyboardShiftMode() + == WordComposer.CAPS_MODE_AUTO_SHIFTED; + } + + public void testTypicalSentence() { + assertTrue("Initial auto caps state", isCapsModeAutoShifted()); + type("Test"); + assertFalse("Caps after letter", isCapsModeAutoShifted()); + type(" "); + assertFalse("Caps after space", isCapsModeAutoShifted()); + type("some,"); + assertFalse("Caps after comma", isCapsModeAutoShifted()); + type(" "); + assertFalse("Caps after comma space", isCapsModeAutoShifted()); + type("words."); + assertFalse("Caps directly after period", isCapsModeAutoShifted()); + type(" "); + assertTrue("Caps after period space", isCapsModeAutoShifted()); + } + + public void testBackspace() { + assertTrue("Initial auto caps state", isCapsModeAutoShifted()); + type("A"); + assertFalse("Caps state after one letter", isCapsModeAutoShifted()); + type(Constants.CODE_DELETE); + assertTrue("Auto caps state at start after delete", isCapsModeAutoShifted()); + } + + public void testRepeatingBackspace() { + final String SENTENCE_TO_TYPE = "Test sentence. Another."; + final int BACKSPACE_COUNT = + SENTENCE_TO_TYPE.length() - SENTENCE_TO_TYPE.lastIndexOf(' ') - 1; + + type(SENTENCE_TO_TYPE); + assertFalse("Caps after typing \"" + SENTENCE_TO_TYPE + "\"", isCapsModeAutoShifted()); + type(Constants.CODE_DELETE); + for (int i = 1; i < BACKSPACE_COUNT; ++i) { + repeatKey(Constants.CODE_DELETE); + } + assertFalse("Caps immediately after repeating Backspace a lot", isCapsModeAutoShifted()); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + assertTrue("Caps after a while after repeating Backspace a lot", isCapsModeAutoShifted()); + } + + public void testAutoCapsAfterDigitsPeriod() { + changeLanguage("en"); + type("On 22.11."); + assertFalse("(English) Auto caps after digits-period", isCapsModeAutoShifted()); + type(" "); + assertTrue("(English) Auto caps after digits-period-whitespace", isCapsModeAutoShifted()); + mEditText.setText(""); + changeLanguage("fr"); + type("Le 22."); + assertFalse("(French) Auto caps after digits-period", isCapsModeAutoShifted()); + type(" "); + assertTrue("(French) Auto caps after digits-period-whitespace", isCapsModeAutoShifted()); + mEditText.setText(""); + changeLanguage("de"); + type("Am 22."); + assertFalse("(German) Auto caps after digits-period", isCapsModeAutoShifted()); + type(" "); + // For German, no auto-caps in this case + assertFalse("(German) Auto caps after digits-period-whitespace", isCapsModeAutoShifted()); + } + + public void testAutoCapsAfterInvertedMarks() { + changeLanguage("es"); + assertTrue("(Spanish) Auto caps at start", isCapsModeAutoShifted()); + type("Hey. ¿"); + assertTrue("(Spanish) Auto caps after inverted what", isCapsModeAutoShifted()); + mEditText.setText(""); + type("¡"); + assertTrue("(Spanish) Auto caps after inverted bang", isCapsModeAutoShifted()); + } + + public void testOtherSentenceSeparators() { + changeLanguage("hy_AM"); + assertTrue("(Armenian) Auto caps at start", isCapsModeAutoShifted()); + type("Hey. "); + assertFalse("(Armenian) No auto-caps after latin period", isCapsModeAutoShifted()); + type("Hey\u0589"); + assertFalse("(Armenian) No auto-caps directly after armenian period", + isCapsModeAutoShifted()); + type(" "); + assertTrue("(Armenian) Auto-caps after armenian period-whitespace", + isCapsModeAutoShifted()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/SuggestedWordsTests.java b/tests/src/org/kelar/inputmethod/latin/SuggestedWordsTests.java new file mode 100644 index 000000000..1d3df9335 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/SuggestedWordsTests.java @@ -0,0 +1,186 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.SuggestedWords.SuggestedWordInfo; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SuggestedWordsTests { + + /** + * Helper method to create a placeholder {@link SuggestedWordInfo} with specifying + * {@link SuggestedWordInfo#KIND_TYPED}. + * + * @param word the word to be used to create {@link SuggestedWordInfo}. + * @return a new instance of {@link SuggestedWordInfo}. + */ + private static SuggestedWordInfo createTypedWordInfo(final String word) { + // Use 100 as the frequency because the numerical value does not matter as + // long as it's > 1 and < INT_MAX. + return new SuggestedWordInfo(word, "" /* prevWordsContext */, 100 /* score */, + SuggestedWordInfo.KIND_TYPED, + null /* sourceDict */, + SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, + 1 /* autoCommitFirstWordConfidence */); + } + + /** + * Helper method to create a placeholder {@link SuggestedWordInfo} with specifying + * {@link SuggestedWordInfo#KIND_CORRECTION}. + * + * @param word the word to be used to create {@link SuggestedWordInfo}. + * @return a new instance of {@link SuggestedWordInfo}. + */ + private static SuggestedWordInfo createCorrectionWordInfo(final String word) { + return new SuggestedWordInfo(word, "" /* prevWordsContext */, 1 /* score */, + SuggestedWordInfo.KIND_CORRECTION, + null /* sourceDict */, + SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, + SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */); + } + + private static ArrayList<SuggestedWordInfo> createCorrectionWordInfos(final String... words) { + final ArrayList<SuggestedWordInfo> infos = new ArrayList<>(); + for (final String word : words) { + infos.add(createCorrectionWordInfo(word)); + } + return infos; + } + + // Helper for testGetTransformedWordInfo + private static SuggestedWordInfo transformWordInfo(final String info, + final int trailingSingleQuotesCount) { + final SuggestedWordInfo suggestedWordInfo = createTypedWordInfo(info); + final SuggestedWordInfo returnedWordInfo = + Suggest.getTransformedSuggestedWordInfo(suggestedWordInfo, + Locale.ENGLISH, false /* isAllUpperCase */, false /* isFirstCharCapitalized */, + trailingSingleQuotesCount); + assertEquals(suggestedWordInfo.mAutoCommitFirstWordConfidence, + returnedWordInfo.mAutoCommitFirstWordConfidence); + return returnedWordInfo; + } + + @Test + public void testRemoveDupesNoDupes() { + final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "c"); + assertEquals(-1, SuggestedWordInfo.removeDups("b", infos)); + assertEquals(2, infos.size()); + } + + @Test + public void testRemoveDupesTypedWordNotDupe() { + final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "a", "c"); + assertEquals(-1, SuggestedWordInfo.removeDups("b", infos)); + assertEquals(2, infos.size()); + } + + @Test + public void testRemoveDupesTypedWordOnlyDupe() { + final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "b", "c"); + assertEquals(1, SuggestedWordInfo.removeDups("b", infos)); + assertEquals(2, infos.size()); + } + + @Test + public void testRemoveDupesTypedWordNotOnlyDupe() { + final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "b", "b", "c"); + assertEquals(1, SuggestedWordInfo.removeDups("b", infos)); + assertEquals(2, infos.size()); + } + + @Test + public void testGetTransformedSuggestedWordInfo() { + SuggestedWordInfo result = transformWordInfo("word", 0); + assertEquals(result.mWord, "word"); + result = transformWordInfo("word", 1); + assertEquals(result.mWord, "word'"); + result = transformWordInfo("word", 3); + assertEquals(result.mWord, "word'''"); + result = transformWordInfo("didn't", 0); + assertEquals(result.mWord, "didn't"); + result = transformWordInfo("didn't", 1); + assertEquals(result.mWord, "didn't"); + result = transformWordInfo("didn't", 3); + assertEquals(result.mWord, "didn't''"); + } + + @Test + public void testGetTypedWordInfoOrNull() { + final String TYPED_WORD = "typed"; + final SuggestedWordInfo TYPED_WORD_INFO = createTypedWordInfo(TYPED_WORD); + final int NUMBER_OF_ADDED_SUGGESTIONS = 5; + final ArrayList<SuggestedWordInfo> list = new ArrayList<>(); + list.add(TYPED_WORD_INFO); + for (int i = 0; i < NUMBER_OF_ADDED_SUGGESTIONS; ++i) { + list.add(createCorrectionWordInfo(Integer.toString(i))); + } + + // Make sure getTypedWordInfoOrNull() returns non-null object. + final SuggestedWords wordsWithTypedWord = new SuggestedWords( + list, null /* rawSuggestions */, + TYPED_WORD_INFO, + false /* typedWordValid */, + false /* willAutoCorrect */, + false /* isObsoleteSuggestions */, + SuggestedWords.INPUT_STYLE_NONE, + SuggestedWords.NOT_A_SEQUENCE_NUMBER); + final SuggestedWordInfo typedWord = wordsWithTypedWord.getTypedWordInfoOrNull(); + assertNotNull(typedWord); + assertEquals(TYPED_WORD, typedWord.mWord); + + // Make sure getTypedWordInfoOrNull() returns null when no typed word. + list.remove(0); + final SuggestedWords wordsWithoutTypedWord = new SuggestedWords( + list, null /* rawSuggestions */, + null /* typedWord */, + false /* typedWordValid */, + false /* willAutoCorrect */, + false /* isObsoleteSuggestions */, + SuggestedWords.INPUT_STYLE_NONE, + SuggestedWords.NOT_A_SEQUENCE_NUMBER); + assertNull(wordsWithoutTypedWord.getTypedWordInfoOrNull()); + + // Make sure getTypedWordInfoOrNull() returns null. + assertNull(SuggestedWords.getEmptyInstance().getTypedWordInfoOrNull()); + + final SuggestedWords emptySuggestedWords = new SuggestedWords( + new ArrayList<SuggestedWordInfo>(), null /* rawSuggestions */, + null /* typedWord */, + false /* typedWordValid */, + false /* willAutoCorrect */, + false /* isObsoleteSuggestions */, + SuggestedWords.INPUT_STYLE_NONE, + SuggestedWords.NOT_A_SEQUENCE_NUMBER); + assertNull(emptySuggestedWords.getTypedWordInfoOrNull()); + + assertNull(SuggestedWords.getEmptyInstance().getTypedWordInfoOrNull()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/WordComposerTests.java b/tests/src/org/kelar/inputmethod/latin/WordComposerTests.java new file mode 100644 index 000000000..f13458526 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/WordComposerTests.java @@ -0,0 +1,133 @@ +/* + * 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 org.kelar.inputmethod.latin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.common.CoordinateUtils; +import org.kelar.inputmethod.latin.common.StringUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Unit tests for WordComposer. + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class WordComposerTests { + + @Test + public void testMoveCursor() { + final WordComposer wc = new WordComposer(); + // BMP is the Basic Multilingual Plane, as defined by Unicode. This includes + // most characters for most scripts, including all Roman alphabet languages, + // CJK, Arabic, Hebrew. Notable exceptions include some emoji and some + // very rare Chinese ideograms. BMP characters can be encoded on 2 bytes + // in UTF-16, whereas those outside the BMP need 4 bytes. + // http://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane + final String STR_WITHIN_BMP = "abcdef"; + final int[] CODEPOINTS_WITHIN_BMP = StringUtils.toCodePointArray(STR_WITHIN_BMP); + final int[] COORDINATES_WITHIN_BMP = + CoordinateUtils.newCoordinateArray(CODEPOINTS_WITHIN_BMP.length, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); + wc.setComposingWord(CODEPOINTS_WITHIN_BMP, COORDINATES_WITHIN_BMP); + assertEquals(wc.size(), STR_WITHIN_BMP.codePointCount(0, STR_WITHIN_BMP.length())); + assertFalse(wc.isCursorFrontOrMiddleOfComposingWord()); + wc.setCursorPositionWithinWord(2); + assertTrue(wc.isCursorFrontOrMiddleOfComposingWord()); + // Move the cursor to after the 'd' + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(2)); + assertTrue(wc.isCursorFrontOrMiddleOfComposingWord()); + // Move the cursor to after the 'e' + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(1)); + assertTrue(wc.isCursorFrontOrMiddleOfComposingWord()); + assertEquals(wc.size(), 6); + // Move the cursor to after the 'f' + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(1)); + assertFalse(wc.isCursorFrontOrMiddleOfComposingWord()); + // Move the cursor past the end of the word + assertFalse(wc.moveCursorByAndReturnIfInsideComposingWord(1)); + assertFalse(wc.moveCursorByAndReturnIfInsideComposingWord(15)); + // Do what LatinIME does when the cursor is moved outside of the word, + // and check the behavior is correct. + wc.reset(); + + // \uD861\uDED7 is 𨛗, a character outside the BMP + final String STR_WITH_SUPPLEMENTARY_CHAR = "abcde\uD861\uDED7fgh"; + final int[] CODEPOINTS_WITH_SUPPLEMENTARY_CHAR = + StringUtils.toCodePointArray(STR_WITH_SUPPLEMENTARY_CHAR); + final int[] COORDINATES_WITH_SUPPLEMENTARY_CHAR = + CoordinateUtils.newCoordinateArray(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR.length, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + assertEquals(wc.size(), CODEPOINTS_WITH_SUPPLEMENTARY_CHAR.length); + assertFalse(wc.isCursorFrontOrMiddleOfComposingWord()); + wc.setCursorPositionWithinWord(3); + assertTrue(wc.isCursorFrontOrMiddleOfComposingWord()); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(6)); + assertTrue(wc.isCursorFrontOrMiddleOfComposingWord()); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(1)); + assertFalse(wc.isCursorFrontOrMiddleOfComposingWord()); + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + wc.setCursorPositionWithinWord(3); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(7)); + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + wc.setCursorPositionWithinWord(3); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(7)); + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + wc.setCursorPositionWithinWord(3); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(-3)); + assertFalse(wc.moveCursorByAndReturnIfInsideComposingWord(-1)); + + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + wc.setCursorPositionWithinWord(3); + assertFalse(wc.moveCursorByAndReturnIfInsideComposingWord(-9)); + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(-10)); + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + assertFalse(wc.moveCursorByAndReturnIfInsideComposingWord(-11)); + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(0)); + + wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, + COORDINATES_WITH_SUPPLEMENTARY_CHAR); + wc.setCursorPositionWithinWord(2); + assertTrue(wc.moveCursorByAndReturnIfInsideComposingWord(0)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/accounts/AccountsChangedReceiverTests.java b/tests/src/org/kelar/inputmethod/latin/accounts/AccountsChangedReceiverTests.java new file mode 100644 index 000000000..96e522182 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/accounts/AccountsChangedReceiverTests.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.accounts; + +import static org.junit.Assert.assertEquals; + +import android.accounts.AccountManager; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.settings.LocalSettingsConstants; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests for {@link AccountsChangedReceiver}. + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class AccountsChangedReceiverTests { + private static final String ACCOUNT_1 = "account1@example.com"; + private static final String ACCOUNT_2 = "account2@example.com"; + + private SharedPreferences mPrefs; + private String mLastKnownAccount = null; + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + @Before + public void setUp() throws Exception { + mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + // Keep track of the current account so that we restore it when the test finishes. + mLastKnownAccount = mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null); + } + + @After + public void tearDown() throws Exception { + // Restore the account that was present before running the test. + updateAccountName(mLastKnownAccount); + } + + @Test + public void testUnknownIntent() { + updateAccountName(ACCOUNT_1); + AccountsChangedReceiver reciever = new AccountsChangedReceiver(); + reciever.onReceive(getContext(), new Intent("some-random-action")); + // Account should *not* be removed from preferences. + assertAccountName(ACCOUNT_1); + } + + @Test + public void testAccountRemoved() { + updateAccountName(ACCOUNT_1); + AccountsChangedReceiver reciever = new AccountsChangedReceiver() { + @Override + protected String[] getAccountsForLogin(Context context) { + return new String[] {ACCOUNT_2}; + } + }; + reciever.onReceive(getContext(), new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)); + // Account should be removed from preferences. + assertAccountName(null); + } + + @Test + public void testAccountRemoved_noAccounts() { + updateAccountName(ACCOUNT_2); + AccountsChangedReceiver reciever = new AccountsChangedReceiver() { + @Override + protected String[] getAccountsForLogin(Context context) { + return new String[0]; + } + }; + reciever.onReceive(getContext(), new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)); + // Account should be removed from preferences. + assertAccountName(null); + } + + @Test + public void testAccountNotRemoved() { + updateAccountName(ACCOUNT_2); + AccountsChangedReceiver reciever = new AccountsChangedReceiver() { + @Override + protected String[] getAccountsForLogin(Context context) { + return new String[] {ACCOUNT_1, ACCOUNT_2}; + } + }; + reciever.onReceive(getContext(), new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)); + // Account should *not* be removed from preferences. + assertAccountName(ACCOUNT_2); + } + + private void updateAccountName(String accountName) { + if (accountName == null) { + mPrefs.edit().remove(LocalSettingsConstants.PREF_ACCOUNT_NAME).apply(); + } else { + mPrefs.edit().putString(LocalSettingsConstants.PREF_ACCOUNT_NAME, accountName).apply(); + } + } + + private void assertAccountName(String expectedAccountName) { + assertEquals(expectedAccountName, + mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/common/InputPointersTests.java b/tests/src/org/kelar/inputmethod/latin/common/InputPointersTests.java new file mode 100644 index 000000000..e0b98dd13 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/common/InputPointersTests.java @@ -0,0 +1,344 @@ +/* + * 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 org.kelar.inputmethod.latin.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class InputPointersTests { + private static final int DEFAULT_CAPACITY = 48; + + @Test + public void testNewInstance() { + final InputPointers src = new InputPointers(DEFAULT_CAPACITY); + assertEquals("new instance size", 0, src.getPointerSize()); + assertNotNull("new instance xCoordinates", src.getXCoordinates()); + assertNotNull("new instance yCoordinates", src.getYCoordinates()); + assertNotNull("new instance pointerIds", src.getPointerIds()); + assertNotNull("new instance times", src.getTimes()); + } + + @Test + public void testReset() { + final InputPointers src = new InputPointers(DEFAULT_CAPACITY); + final int[] xCoordinates = src.getXCoordinates(); + final int[] yCoordinates = src.getXCoordinates(); + final int[] pointerIds = src.getXCoordinates(); + final int[] times = src.getXCoordinates(); + + src.reset(); + assertEquals("size after reset", 0, src.getPointerSize()); + assertNotSame("xCoordinates after reset", xCoordinates, src.getXCoordinates()); + assertNotSame("yCoordinates after reset", yCoordinates, src.getYCoordinates()); + assertNotSame("pointerIds after reset", pointerIds, src.getPointerIds()); + assertNotSame("times after reset", times, src.getTimes()); + } + + @Test + public void testAdd() { + final InputPointers src = new InputPointers(DEFAULT_CAPACITY); + final int limit = src.getXCoordinates().length * 2 + 10; + for (int i = 0; i < limit; i++) { + final int x = i; + final int y = i * 2; + final int pointerId = i * 3; + final int time = i * 4; + src.addPointer(x, y, pointerId, time); + assertEquals("size after add " + i, i + 1, src.getPointerSize()); + } + for (int i = 0; i < limit; i++) { + final int x = i; + final int y = i * 2; + final int pointerId = i * 3; + final int time = i * 4; + assertEquals("xCoordinates at " + i, x, src.getXCoordinates()[i]); + assertEquals("yCoordinates at " + i, y, src.getYCoordinates()[i]); + assertEquals("pointerIds at " + i, pointerId, src.getPointerIds()[i]); + assertEquals("times at " + i, time, src.getTimes()[i]); + } + } + + @Test + public void testAddAt() { + final InputPointers src = new InputPointers(DEFAULT_CAPACITY); + final int limit = 1000, step = 100; + for (int i = 0; i < limit; i += step) { + final int x = i; + final int y = i * 2; + final int pointerId = i * 3; + final int time = i * 4; + src.addPointerAt(i, x, y, pointerId, time); + assertEquals("size after add at " + i, i + 1, src.getPointerSize()); + } + for (int i = 0; i < limit; i += step) { + final int x = i; + final int y = i * 2; + final int pointerId = i * 3; + final int time = i * 4; + assertEquals("xCoordinates at " + i, x, src.getXCoordinates()[i]); + assertEquals("yCoordinates at " + i, y, src.getYCoordinates()[i]); + assertEquals("pointerIds at " + i, pointerId, src.getPointerIds()[i]); + assertEquals("times at " + i, time, src.getTimes()[i]); + } + } + + @Test + public void testSet() { + final InputPointers src = new InputPointers(DEFAULT_CAPACITY); + final int limit = src.getXCoordinates().length * 2 + 10; + for (int i = 0; i < limit; i++) { + final int x = i; + final int y = i * 2; + final int pointerId = i * 3; + final int time = i * 4; + src.addPointer(x, y, pointerId, time); + } + final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); + dst.set(src); + assertEquals("size after set", dst.getPointerSize(), src.getPointerSize()); + assertSame("xCoordinates after set", dst.getXCoordinates(), src.getXCoordinates()); + assertSame("yCoordinates after set", dst.getYCoordinates(), src.getYCoordinates()); + assertSame("pointerIds after set", dst.getPointerIds(), src.getPointerIds()); + assertSame("times after set", dst.getTimes(), src.getTimes()); + } + + @Test + public void testCopy() { + final InputPointers src = new InputPointers(DEFAULT_CAPACITY); + final int limit = 100; + for (int i = 0; i < limit; i++) { + final int x = i; + final int y = i * 2; + final int pointerId = i * 3; + final int time = i * 4; + src.addPointer(x, y, pointerId, time); + } + final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); + dst.copy(src); + assertEquals("size after copy", dst.getPointerSize(), src.getPointerSize()); + assertNotSame("xCoordinates after copy", dst.getXCoordinates(), src.getXCoordinates()); + assertNotSame("yCoordinates after copy", dst.getYCoordinates(), src.getYCoordinates()); + assertNotSame("pointerIds after copy", dst.getPointerIds(), src.getPointerIds()); + assertNotSame("times after copy", dst.getTimes(), src.getTimes()); + final int size = dst.getPointerSize(); + assertIntArrayEquals("xCoordinates values after copy", + dst.getXCoordinates(), 0, src.getXCoordinates(), 0, size); + assertIntArrayEquals("yCoordinates values after copy", + dst.getYCoordinates(), 0, src.getYCoordinates(), 0, size); + assertIntArrayEquals("pointerIds values after copy", + dst.getPointerIds(), 0, src.getPointerIds(), 0, size); + assertIntArrayEquals("times values after copy", + dst.getTimes(), 0, src.getTimes(), 0, size); + } + + @Test + public void testAppend() { + final int dstLength = 50; + final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); + for (int i = 0; i < dstLength; i++) { + final int x = i * 4; + final int y = i * 3; + final int pointerId = i * 2; + final int time = i; + dst.addPointer(x, y, pointerId, time); + } + final InputPointers dstCopy = new InputPointers(DEFAULT_CAPACITY); + dstCopy.copy(dst); + + final ResizableIntArray srcXCoords = new ResizableIntArray(DEFAULT_CAPACITY); + final ResizableIntArray srcYCoords = new ResizableIntArray(DEFAULT_CAPACITY); + final ResizableIntArray srcPointerIds = new ResizableIntArray(DEFAULT_CAPACITY); + final ResizableIntArray srcTimes = new ResizableIntArray(DEFAULT_CAPACITY); + final int srcLength = 100; + final int srcPointerId = 10; + for (int i = 0; i < srcLength; i++) { + final int x = i; + final int y = i * 2; + // The time value must be larger than <code>dst</code>. + final int time = i * 4 + dstLength; + srcXCoords.add(x); + srcYCoords.add(y); + srcPointerIds.add(srcPointerId); + srcTimes.add(time); + } + + final int startPos = 0; + dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords, + startPos, 0 /* length */); + assertEquals("size after append zero", dstLength, dst.getPointerSize()); + assertIntArrayEquals("xCoordinates after append zero", + dstCopy.getXCoordinates(), startPos, dst.getXCoordinates(), startPos, dstLength); + assertIntArrayEquals("yCoordinates after append zero", + dstCopy.getYCoordinates(), startPos, dst.getYCoordinates(), startPos, dstLength); + assertIntArrayEquals("pointerIds after append zero", + dstCopy.getPointerIds(), startPos, dst.getPointerIds(), startPos, dstLength); + assertIntArrayEquals("times after append zero", + dstCopy.getTimes(), startPos, dst.getTimes(), startPos, dstLength); + + dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords, + startPos, srcLength); + assertEquals("size after append", dstLength + srcLength, dst.getPointerSize()); + assertTrue("primitive length after append", + dst.getPointerIds().length >= dstLength + srcLength); + assertIntArrayEquals("original xCoordinates values after append", + dstCopy.getXCoordinates(), startPos, dst.getXCoordinates(), startPos, dstLength); + assertIntArrayEquals("original yCoordinates values after append", + dstCopy.getYCoordinates(), startPos, dst.getYCoordinates(), startPos, dstLength); + assertIntArrayEquals("original pointerIds values after append", + dstCopy.getPointerIds(), startPos, dst.getPointerIds(), startPos, dstLength); + assertIntArrayEquals("original times values after append", + dstCopy.getTimes(), startPos, dst.getTimes(), startPos, dstLength); + assertIntArrayEquals("appended xCoordinates values after append", + srcXCoords.getPrimitiveArray(), startPos, dst.getXCoordinates(), + dstLength, srcLength); + assertIntArrayEquals("appended yCoordinates values after append", + srcYCoords.getPrimitiveArray(), startPos, dst.getYCoordinates(), + dstLength, srcLength); + assertIntArrayEquals("appended pointerIds values after append", + srcPointerIds.getPrimitiveArray(), startPos, dst.getPointerIds(), + dstLength, srcLength); + assertIntArrayEquals("appended times values after append", + srcTimes.getPrimitiveArray(), startPos, dst.getTimes(), dstLength, srcLength); + } + + @Test + public void testAppendResizableIntArray() { + final int dstLength = 50; + final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); + for (int i = 0; i < dstLength; i++) { + final int x = i * 4; + final int y = i * 3; + final int pointerId = i * 2; + final int time = i; + dst.addPointer(x, y, pointerId, time); + } + final InputPointers dstCopy = new InputPointers(DEFAULT_CAPACITY); + dstCopy.copy(dst); + + final int srcLength = 100; + final int srcPointerId = 1; + final int[] srcPointerIds = new int[srcLength]; + Arrays.fill(srcPointerIds, srcPointerId); + final ResizableIntArray srcTimes = new ResizableIntArray(DEFAULT_CAPACITY); + final ResizableIntArray srcXCoords = new ResizableIntArray(DEFAULT_CAPACITY); + final ResizableIntArray srcYCoords= new ResizableIntArray(DEFAULT_CAPACITY); + for (int i = 0; i < srcLength; i++) { + // The time value must be larger than <code>dst</code>. + final int time = i * 2 + dstLength; + final int x = i * 3; + final int y = i * 4; + srcTimes.add(time); + srcXCoords.add(x); + srcYCoords.add(y); + } + + dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords, 0, 0); + assertEquals("size after append zero", dstLength, dst.getPointerSize()); + assertIntArrayEquals("xCoordinates after append zero", + dstCopy.getXCoordinates(), 0, dst.getXCoordinates(), 0, dstLength); + assertIntArrayEquals("yCoordinates after append zero", + dstCopy.getYCoordinates(), 0, dst.getYCoordinates(), 0, dstLength); + assertIntArrayEquals("pointerIds after append zero", + dstCopy.getPointerIds(), 0, dst.getPointerIds(), 0, dstLength); + assertIntArrayEquals("times after append zero", + dstCopy.getTimes(), 0, dst.getTimes(), 0, dstLength); + + dst.append(srcPointerId, srcTimes, srcXCoords, srcYCoords, 0, srcLength); + assertEquals("size after append", dstLength + srcLength, dst.getPointerSize()); + assertTrue("primitive length after append", + dst.getPointerIds().length >= dstLength + srcLength); + assertIntArrayEquals("original xCoordinates values after append", + dstCopy.getXCoordinates(), 0, dst.getXCoordinates(), 0, dstLength); + assertIntArrayEquals("original yCoordinates values after append", + dstCopy.getYCoordinates(), 0, dst.getYCoordinates(), 0, dstLength); + assertIntArrayEquals("original pointerIds values after append", + dstCopy.getPointerIds(), 0, dst.getPointerIds(), 0, dstLength); + assertIntArrayEquals("original times values after append", + dstCopy.getTimes(), 0, dst.getTimes(), 0, dstLength); + assertIntArrayEquals("appended xCoordinates values after append", + srcXCoords.getPrimitiveArray(), 0, dst.getXCoordinates(), dstLength, srcLength); + assertIntArrayEquals("appended yCoordinates values after append", + srcYCoords.getPrimitiveArray(), 0, dst.getYCoordinates(), dstLength, srcLength); + assertIntArrayEquals("appended pointerIds values after append", + srcPointerIds, 0, dst.getPointerIds(), dstLength, srcLength); + assertIntArrayEquals("appended times values after append", + srcTimes.getPrimitiveArray(), 0, dst.getTimes(), dstLength, srcLength); + } + + // TODO: Consolidate this method with + // {@link ResizableIntArrayTests#assertIntArrayEquals(String,int[],int,int[],int,int)}. + 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]); + } + } + + @Test + public void testShift() { + final InputPointers src = new InputPointers(DEFAULT_CAPACITY); + final int limit = 100; + final int shiftAmount = 20; + for (int i = 0; i < limit; i++) { + final int x = i; + final int y = i * 2; + final int pointerId = i * 3; + final int time = i * 4; + src.addPointer(x, y, pointerId, time); + } + src.shift(shiftAmount); + assertEquals("length after shift", src.getPointerSize(), limit - shiftAmount); + for (int i = 0; i < limit - shiftAmount; ++i) { + final int oldIndex = i + shiftAmount; + final int x = oldIndex; + final int y = oldIndex * 2; + final int pointerId = oldIndex * 3; + final int time = oldIndex * 4; + assertEquals("xCoordinates at " + i, x, src.getXCoordinates()[i]); + assertEquals("yCoordinates at " + i, y, src.getYCoordinates()[i]); + assertEquals("pointerIds at " + i, pointerId, src.getPointerIds()[i]); + assertEquals("times at " + i, time, src.getTimes()[i]); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/common/ResizableIntArrayTests.java b/tests/src/org/kelar/inputmethod/latin/common/ResizableIntArrayTests.java new file mode 100644 index 000000000..d2a7a651f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/common/ResizableIntArrayTests.java @@ -0,0 +1,399 @@ +/* + * 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 org.kelar.inputmethod.latin.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class ResizableIntArrayTests { + private static final int DEFAULT_CAPACITY = 48; + + @Test + 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); + } + + @Test + 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)); + } + } + + @Test + 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)); + } + } + + @Test + 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 + } + } + + @Test + 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()); + } + } + } + + @Test + 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)); + } + } + + @Test + 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()); + } + + @Test + 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()); + } + + @Test + 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); + } + + @Test + 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]); + } + } + + @Test + 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/org/kelar/inputmethod/latin/common/StringUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/common/StringUtilsTests.java new file mode 100644 index 000000000..016819ce8 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/common/StringUtilsTests.java @@ -0,0 +1,501 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class StringUtilsTests { + private static final Locale US = Locale.US; + private static final Locale GERMAN = Locale.GERMAN; + private static final Locale TURKEY = new Locale("tr", "TR"); + private static final Locale GREECE = new Locale("el", "GR"); + + private static void assert_toTitleCaseOfKeyLabel(final Locale locale, + final String lowerCase, final String expected) { + assertEquals(lowerCase + " in " + locale, expected, + StringUtils.toTitleCaseOfKeyLabel(lowerCase, locale)); + } + + @Test + public void test_toTitleCaseOfKeyLabel() { + assert_toTitleCaseOfKeyLabel(US, null, null); + assert_toTitleCaseOfKeyLabel(US, "", ""); + assert_toTitleCaseOfKeyLabel(US, "aeiou", "AEIOU"); + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+00C0: "À" LATIN CAPITAL LETTER A WITH GRAVE + // U+00C8: "È" LATIN CAPITAL LETTER E WITH GRAVE + // U+00CE: "Î" LATIN CAPITAL LETTER I WITH CIRCUMFLEX + // U+00D6: "Ö" LATIN CAPITAL LETTER O WITH DIAERESIS + // U+016A: "Ū" LATIN CAPITAL LETTER U WITH MACRON + // U+00D1: "Ñ" LATIN CAPITAL LETTER N WITH TILDE + // U+00C7: "Ç" LATIN CAPITAL LETTER C WITH CEDILLA + assert_toTitleCaseOfKeyLabel(US, + "\u00E0\u00E8\u00EE\u00F6\u016B\u00F1\u00E7", + "\u00C0\u00C8\u00CE\u00D6\u016A\u00D1\u00C7"); + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+015A: "Ś" LATIN CAPITAL LETTER S WITH ACUTE + // U+0160: "Š" LATIN CAPITAL LETTER S WITH CARONZ + assert_toTitleCaseOfKeyLabel(GERMAN, + "\u00DF\u015B\u0161", + "SS\u015A\u0160"); + // U+0259: "ə" LATIN SMALL LETTER SCHWA + // U+0069: "i" LATIN SMALL LETTER I + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+018F: "Ə" LATIN SMALL LETTER SCHWA + // U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE + // U+0049: "I" LATIN SMALL LETTER I + assert_toTitleCaseOfKeyLabel(TURKEY, + "\u0259\u0069\u0131", + "\u018F\u0130\u0049"); + // U+03C3: "σ" GREEK SMALL LETTER SIGMA + // U+03C2: "ς" GREEK SMALL LETTER FINAL SIGMA + // U+03A3: "Σ" GREEK CAPITAL LETTER SIGMA + assert_toTitleCaseOfKeyLabel(GREECE, + "\u03C3\u03C2", + "\u03A3\u03A3"); + // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS + // U+03AD: "έ" GREEK SMALL LETTER EPSILON WITH TONOS + // U+03AE: "ή" GREEK SMALL LETTER ETA WITH TONOS + // U+03AF: "ί" GREEK SMALL LETTER IOTA WITH TONOS + // U+03CC: "ό" GREEK SMALL LETTER OMICRON WITH TONOS + // U+03CD: "ύ" GREEK SMALL LETTER UPSILON WITH TONOS + // U+03CE: "ώ" GREEK SMALL LETTER OMEGA WITH TONOS + // U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS + // U+0388: "Έ" GREEK CAPITAL LETTER EPSILON WITH TONOS + // U+0389: "Ή" GREEK CAPITAL LETTER ETA WITH TONOS + // U+038A: "Ί" GREEK CAPITAL LETTER IOTA WITH TONOS + // U+038C: "Ό" GREEK CAPITAL LETTER OMICRON WITH TONOS + // U+038E: "Ύ" GREEK CAPITAL LETTER UPSILON WITH TONOS + // U+038F: "Ώ" GREEK CAPITAL LETTER OMEGA WITH TONOS + assert_toTitleCaseOfKeyLabel(GREECE, + "\u03AC\u03AD\u03AE\u03AF\u03CC\u03CD\u03CE", + "\u0386\u0388\u0389\u038A\u038C\u038E\u038F"); + // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA + // U+03CB: "ϋ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA + // U+0390: "ΐ" GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS + // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS + // U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA + // U+03AB: "Ϋ" GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA + // U+0399: "Ι" GREEK CAPITAL LETTER IOTA + // U+03A5: "Υ" GREEK CAPITAL LETTER UPSILON + // U+0308: COMBINING DIAERESIS + // U+0301: COMBINING GRAVE ACCENT + assert_toTitleCaseOfKeyLabel(GREECE, + "\u03CA\u03CB\u0390\u03B0", + "\u03AA\u03AB\u0399\u0308\u0301\u03A5\u0308\u0301"); + } + + private static void assert_toTitleCaseOfKeyCode(final Locale locale, final int lowerCase, + final int expected) { + assertEquals(lowerCase + " in " + locale, expected, + StringUtils.toTitleCaseOfKeyCode(lowerCase, locale)); + } + + @Test + public void test_toTitleCaseOfKeyCode() { + assert_toTitleCaseOfKeyCode(US, Constants.CODE_ENTER, Constants.CODE_ENTER); + assert_toTitleCaseOfKeyCode(US, Constants.CODE_SPACE, Constants.CODE_SPACE); + assert_toTitleCaseOfKeyCode(US, Constants.CODE_COMMA, Constants.CODE_COMMA); + // U+0069: "i" LATIN SMALL LETTER I + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE + // U+0049: "I" LATIN SMALL LETTER I + assert_toTitleCaseOfKeyCode(US, 0x0069, 0x0049); // i -> I + assert_toTitleCaseOfKeyCode(US, 0x0131, 0x0049); // ı -> I + assert_toTitleCaseOfKeyCode(TURKEY, 0x0069, 0x0130); // i -> İ + assert_toTitleCaseOfKeyCode(TURKEY, 0x0131, 0x0049); // ı -> I + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // The title case of "ß" is "SS". + assert_toTitleCaseOfKeyCode(US, 0x00DF, Constants.CODE_UNSPECIFIED); + // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS + // U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS + assert_toTitleCaseOfKeyCode(GREECE, 0x03AC, 0x0386); + // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA + // U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA + assert_toTitleCaseOfKeyCode(GREECE, 0x03CA, 0x03AA); + // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS + // The title case of "ΰ" is "\u03A5\u0308\u0301". + assert_toTitleCaseOfKeyCode(GREECE, 0x03B0, Constants.CODE_UNSPECIFIED); + } + + private static void assert_capitalizeFirstCodePoint(final Locale locale, final String text, + final String expected) { + assertEquals(text + " in " + locale, expected, + StringUtils.capitalizeFirstCodePoint(text, locale)); + } + + @Test + public void test_capitalizeFirstCodePoint() { + assert_capitalizeFirstCodePoint(US, "", ""); + assert_capitalizeFirstCodePoint(US, "a", "A"); + assert_capitalizeFirstCodePoint(US, "à", "À"); + assert_capitalizeFirstCodePoint(US, "ß", "SS"); + assert_capitalizeFirstCodePoint(US, "text", "Text"); + assert_capitalizeFirstCodePoint(US, "iGoogle", "IGoogle"); + assert_capitalizeFirstCodePoint(TURKEY, "iyi", "İyi"); + assert_capitalizeFirstCodePoint(TURKEY, "ısırdı", "Isırdı"); + assert_capitalizeFirstCodePoint(GREECE, "ά", "Ά"); + assert_capitalizeFirstCodePoint(GREECE, "άνεση", "Άνεση"); + } + + private static void assert_capitalizeFirstAndDowncaseRest(final Locale locale, + final String text, final String expected) { + assertEquals(text + " in " + locale, expected, + StringUtils.capitalizeFirstAndDowncaseRest(text, locale)); + } + + @Test + public void test_capitalizeFirstAndDowncaseRest() { + assert_capitalizeFirstAndDowncaseRest(US, "", ""); + assert_capitalizeFirstAndDowncaseRest(US, "a", "A"); + assert_capitalizeFirstAndDowncaseRest(US, "à", "À"); + assert_capitalizeFirstAndDowncaseRest(US, "ß", "SS"); + assert_capitalizeFirstAndDowncaseRest(US, "text", "Text"); + assert_capitalizeFirstAndDowncaseRest(US, "iGoogle", "Igoogle"); + assert_capitalizeFirstAndDowncaseRest(US, "invite", "Invite"); + assert_capitalizeFirstAndDowncaseRest(US, "INVITE", "Invite"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "iyi", "İyi"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "İYİ", "İyi"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "ısırdı", "Isırdı"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "ISIRDI", "Isırdı"); + assert_capitalizeFirstAndDowncaseRest(GREECE, "ά", "Ά"); + assert_capitalizeFirstAndDowncaseRest(GREECE, "άνεση", "Άνεση"); + assert_capitalizeFirstAndDowncaseRest(GREECE, "ΆΝΕΣΗ", "Άνεση"); + } + + @Test + public void testContainsInArray() { + assertFalse("empty array", StringUtils.containsInArray("key", new String[0])); + assertFalse("not in 1 element", StringUtils.containsInArray("key", new String[] { + "key1" + })); + assertFalse("not in 2 elements", StringUtils.containsInArray("key", new String[] { + "key1", "key2" + })); + + assertTrue("in 1 element", StringUtils.containsInArray("key", new String[] { + "key" + })); + assertTrue("in 2 elements", StringUtils.containsInArray("key", new String[] { + "key1", "key" + })); + } + + @Test + public void testContainsInCommaSplittableText() { + assertFalse("null", StringUtils.containsInCommaSplittableText("key", null)); + assertFalse("empty", StringUtils.containsInCommaSplittableText("key", "")); + assertFalse("not in 1 element", + StringUtils.containsInCommaSplittableText("key", "key1")); + assertFalse("not in 2 elements", + StringUtils.containsInCommaSplittableText("key", "key1,key2")); + + assertTrue("in 1 element", StringUtils.containsInCommaSplittableText("key", "key")); + assertTrue("in 2 elements", StringUtils.containsInCommaSplittableText("key", "key1,key")); + } + + @Test + public void testRemoveFromCommaSplittableTextIfExists() { + assertEquals("null", "", StringUtils.removeFromCommaSplittableTextIfExists("key", null)); + assertEquals("empty", "", StringUtils.removeFromCommaSplittableTextIfExists("key", "")); + + assertEquals("not in 1 element", "key1", + StringUtils.removeFromCommaSplittableTextIfExists("key", "key1")); + assertEquals("not in 2 elements", "key1,key2", + StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key2")); + + assertEquals("in 1 element", "", + StringUtils.removeFromCommaSplittableTextIfExists("key", "key")); + assertEquals("in 2 elements at position 1", "key2", + StringUtils.removeFromCommaSplittableTextIfExists("key", "key,key2")); + assertEquals("in 2 elements at position 2", "key1", + StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key")); + assertEquals("in 3 elements at position 2", "key1,key3", + StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key,key3")); + + assertEquals("in 3 elements at position 1,2,3", "", + StringUtils.removeFromCommaSplittableTextIfExists("key", "key,key,key")); + assertEquals("in 5 elements at position 2,4", "key1,key3,key5", + StringUtils.removeFromCommaSplittableTextIfExists( + "key", "key1,key,key3,key,key5")); + } + + @Test + public void testCapitalizeFirstCodePoint() { + assertEquals("SSaa", + StringUtils.capitalizeFirstCodePoint("ßaa", Locale.GERMAN)); + assertEquals("Aßa", + StringUtils.capitalizeFirstCodePoint("aßa", Locale.GERMAN)); + assertEquals("Iab", + StringUtils.capitalizeFirstCodePoint("iab", Locale.ENGLISH)); + assertEquals("CAmElCaSe", + StringUtils.capitalizeFirstCodePoint("cAmElCaSe", Locale.ENGLISH)); + assertEquals("İab", + StringUtils.capitalizeFirstCodePoint("iab", new Locale("tr"))); + assertEquals("AİB", + StringUtils.capitalizeFirstCodePoint("AİB", new Locale("tr"))); + assertEquals("A", + StringUtils.capitalizeFirstCodePoint("a", Locale.ENGLISH)); + assertEquals("A", + StringUtils.capitalizeFirstCodePoint("A", Locale.ENGLISH)); + } + + @Test + public void testCapitalizeFirstAndDowncaseRest() { + assertEquals("SSaa", + StringUtils.capitalizeFirstAndDowncaseRest("ßaa", Locale.GERMAN)); + assertEquals("Aßa", + StringUtils.capitalizeFirstAndDowncaseRest("aßa", Locale.GERMAN)); + assertEquals("Iab", + StringUtils.capitalizeFirstAndDowncaseRest("iab", Locale.ENGLISH)); + assertEquals("Camelcase", + StringUtils.capitalizeFirstAndDowncaseRest("cAmElCaSe", Locale.ENGLISH)); + assertEquals("İab", + StringUtils.capitalizeFirstAndDowncaseRest("iab", new Locale("tr"))); + assertEquals("Aib", + StringUtils.capitalizeFirstAndDowncaseRest("AİB", new Locale("tr"))); + assertEquals("A", + StringUtils.capitalizeFirstAndDowncaseRest("a", Locale.ENGLISH)); + assertEquals("A", + StringUtils.capitalizeFirstAndDowncaseRest("A", Locale.ENGLISH)); + } + + @Test + public void testGetCapitalizationType() { + assertEquals(StringUtils.CAPITALIZE_NONE, + StringUtils.getCapitalizationType("capitalize")); + assertEquals(StringUtils.CAPITALIZE_NONE, + StringUtils.getCapitalizationType("cApITalize")); + assertEquals(StringUtils.CAPITALIZE_NONE, + StringUtils.getCapitalizationType("capitalizE")); + assertEquals(StringUtils.CAPITALIZE_NONE, + StringUtils.getCapitalizationType("__c a piu$@tali56ze")); + assertEquals(StringUtils.CAPITALIZE_FIRST, + StringUtils.getCapitalizationType("A__c a piu$@tali56ze")); + assertEquals(StringUtils.CAPITALIZE_FIRST, + StringUtils.getCapitalizationType("Capitalize")); + assertEquals(StringUtils.CAPITALIZE_FIRST, + StringUtils.getCapitalizationType(" Capitalize")); + assertEquals(StringUtils.CAPITALIZE_ALL, + StringUtils.getCapitalizationType("CAPITALIZE")); + assertEquals(StringUtils.CAPITALIZE_ALL, + StringUtils.getCapitalizationType(" PI26LIE")); + assertEquals(StringUtils.CAPITALIZE_NONE, + StringUtils.getCapitalizationType("")); + } + + @Test + public void testIsIdenticalAfterUpcaseIsIdenticalAfterDowncase() { + assertFalse(StringUtils.isIdenticalAfterUpcase("capitalize")); + assertTrue(StringUtils.isIdenticalAfterDowncase("capitalize")); + assertFalse(StringUtils.isIdenticalAfterUpcase("cApITalize")); + assertFalse(StringUtils.isIdenticalAfterDowncase("cApITalize")); + assertFalse(StringUtils.isIdenticalAfterUpcase("capitalizE")); + assertFalse(StringUtils.isIdenticalAfterDowncase("capitalizE")); + assertFalse(StringUtils.isIdenticalAfterUpcase("__c a piu$@tali56ze")); + assertTrue(StringUtils.isIdenticalAfterDowncase("__c a piu$@tali56ze")); + assertFalse(StringUtils.isIdenticalAfterUpcase("A__c a piu$@tali56ze")); + assertFalse(StringUtils.isIdenticalAfterDowncase("A__c a piu$@tali56ze")); + assertFalse(StringUtils.isIdenticalAfterUpcase("Capitalize")); + assertFalse(StringUtils.isIdenticalAfterDowncase("Capitalize")); + assertFalse(StringUtils.isIdenticalAfterUpcase(" Capitalize")); + assertFalse(StringUtils.isIdenticalAfterDowncase(" Capitalize")); + assertTrue(StringUtils.isIdenticalAfterUpcase("CAPITALIZE")); + assertFalse(StringUtils.isIdenticalAfterDowncase("CAPITALIZE")); + assertTrue(StringUtils.isIdenticalAfterUpcase(" PI26LIE")); + assertFalse(StringUtils.isIdenticalAfterDowncase(" PI26LIE")); + assertTrue(StringUtils.isIdenticalAfterUpcase("")); + assertTrue(StringUtils.isIdenticalAfterDowncase("")); + } + + private static void checkCapitalize(final String src, final String dst, + final int[] sortedSeparators, final Locale locale) { + assertEquals(dst, StringUtils.capitalizeEachWord(src, sortedSeparators, locale)); + assert(src.equals(dst) + == StringUtils.isIdenticalAfterCapitalizeEachWord(src, sortedSeparators)); + } + + private static final int[] SPACE = { Constants.CODE_SPACE }; + private static final int[] SPACE_PERIOD = StringUtils.toSortedCodePointArray(" ."); + private static final int[] SENTENCE_SEPARATORS = + StringUtils.toSortedCodePointArray(" \n.!?*()&"); + private static final int[] WORD_SEPARATORS = StringUtils.toSortedCodePointArray(" \n.!?*,();&"); + + @Test + public void testCapitalizeEachWord() { + checkCapitalize("", "", SPACE, Locale.ENGLISH); + checkCapitalize("test", "Test", SPACE, Locale.ENGLISH); + checkCapitalize(" test", " Test", SPACE, Locale.ENGLISH); + checkCapitalize("Test", "Test", SPACE, Locale.ENGLISH); + checkCapitalize(" Test", " Test", SPACE, Locale.ENGLISH); + checkCapitalize(".Test", ".test", SPACE, Locale.ENGLISH); + checkCapitalize(".Test", ".Test", SPACE_PERIOD, Locale.ENGLISH); + checkCapitalize("test and retest", "Test And Retest", SPACE_PERIOD, Locale.ENGLISH); + checkCapitalize("Test and retest", "Test And Retest", SPACE_PERIOD, Locale.ENGLISH); + checkCapitalize("Test And Retest", "Test And Retest", SPACE_PERIOD, Locale.ENGLISH); + checkCapitalize("Test And.Retest ", "Test And.Retest ", SPACE_PERIOD, Locale.ENGLISH); + checkCapitalize("Test And.retest ", "Test And.Retest ", SPACE_PERIOD, Locale.ENGLISH); + checkCapitalize("Test And.retest ", "Test And.retest ", SPACE, Locale.ENGLISH); + checkCapitalize("Test And.Retest ", "Test And.retest ", SPACE, Locale.ENGLISH); + checkCapitalize("test and ietest", "Test And İetest", SPACE_PERIOD, new Locale("tr")); + checkCapitalize("test and ietest", "Test And Ietest", SPACE_PERIOD, Locale.ENGLISH); + checkCapitalize("Test&Retest", "Test&Retest", SENTENCE_SEPARATORS, Locale.ENGLISH); + checkCapitalize("Test&retest", "Test&Retest", SENTENCE_SEPARATORS, Locale.ENGLISH); + checkCapitalize("test&Retest", "Test&Retest", SENTENCE_SEPARATORS, Locale.ENGLISH); + checkCapitalize("rest\nrecreation! And in the end...", + "Rest\nRecreation! And In The End...", WORD_SEPARATORS, Locale.ENGLISH); + checkCapitalize("lorem ipsum dolor sit amet", "Lorem Ipsum Dolor Sit Amet", + WORD_SEPARATORS, Locale.ENGLISH); + checkCapitalize("Lorem!Ipsum (Dolor) Sit * Amet", "Lorem!Ipsum (Dolor) Sit * Amet", + WORD_SEPARATORS, Locale.ENGLISH); + checkCapitalize("Lorem!Ipsum (dolor) Sit * Amet", "Lorem!Ipsum (Dolor) Sit * Amet", + WORD_SEPARATORS, Locale.ENGLISH); + } + + @Test + public void testLooksLikeURL() { + assertTrue(StringUtils.lastPartLooksLikeURL("http://www.google.")); + assertFalse(StringUtils.lastPartLooksLikeURL("word wo")); + assertTrue(StringUtils.lastPartLooksLikeURL("/etc/foo")); + assertFalse(StringUtils.lastPartLooksLikeURL("left/right")); + assertTrue(StringUtils.lastPartLooksLikeURL("www.goo")); + assertTrue(StringUtils.lastPartLooksLikeURL("www.")); + assertFalse(StringUtils.lastPartLooksLikeURL("U.S.A")); + assertFalse(StringUtils.lastPartLooksLikeURL("U.S.A.")); + assertTrue(StringUtils.lastPartLooksLikeURL("rtsp://foo.")); + assertTrue(StringUtils.lastPartLooksLikeURL("://")); + assertFalse(StringUtils.lastPartLooksLikeURL("abc/")); + assertTrue(StringUtils.lastPartLooksLikeURL("abc.def/ghi")); + assertFalse(StringUtils.lastPartLooksLikeURL("abc.def")); + // TODO: ideally this would not look like a URL, but to keep down the complexity of the + // code for now True is acceptable. + assertTrue(StringUtils.lastPartLooksLikeURL("abc./def")); + // TODO: ideally this would not look like a URL, but to keep down the complexity of the + // code for now True is acceptable. + assertTrue(StringUtils.lastPartLooksLikeURL(".abc/def")); + } + + @Test + public void testHexStringUtils() { + final byte[] bytes = new byte[] { (byte)0x01, (byte)0x11, (byte)0x22, (byte)0x33, + (byte)0x55, (byte)0x88, (byte)0xEE }; + final String bytesStr = StringUtils.byteArrayToHexString(bytes); + final byte[] bytes2 = StringUtils.hexStringToByteArray(bytesStr); + for (int i = 0; i < bytes.length; ++i) { + assertTrue(bytes[i] == bytes2[i]); + } + final String bytesStr2 = StringUtils.byteArrayToHexString(bytes2); + assertTrue(bytesStr.equals(bytesStr2)); + } + + @Test + public void testToCodePointArray() { + final String STR_WITH_SUPPLEMENTARY_CHAR = "abcde\uD861\uDED7fgh\u0000\u2002\u2003\u3000xx"; + final int[] EXPECTED_RESULT = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7, 'f', 'g', 'h', + 0, 0x2002, 0x2003, 0x3000, 'x', 'x'}; + final int[] codePointArray = StringUtils.toCodePointArray(STR_WITH_SUPPLEMENTARY_CHAR, 0, + STR_WITH_SUPPLEMENTARY_CHAR.length()); + assertEquals("toCodePointArray, size matches", codePointArray.length, + EXPECTED_RESULT.length); + for (int i = 0; i < EXPECTED_RESULT.length; ++i) { + assertEquals("toCodePointArray position " + i, codePointArray[i], EXPECTED_RESULT[i]); + } + } + + @Test + public void testCopyCodePointsAndReturnCodePointCount() { + final String STR_WITH_SUPPLEMENTARY_CHAR = "AbcDE\uD861\uDED7fGh\u0000\u2002\u3000あx"; + final int[] EXPECTED_RESULT = new int[] { 'A', 'b', 'c', 'D', 'E', 0x286D7, + 'f', 'G', 'h', 0, 0x2002, 0x3000, 'あ', 'x'}; + final int[] EXPECTED_RESULT_DOWNCASE = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7, + 'f', 'g', 'h', 0, 0x2002, 0x3000, 'あ', 'x'}; + + int[] codePointArray = new int[50]; + int codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray, + STR_WITH_SUPPLEMENTARY_CHAR, 0, + STR_WITH_SUPPLEMENTARY_CHAR.length(), false /* downCase */); + assertEquals("copyCodePointsAndReturnCodePointCount, size matches", codePointCount, + EXPECTED_RESULT.length); + for (int i = 0; i < codePointCount; ++i) { + assertEquals("copyCodePointsAndReturnCodePointCount position " + i, codePointArray[i], + EXPECTED_RESULT[i]); + } + + codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray, + STR_WITH_SUPPLEMENTARY_CHAR, 0, + STR_WITH_SUPPLEMENTARY_CHAR.length(), true /* downCase */); + assertEquals("copyCodePointsAndReturnCodePointCount downcase, size matches", codePointCount, + EXPECTED_RESULT_DOWNCASE.length); + for (int i = 0; i < codePointCount; ++i) { + assertEquals("copyCodePointsAndReturnCodePointCount position " + i, codePointArray[i], + EXPECTED_RESULT_DOWNCASE[i]); + } + + final int JAVA_CHAR_COUNT = 8; + final int CODEPOINT_COUNT = 7; + codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray, + STR_WITH_SUPPLEMENTARY_CHAR, 0, JAVA_CHAR_COUNT, false /* downCase */); + assertEquals("copyCodePointsAndReturnCodePointCount, size matches", codePointCount, + CODEPOINT_COUNT); + for (int i = 0; i < codePointCount; ++i) { + assertEquals("copyCodePointsAndReturnCodePointCount position " + i, codePointArray[i], + EXPECTED_RESULT[i]); + } + + boolean exceptionHappened = false; + codePointArray = new int[5]; + try { + codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray, + STR_WITH_SUPPLEMENTARY_CHAR, 0, JAVA_CHAR_COUNT, false /* downCase */); + } catch (ArrayIndexOutOfBoundsException e) { + exceptionHappened = true; + } + assertTrue("copyCodePointsAndReturnCodePointCount throws when array is too small", + exceptionHappened); + } + + @Test + public void testGetTrailingSingleQuotesCount() { + assertEquals(0, StringUtils.getTrailingSingleQuotesCount("")); + assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'")); + assertEquals(5, StringUtils.getTrailingSingleQuotesCount("'''''")); + assertEquals(0, StringUtils.getTrailingSingleQuotesCount("a")); + assertEquals(0, StringUtils.getTrailingSingleQuotesCount("'this")); + assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'word'")); + assertEquals(0, StringUtils.getTrailingSingleQuotesCount("I'm")); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/common/UnicodeSurrogateTests.java b/tests/src/org/kelar/inputmethod/latin/common/UnicodeSurrogateTests.java new file mode 100644 index 000000000..7fad18588 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/common/UnicodeSurrogateTests.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 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 org.kelar.inputmethod.latin.common; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class UnicodeSurrogateTests { + + @Test + public void testIsLowSurrogate() { + assertFalse(UnicodeSurrogate.isLowSurrogate('\uD7FF')); + assertTrue(UnicodeSurrogate.isLowSurrogate('\uD83D')); + assertFalse(UnicodeSurrogate.isLowSurrogate('\uDC00')); + } + + @Test + public void testIsHighSurrogate() { + assertFalse(UnicodeSurrogate.isHighSurrogate('\uDBFF')); + assertTrue(UnicodeSurrogate.isHighSurrogate('\uDE25')); + assertFalse(UnicodeSurrogate.isHighSurrogate('\uE000')); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/AbstractDictDecoder.java b/tests/src/org/kelar/inputmethod/latin/makedict/AbstractDictDecoder.java new file mode 100644 index 000000000..978e6cd3a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/AbstractDictDecoder.java @@ -0,0 +1,104 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.TreeMap; + +/** + * A base class of the binary dictionary decoder. + */ +public abstract class AbstractDictDecoder implements DictDecoder { + private static final int SUCCESS = 0; + private static final int ERROR_CANNOT_READ = 1; + private static final int ERROR_WRONG_FORMAT = 2; + + @Override @UsedForTesting + public int getTerminalPosition(final String word) + throws IOException, UnsupportedFormatException { + if (!isDictBufferOpen()) { + openDictBuffer(); + } + return BinaryDictIOUtils.getTerminalPosition(this, word); + } + + @Override @UsedForTesting + public void readUnigramsAndBigramsBinary(final TreeMap<Integer, String> words, + final TreeMap<Integer, Integer> frequencies, + final TreeMap<Integer, ArrayList<PendingAttribute>> bigrams) + throws IOException, UnsupportedFormatException { + if (!isDictBufferOpen()) { + openDictBuffer(); + } + BinaryDictIOUtils.readUnigramsAndBigramsBinary(this, words, frequencies, bigrams); + } + + /** + * Check whether the header contains the expected information. This is a no-error method, + * that will return an error code and never throw a checked exception. + * @return an error code, either ERROR_* or SUCCESS. + */ + private int checkHeader() { + try { + readHeader(); + } catch (IOException e) { + return ERROR_CANNOT_READ; + } catch (UnsupportedFormatException e) { + return ERROR_WRONG_FORMAT; + } + return SUCCESS; + } + + @Override + public boolean hasValidRawBinaryDictionary() { + return checkHeader() == SUCCESS; + } + + // Placeholder implementations below. These are actually unused. + @Override + public void openDictBuffer() throws FileNotFoundException, IOException, + UnsupportedFormatException { + } + + @Override + public boolean isDictBufferOpen() { + return false; + } + + @Override + public PtNodeInfo readPtNode(final int ptNodePos) { + return null; + } + + @Override + public void setPosition(int newPos) { + } + + @Override + public int getPosition() { + return 0; + } + + @Override + public int readPtNodeCount() { + return 0; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java new file mode 100644 index 000000000..659df6859 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -0,0 +1,675 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import android.test.AndroidTestCase; +import android.util.Log; +import android.util.Pair; +import android.util.SparseArray; + +import org.kelar.inputmethod.latin.BinaryDictionary; +import org.kelar.inputmethod.latin.common.CodePointUtils; +import org.kelar.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding; +import org.kelar.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; +import org.kelar.inputmethod.latin.makedict.FormatSpec.FormatOptions; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNode; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; +import org.kelar.inputmethod.latin.utils.BinaryDictionaryUtils; +import org.kelar.inputmethod.latin.utils.ByteArrayDictBuffer; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; + +/** + * Unit tests for BinaryDictDecoderUtils and BinaryDictEncoderUtils. + */ +public class BinaryDictDecoderEncoderTests extends AndroidTestCase { + private static final String TAG = BinaryDictDecoderEncoderTests.class.getSimpleName(); + private static final int DEFAULT_MAX_UNIGRAMS = 300; + private static final int DEFAULT_CODE_POINT_SET_SIZE = 50; + private static final int LARGE_CODE_POINT_SET_SIZE = 300; + private static final int UNIGRAM_FREQ = 10; + private static final int BIGRAM_FREQ = 50; + private static final int TOLERANCE_OF_BIGRAM_FREQ = 5; + + private static final ArrayList<String> sWords = new ArrayList<>(); + private static final ArrayList<String> sWordsWithVariousCodePoints = new ArrayList<>(); + private static final SparseArray<List<Integer>> sEmptyBigrams = new SparseArray<>(); + private static final SparseArray<List<Integer>> sStarBigrams = new SparseArray<>(); + private static final SparseArray<List<Integer>> sChainBigrams = new SparseArray<>(); + + final Random mRandom; + + public BinaryDictDecoderEncoderTests() { + this(System.currentTimeMillis(), DEFAULT_MAX_UNIGRAMS); + } + + public BinaryDictDecoderEncoderTests(final long seed, final int maxUnigrams) { + super(); + BinaryDictionaryUtils.setCurrentTimeForTest(0); + Log.e(TAG, "Testing dictionary: seed is " + seed); + mRandom = new Random(seed); + sWords.clear(); + sWordsWithVariousCodePoints.clear(); + generateWords(maxUnigrams, mRandom); + + for (int i = 0; i < sWords.size(); ++i) { + sChainBigrams.put(i, new ArrayList<Integer>()); + if (i > 0) { + sChainBigrams.get(i - 1).add(i); + } + } + + sStarBigrams.put(0, new ArrayList<Integer>()); + // MAX - 1 because we added one above already + final int maxBigrams = Math.min(sWords.size(), FormatSpec.MAX_BIGRAMS_IN_A_PTNODE - 1); + for (int i = 1; i < maxBigrams; ++i) { + sStarBigrams.get(0).add(i); + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + BinaryDictionaryUtils.setCurrentTimeForTest(0); + } + + @Override + protected void tearDown() throws Exception { + // Quit test mode. + BinaryDictionaryUtils.setCurrentTimeForTest(-1); + super.tearDown(); + } + + private static void generateWords(final int number, final Random random) { + final int[] codePointSet = CodePointUtils.generateCodePointSet(DEFAULT_CODE_POINT_SET_SIZE, + random); + final Set<String> wordSet = new HashSet<>(); + while (wordSet.size() < number) { + wordSet.add(CodePointUtils.generateWord(random, codePointSet)); + } + sWords.addAll(wordSet); + + final int[] largeCodePointSet = CodePointUtils.generateCodePointSet( + LARGE_CODE_POINT_SET_SIZE, random); + wordSet.clear(); + while (wordSet.size() < number) { + wordSet.add(CodePointUtils.generateWord(random, largeCodePointSet)); + } + sWordsWithVariousCodePoints.addAll(wordSet); + } + + /** + * Adds unigrams to the dictionary. + */ + private static void addUnigrams(final int number, final FusionDictionary dict, + final List<String> words) { + for (int i = 0; i < number; ++i) { + final String word = words.get(i); + final ArrayList<WeightedString> shortcuts = new ArrayList<>(); + dict.add(word, new ProbabilityInfo(UNIGRAM_FREQ), false /* isNotAWord */, + false /* isPossiblyOffensive */); + } + } + + private static void addBigrams(final FusionDictionary dict, + final List<String> words, + final SparseArray<List<Integer>> bigrams) { + for (int i = 0; i < bigrams.size(); ++i) { + final int w1 = bigrams.keyAt(i); + for (int w2 : bigrams.valueAt(i)) { + dict.setBigram(words.get(w1), words.get(w2), new ProbabilityInfo(BIGRAM_FREQ)); + } + } + } + +// The following is useful to dump the dictionary into a textual file, but it can't compile +// on-device, so it's commented out. +// private void dumpToCombinedFileForDebug(final FusionDictionary dict, final String filename) +// throws IOException { +// org.kelar.inputmethod.latin.dicttool.CombinedInputOutput.writeDictionaryCombined( +// new java.io.FileWriter(new File(filename)), dict); +// } + + private static long timeWritingDictToFile(final File file, final FusionDictionary dict, + final FormatSpec.FormatOptions formatOptions) { + + long now = -1, diff = -1; + + try { + final DictEncoder dictEncoder = BinaryDictUtils.getDictEncoder(file, formatOptions); + + now = System.currentTimeMillis(); + // If you need to dump the dict to a textual file, uncomment the line below and the + // function above + // dumpToCombinedFileForDebug(file, "/tmp/foo"); + dictEncoder.writeDictionary(dict, formatOptions); + diff = System.currentTimeMillis() - now; + } catch (IOException e) { + Log.e(TAG, "IO exception while writing file", e); + } catch (UnsupportedFormatException e) { + Log.e(TAG, "UnsupportedFormatException", e); + } + + return diff; + } + + private static void checkDictionary(final FusionDictionary dict, final List<String> words, + final SparseArray<List<Integer>> bigrams) { + assertNotNull(dict); + + // check unigram + for (final String word : words) { + final PtNode ptNode = FusionDictionary.findWordInTree(dict.mRootNodeArray, word); + assertNotNull(ptNode); + } + + // check bigram + for (int i = 0; i < bigrams.size(); ++i) { + final int w1 = bigrams.keyAt(i); + for (final int w2 : bigrams.valueAt(i)) { + final PtNode ptNode = FusionDictionary.findWordInTree(dict.mRootNodeArray, + words.get(w1)); + assertNotNull(words.get(w1) + "," + words.get(w2), ptNode.getBigram(words.get(w2))); + } + } + } + + private static String outputOptions(final int bufferType, + final FormatSpec.FormatOptions formatOptions) { + final String result = " : buffer type = " + + ((bufferType == BinaryDictUtils.USE_BYTE_BUFFER) ? "byte buffer" : "byte array"); + return result + " : version = " + formatOptions.mVersion; + } + + // Tests for readDictionaryBinary and writeDictionaryBinary + + private static long timeReadingAndCheckDict(final File file, final List<String> words, + final SparseArray<List<Integer>> bigrams, final int bufferType) { + long now, diff = -1; + + FusionDictionary dict = null; + try { + final DictDecoder dictDecoder = BinaryDictIOUtils.getDictDecoder(file, 0, file.length(), + bufferType); + now = System.currentTimeMillis(); + dict = dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */); + diff = System.currentTimeMillis() - now; + } catch (IOException e) { + Log.e(TAG, "IOException while reading dictionary", e); + } catch (UnsupportedFormatException e) { + Log.e(TAG, "Unsupported format", e); + } + + checkDictionary(dict, words, bigrams); + return diff; + } + + // Tests for readDictionaryBinary and writeDictionaryBinary + private String runReadAndWrite(final List<String> words, + final SparseArray<List<Integer>> bigrams, + final int bufferType, final FormatSpec.FormatOptions formatOptions, + final String message) { + + final String dictName = "runReadAndWrite"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + final File file = BinaryDictUtils.getDictFile(dictName, dictVersion, formatOptions, + getContext().getCacheDir()); + + final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(words.size(), dict, words); + addBigrams(dict, words, bigrams); + checkDictionary(dict, words, bigrams); + + final long write = timeWritingDictToFile(file, dict, formatOptions); + final long read = timeReadingAndCheckDict(file, words, bigrams, bufferType); + + return "PROF: read=" + read + "ms, write=" + write + "ms :" + message + + " : " + outputOptions(bufferType, formatOptions); + } + + private void runReadAndWriteTests(final List<String> results, final int bufferType, + final FormatSpec.FormatOptions formatOptions) { + results.add(runReadAndWrite(sWords, sEmptyBigrams, bufferType, + formatOptions, "unigram")); + results.add(runReadAndWrite(sWords, sChainBigrams, bufferType, + formatOptions, "chain")); + results.add(runReadAndWrite(sWords, sStarBigrams, bufferType, + formatOptions, "star")); + results.add(runReadAndWrite(sWords, sEmptyBigrams, bufferType, formatOptions, + "unigram with shortcuts")); + results.add(runReadAndWrite(sWords, sChainBigrams, bufferType, formatOptions, + "chain with shortcuts")); + results.add(runReadAndWrite(sWords, sStarBigrams, bufferType, formatOptions, + "star with shortcuts")); + results.add(runReadAndWrite(sWordsWithVariousCodePoints, sEmptyBigrams, + bufferType, formatOptions, + "unigram with various code points")); + } + + public void testCharacterTableIsPresent() throws IOException, UnsupportedFormatException { + final String[] wordSource = {"words", "used", "for", "testing", "a", "code point", "table"}; + final List<String> words = Arrays.asList(wordSource); + final String correctCodePointTable = "toesdrniawuplgfcb "; + final String dictName = "codePointTableTest"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + final String codePointTableAttribute = DictionaryHeader.CODE_POINT_TABLE_KEY; + final File file = BinaryDictUtils.getDictFile(dictName, dictVersion, + BinaryDictUtils.STATIC_OPTIONS, getContext().getCacheDir()); + + // Write a test dictionary + final DictEncoder dictEncoder = new Ver2DictEncoder(file, + Ver2DictEncoder.CODE_POINT_TABLE_ON); + final FormatSpec.FormatOptions formatOptions = + new FormatSpec.FormatOptions( + FormatSpec.MINIMUM_SUPPORTED_STATIC_VERSION); + final FusionDictionary sourcedict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(words.size(), sourcedict, words); + dictEncoder.writeDictionary(sourcedict, formatOptions); + + // Read the dictionary + final DictDecoder dictDecoder = BinaryDictIOUtils.getDictDecoder(file, 0, file.length(), + DictDecoder.USE_BYTEARRAY); + final DictionaryHeader fileHeader = dictDecoder.readHeader(); + // Check if codePointTable is present + assertTrue("codePointTable is not present", + fileHeader.mDictionaryOptions.mAttributes.containsKey(codePointTableAttribute)); + final String codePointTable = + fileHeader.mDictionaryOptions.mAttributes.get(codePointTableAttribute); + // Check if codePointTable is correct + assertEquals("codePointTable is incorrect", codePointTable, correctCodePointTable); + } + + // Unit test for CharEncoding.readString and CharEncoding.writeString. + public void testCharEncoding() { + // the max length of a word in sWords is less than 50. + // See generateWords. + final byte[] buffer = new byte[50 * 3]; + final DictBuffer dictBuffer = new ByteArrayDictBuffer(buffer); + for (final String word : sWords) { + Arrays.fill(buffer, (byte) 0); + CharEncoding.writeString(buffer, 0, word, null); + dictBuffer.position(0); + final String str = CharEncoding.readString(dictBuffer); + assertEquals(word, str); + } + } + + public void testReadAndWriteWithByteBuffer() { + final List<String> results = new ArrayList<>(); + + runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_BUFFER, + BinaryDictUtils.STATIC_OPTIONS); + runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_BUFFER, + BinaryDictUtils.DYNAMIC_OPTIONS_WITHOUT_TIMESTAMP); + runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_BUFFER, + BinaryDictUtils.DYNAMIC_OPTIONS_WITH_TIMESTAMP); + for (final String result : results) { + Log.d(TAG, result); + } + } + + public void testReadAndWriteWithByteArray() { + final List<String> results = new ArrayList<>(); + + runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_ARRAY, + BinaryDictUtils.STATIC_OPTIONS); + runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_ARRAY, + BinaryDictUtils.DYNAMIC_OPTIONS_WITHOUT_TIMESTAMP); + runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_ARRAY, + BinaryDictUtils.DYNAMIC_OPTIONS_WITH_TIMESTAMP); + + for (final String result : results) { + Log.d(TAG, result); + } + } + + // Tests for readUnigramsAndBigramsBinary + + private static void checkWordMap(final List<String> expectedWords, + final SparseArray<List<Integer>> expectedBigrams, + final TreeMap<Integer, String> resultWords, + final TreeMap<Integer, Integer> resultFrequencies, + final TreeMap<Integer, ArrayList<PendingAttribute>> resultBigrams, + final boolean checkProbability) { + // check unigrams + final Set<String> actualWordsSet = new HashSet<>(resultWords.values()); + final Set<String> expectedWordsSet = new HashSet<>(expectedWords); + assertEquals(actualWordsSet, expectedWordsSet); + if (checkProbability) { + for (int freq : resultFrequencies.values()) { + assertEquals(freq, UNIGRAM_FREQ); + } + } + + // check bigrams + final HashMap<String, Set<String>> expBigrams = new HashMap<>(); + for (int i = 0; i < expectedBigrams.size(); ++i) { + final String word1 = expectedWords.get(expectedBigrams.keyAt(i)); + for (int w2 : expectedBigrams.valueAt(i)) { + if (expBigrams.get(word1) == null) { + expBigrams.put(word1, new HashSet<String>()); + } + expBigrams.get(word1).add(expectedWords.get(w2)); + } + } + + final HashMap<String, Set<String>> actBigrams = new HashMap<>(); + for (Entry<Integer, ArrayList<PendingAttribute>> entry : resultBigrams.entrySet()) { + final String word1 = resultWords.get(entry.getKey()); + final int unigramFreq = resultFrequencies.get(entry.getKey()); + for (PendingAttribute attr : entry.getValue()) { + final String word2 = resultWords.get(attr.mAddress); + if (actBigrams.get(word1) == null) { + actBigrams.put(word1, new HashSet<String>()); + } + actBigrams.get(word1).add(word2); + + if (checkProbability) { + final int bigramFreq = BinaryDictIOUtils.reconstructBigramFrequency( + unigramFreq, attr.mFrequency); + assertTrue(Math.abs(bigramFreq - BIGRAM_FREQ) < TOLERANCE_OF_BIGRAM_FREQ); + } + } + } + assertEquals(actBigrams, expBigrams); + } + + private static long timeAndCheckReadUnigramsAndBigramsBinary(final File file, + final List<String> words, final SparseArray<List<Integer>> bigrams, + final int bufferType, final boolean checkProbability) { + final TreeMap<Integer, String> resultWords = new TreeMap<>(); + final TreeMap<Integer, ArrayList<PendingAttribute>> resultBigrams = new TreeMap<>(); + final TreeMap<Integer, Integer> resultFreqs = new TreeMap<>(); + + long now = -1, diff = -1; + try { + final DictDecoder dictDecoder = BinaryDictIOUtils.getDictDecoder(file, 0, file.length(), + bufferType); + now = System.currentTimeMillis(); + dictDecoder.readUnigramsAndBigramsBinary(resultWords, resultFreqs, resultBigrams); + diff = System.currentTimeMillis() - now; + } catch (IOException e) { + Log.e(TAG, "IOException", e); + } catch (UnsupportedFormatException e) { + Log.e(TAG, "UnsupportedFormatException", e); + } + + checkWordMap(words, bigrams, resultWords, resultFreqs, resultBigrams, checkProbability); + return diff; + } + + private String runReadUnigramsAndBigramsBinary(final ArrayList<String> words, + final SparseArray<List<Integer>> bigrams, final int bufferType, + final FormatSpec.FormatOptions formatOptions, final String message) { + final String dictName = "runReadUnigrams"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + final File file = BinaryDictUtils.getDictFile(dictName, dictVersion, formatOptions, + getContext().getCacheDir()); + + // making the dictionary from lists of words. + final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(words.size(), dict, words); + addBigrams(dict, words, bigrams); + + timeWritingDictToFile(file, dict, formatOptions); + + // Caveat: Currently, the Java code to read a v4 dictionary doesn't calculate the + // probability when there's a timestamp for the entry. + // TODO: Abandon the Java code, and implement the v4 dictionary reading code in native. + long wordMap = timeAndCheckReadUnigramsAndBigramsBinary(file, words, bigrams, bufferType, + !formatOptions.mHasTimestamp /* checkProbability */); + long fullReading = timeReadingAndCheckDict(file, words, bigrams, + bufferType); + + return "readDictionaryBinary=" + fullReading + ", readUnigramsAndBigramsBinary=" + wordMap + + " : " + message + " : " + outputOptions(bufferType, formatOptions); + } + + private void runReadUnigramsAndBigramsTests(final ArrayList<String> results, + final int bufferType, final FormatSpec.FormatOptions formatOptions) { + results.add(runReadUnigramsAndBigramsBinary(sWords, sEmptyBigrams, bufferType, + formatOptions, "unigram")); + results.add(runReadUnigramsAndBigramsBinary(sWords, sChainBigrams, bufferType, + formatOptions, "chain")); + results.add(runReadUnigramsAndBigramsBinary(sWords, sStarBigrams, bufferType, + formatOptions, "star")); + } + + public void testReadUnigramsAndBigramsBinaryWithByteBuffer() { + final ArrayList<String> results = new ArrayList<>(); + + runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER, + BinaryDictUtils.STATIC_OPTIONS); + + for (final String result : results) { + Log.d(TAG, result); + } + } + + public void testReadUnigramsAndBigramsBinaryWithByteArray() { + final ArrayList<String> results = new ArrayList<>(); + + runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY, + BinaryDictUtils.STATIC_OPTIONS); + + for (final String result : results) { + Log.d(TAG, result); + } + } + + // Tests for getTerminalPosition + private static String getWordFromBinary(final DictDecoder dictDecoder, final int address) { + if (dictDecoder.getPosition() != 0) dictDecoder.setPosition(0); + + DictionaryHeader fileHeader = null; + try { + fileHeader = dictDecoder.readHeader(); + } catch (IOException e) { + return null; + } catch (UnsupportedFormatException e) { + return null; + } + if (fileHeader == null) return null; + return BinaryDictDecoderUtils.getWordAtPosition(dictDecoder, fileHeader.mBodyOffset, + address).mWord; + } + + private static long checkGetTerminalPosition(final DictDecoder dictDecoder, final String word, + final boolean contained) { + long diff = -1; + int position = -1; + try { + final long now = System.nanoTime(); + position = dictDecoder.getTerminalPosition(word); + diff = System.nanoTime() - now; + } catch (IOException e) { + Log.e(TAG, "IOException while getTerminalPosition", e); + } catch (UnsupportedFormatException e) { + Log.e(TAG, "UnsupportedFormatException while getTerminalPosition", e); + } + + assertEquals(FormatSpec.NOT_VALID_WORD != position, contained); + if (contained) assertEquals(getWordFromBinary(dictDecoder, position), word); + return diff; + } + + private void runGetTerminalPosition(final ArrayList<String> words, + final SparseArray<List<Integer>> bigrams, final int bufferType, + final FormatOptions formatOptions, final String message) { + final String dictName = "testGetTerminalPosition"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + final File file = BinaryDictUtils.getDictFile(dictName, dictVersion, formatOptions, + getContext().getCacheDir()); + + final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(sWords.size(), dict, sWords); + addBigrams(dict, words, bigrams); + timeWritingDictToFile(file, dict, formatOptions); + + final DictDecoder dictDecoder = BinaryDictIOUtils.getDictDecoder(file, 0, file.length(), + DictDecoder.USE_BYTEARRAY); + try { + dictDecoder.openDictBuffer(); + } catch (IOException e) { + Log.e(TAG, "IOException while opening the buffer", e); + } catch (UnsupportedFormatException e) { + Log.e(TAG, "IOException while opening the buffer", e); + } + assertTrue("Can't get the buffer", dictDecoder.isDictBufferOpen()); + + try { + // too long word + final String longWord = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; + assertEquals(FormatSpec.NOT_VALID_WORD, dictDecoder.getTerminalPosition(longWord)); + + // null + assertEquals(FormatSpec.NOT_VALID_WORD, dictDecoder.getTerminalPosition(null)); + + // empty string + assertEquals(FormatSpec.NOT_VALID_WORD, dictDecoder.getTerminalPosition("")); + } catch (IOException e) { + } catch (UnsupportedFormatException e) { + } + + // Test a word that is contained within the dictionary. + long sum = 0; + for (int i = 0; i < sWords.size(); ++i) { + final long time = checkGetTerminalPosition(dictDecoder, sWords.get(i), true); + sum += time == -1 ? 0 : time; + } + Log.d(TAG, "per search : " + (((double)sum) / sWords.size() / 1000000) + " : " + message + + " : " + outputOptions(bufferType, formatOptions)); + + // Test a word that isn't contained within the dictionary. + final int[] codePointSet = CodePointUtils.generateCodePointSet(DEFAULT_CODE_POINT_SET_SIZE, + mRandom); + for (int i = 0; i < 1000; ++i) { + final String word = CodePointUtils.generateWord(mRandom, codePointSet); + if (sWords.indexOf(word) != -1) continue; + checkGetTerminalPosition(dictDecoder, word, false); + } + } + + private void runGetTerminalPositionTests(final int bufferType, + final FormatOptions formatOptions) { + runGetTerminalPosition(sWords, sEmptyBigrams, bufferType, formatOptions, "unigram"); + } + + public void testGetTerminalPosition() { + final ArrayList<String> results = new ArrayList<>(); + + runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY, + BinaryDictUtils.STATIC_OPTIONS); + runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_BUFFER, + BinaryDictUtils.STATIC_OPTIONS); + + for (final String result : results) { + Log.d(TAG, result); + } + } + + public void testVer2DictGetWordProperty() { + final FormatOptions formatOptions = BinaryDictUtils.STATIC_OPTIONS; + final ArrayList<String> words = sWords; + final String dictName = "testGetWordProperty"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(words.size(), dict, words); + addBigrams(dict, words, sEmptyBigrams); + final File file = BinaryDictUtils.getDictFile(dictName, dictVersion, formatOptions, + getContext().getCacheDir()); + file.delete(); + timeWritingDictToFile(file, dict, formatOptions); + final BinaryDictionary binaryDictionary = new BinaryDictionary(file.getAbsolutePath(), + 0 /* offset */, file.length(), true /* useFullEditDistance */, + Locale.ENGLISH, dictName, false /* isUpdatable */); + for (final String word : words) { + final WordProperty wordProperty = binaryDictionary.getWordProperty(word, + false /* isBeginningOfSentence */); + assertEquals(word, wordProperty.mWord); + assertEquals(UNIGRAM_FREQ, wordProperty.getProbability()); + } + } + + public void testVer2DictIteration() { + final FormatOptions formatOptions = BinaryDictUtils.STATIC_OPTIONS; + final ArrayList<String> words = sWords; + final SparseArray<List<Integer>> bigrams = sEmptyBigrams; + final String dictName = "testGetWordProperty"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(words.size(), dict, words); + addBigrams(dict, words, bigrams); + final File file = BinaryDictUtils.getDictFile(dictName, dictVersion, formatOptions, + getContext().getCacheDir()); + timeWritingDictToFile(file, dict, formatOptions); + Log.d(TAG, file.getAbsolutePath()); + final BinaryDictionary binaryDictionary = new BinaryDictionary(file.getAbsolutePath(), + 0 /* offset */, file.length(), true /* useFullEditDistance */, + Locale.ENGLISH, dictName, false /* isUpdatable */); + + final HashSet<String> wordSet = new HashSet<>(words); + final HashSet<Pair<String, String>> bigramSet = new HashSet<>(); + + for (int i = 0; i < words.size(); i++) { + final List<Integer> bigramList = bigrams.get(i); + if (bigramList != null) { + for (final Integer word1Index : bigramList) { + final String word1 = words.get(word1Index); + bigramSet.add(new Pair<>(words.get(i), word1)); + } + } + } + int token = 0; + do { + final BinaryDictionary.GetNextWordPropertyResult result = + binaryDictionary.getNextWordProperty(token); + final WordProperty wordProperty = result.mWordProperty; + final String word0 = wordProperty.mWord; + assertEquals(UNIGRAM_FREQ, wordProperty.mProbabilityInfo.mProbability); + wordSet.remove(word0); + if (wordProperty.mHasNgrams) { + for (final WeightedString bigramTarget : wordProperty.getBigrams()) { + final String word1 = bigramTarget.mWord; + final Pair<String, String> bigram = new Pair<>(word0, word1); + assertTrue(bigramSet.contains(bigram)); + bigramSet.remove(bigram); + } + } + token = result.mNextToken; + } while (token != 0); + assertTrue(wordSet.isEmpty()); + assertTrue(bigramSet.isEmpty()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictDecoderUtils.java new file mode 100644 index 000000000..18199ae21 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictDecoderUtils.java @@ -0,0 +1,425 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.LinkedList; + +import javax.annotation.Nonnull; + +/** + * Decodes binary files for a FusionDictionary. + * + * All the methods in this class are static. + * + * TODO: Move this file to makedict/internal. + * TODO: Rename this class to DictDecoderUtils. + */ +public final class BinaryDictDecoderUtils { + private BinaryDictDecoderUtils() { + // This utility class is not publicly instantiable. + } + + @UsedForTesting + public interface DictBuffer { + public int readUnsignedByte(); + public int readUnsignedShort(); + public int readUnsignedInt24(); + public int readInt(); + public int position(); + public void position(int newPosition); + @UsedForTesting + public void put(final byte b); + public int limit(); + @UsedForTesting + public int capacity(); + } + + public static final class ByteBufferDictBuffer implements DictBuffer { + private ByteBuffer mBuffer; + + public ByteBufferDictBuffer(final ByteBuffer buffer) { + mBuffer = buffer; + } + + @Override + public int readUnsignedByte() { + return mBuffer.get() & 0xFF; + } + + @Override + public int readUnsignedShort() { + return mBuffer.getShort() & 0xFFFF; + } + + @Override + public int readUnsignedInt24() { + final int retval = readUnsignedByte(); + return (retval << 16) + readUnsignedShort(); + } + + @Override + public int readInt() { + return mBuffer.getInt(); + } + + @Override + public int position() { + return mBuffer.position(); + } + + @Override + public void position(int newPos) { + mBuffer.position(newPos); + } + + @Override + public void put(final byte b) { + mBuffer.put(b); + } + + @Override + public int limit() { + return mBuffer.limit(); + } + + @Override + public int capacity() { + return mBuffer.capacity(); + } + } + + /** + * A class grouping utility function for our specific character encoding. + */ + static final class CharEncoding { + + /** + * Helper method to find out whether this code fits on one byte + */ + private static boolean fitsOnOneByte(final int character, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + int codePoint = character; + if (codePointToOneByteCodeMap != null) { + if (codePointToOneByteCodeMap.containsKey(character)) { + codePoint = codePointToOneByteCodeMap.get(character); + } + } + return codePoint >= FormatSpec.MINIMAL_ONE_BYTE_CHARACTER_VALUE + && codePoint <= FormatSpec.MAXIMAL_ONE_BYTE_CHARACTER_VALUE; + } + + /** + * Compute the size of a character given its character code. + * + * Char format is: + * 1 byte = bbbbbbbb match + * case 000xxxxx: xxxxx << 16 + next byte << 8 + next byte + * else: if 00011111 (= 0x1F) : this is the terminator. This is a relevant choice because + * unicode code points range from 0 to 0x10FFFF, so any 3-byte value starting with + * 00011111 would be outside unicode. + * else: iso-latin-1 code + * This allows for the whole unicode range to be encoded, including chars outside of + * the BMP. Also everything in the iso-latin-1 charset is only 1 byte, except control + * characters which should never happen anyway (and still work, but take 3 bytes). + * + * @param character the character code. + * @return the size in binary encoded-form, either 1 or 3 bytes. + */ + static int getCharSize(final int character, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + // See char encoding in FusionDictionary.java + if (fitsOnOneByte(character, codePointToOneByteCodeMap)) return 1; + if (FormatSpec.INVALID_CHARACTER == character) return 1; + return 3; + } + + /** + * Compute the byte size of a character array. + */ + static int getCharArraySize(final int[] chars, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + int size = 0; + for (int character : chars) size += getCharSize(character, codePointToOneByteCodeMap); + return size; + } + + /** + * Writes a char array to a byte buffer. + * + * @param codePoints the code point array to write. + * @param buffer the byte buffer to write to. + * @param fromIndex the index in buffer to write the character array to. + * @param codePointToOneByteCodeMap the map to convert the code point. + * @return the index after the last character. + */ + static int writeCharArray(final int[] codePoints, final byte[] buffer, final int fromIndex, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + int index = fromIndex; + for (int codePoint : codePoints) { + if (codePointToOneByteCodeMap != null) { + if (codePointToOneByteCodeMap.containsKey(codePoint)) { + // Convert code points + codePoint = codePointToOneByteCodeMap.get(codePoint); + } + } + if (1 == getCharSize(codePoint, codePointToOneByteCodeMap)) { + buffer[index++] = (byte)codePoint; + } else { + buffer[index++] = (byte)(0xFF & (codePoint >> 16)); + buffer[index++] = (byte)(0xFF & (codePoint >> 8)); + buffer[index++] = (byte)(0xFF & codePoint); + } + } + return index; + } + + /** + * Writes a string with our character format to a byte buffer. + * + * This will also write the terminator byte. + * + * @param buffer the byte buffer to write to. + * @param origin the offset to write from. + * @param word the string to write. + * @return the size written, in bytes. + */ + static int writeString(final byte[] buffer, final int origin, final String word, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + final int length = word.length(); + int index = origin; + for (int i = 0; i < length; i = word.offsetByCodePoints(i, 1)) { + int codePoint = word.codePointAt(i); + if (codePointToOneByteCodeMap != null) { + if (codePointToOneByteCodeMap.containsKey(codePoint)) { + // Convert code points + codePoint = codePointToOneByteCodeMap.get(codePoint); + } + } + if (1 == getCharSize(codePoint, codePointToOneByteCodeMap)) { + buffer[index++] = (byte)codePoint; + } else { + buffer[index++] = (byte)(0xFF & (codePoint >> 16)); + buffer[index++] = (byte)(0xFF & (codePoint >> 8)); + buffer[index++] = (byte)(0xFF & codePoint); + } + } + buffer[index++] = FormatSpec.PTNODE_CHARACTERS_TERMINATOR; + return index - origin; + } + + /** + * Writes a string with our character format to an OutputStream. + * + * This will also write the terminator byte. + * + * @param stream the OutputStream to write to. + * @param word the string to write. + * @return the size written, in bytes. + */ + static int writeString(final OutputStream stream, final String word, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) throws IOException { + final int length = word.length(); + int written = 0; + for (int i = 0; i < length; i = word.offsetByCodePoints(i, 1)) { + final int codePoint = word.codePointAt(i); + final int charSize = getCharSize(codePoint, codePointToOneByteCodeMap); + if (1 == charSize) { + stream.write((byte) codePoint); + } else { + stream.write((byte) (0xFF & (codePoint >> 16))); + stream.write((byte) (0xFF & (codePoint >> 8))); + stream.write((byte) (0xFF & codePoint)); + } + written += charSize; + } + stream.write(FormatSpec.PTNODE_CHARACTERS_TERMINATOR); + written += FormatSpec.PTNODE_TERMINATOR_SIZE; + return written; + } + + /** + * Reads a string from a DictBuffer. This is the converse of the above method. + */ + static String readString(final DictBuffer dictBuffer) { + final StringBuilder s = new StringBuilder(); + int character = readChar(dictBuffer); + while (character != FormatSpec.INVALID_CHARACTER) { + s.appendCodePoint(character); + character = readChar(dictBuffer); + } + return s.toString(); + } + + /** + * Reads a character from the buffer. + * + * This follows the character format documented earlier in this source file. + * + * @param dictBuffer the buffer, positioned over an encoded character. + * @return the character code. + */ + static int readChar(final DictBuffer dictBuffer) { + int character = dictBuffer.readUnsignedByte(); + if (!fitsOnOneByte(character, null)) { + if (FormatSpec.PTNODE_CHARACTERS_TERMINATOR == character) { + return FormatSpec.INVALID_CHARACTER; + } + character <<= 16; + character += dictBuffer.readUnsignedShort(); + } + return character; + } + } + + /** + * Reads and returns the PtNode count out of a buffer and forwards the pointer. + */ + /* package */ static int readPtNodeCount(final DictBuffer dictBuffer) { + final int msb = dictBuffer.readUnsignedByte(); + if (FormatSpec.MAX_PTNODES_FOR_ONE_BYTE_PTNODE_COUNT >= msb) { + return msb; + } + return ((FormatSpec.MAX_PTNODES_FOR_ONE_BYTE_PTNODE_COUNT & msb) << 8) + + dictBuffer.readUnsignedByte(); + } + + /** + * Finds, as a string, the word at the position passed as an argument. + * + * @param dictDecoder the dict decoder. + * @param headerSize the size of the header. + * @param pos the position to seek. + * @return the word with its frequency, as a weighted string. + */ + @UsedForTesting + /* package for tests */ static WeightedString getWordAtPosition(final DictDecoder dictDecoder, + final int headerSize, final int pos) { + final WeightedString result; + final int originalPos = dictDecoder.getPosition(); + dictDecoder.setPosition(pos); + result = getWordAtPositionWithoutParentAddress(dictDecoder, headerSize, pos); + dictDecoder.setPosition(originalPos); + return result; + } + + private static WeightedString getWordAtPositionWithoutParentAddress( + final DictDecoder dictDecoder, final int headerSize, final int pos) { + dictDecoder.setPosition(headerSize); + final int count = dictDecoder.readPtNodeCount(); + int groupPos = dictDecoder.getPosition(); + final StringBuilder builder = new StringBuilder(); + WeightedString result = null; + + PtNodeInfo last = null; + for (int i = count - 1; i >= 0; --i) { + PtNodeInfo info = dictDecoder.readPtNode(groupPos); + groupPos = info.mEndAddress; + if (info.mOriginalAddress == pos) { + builder.append(new String(info.mCharacters, 0, info.mCharacters.length)); + result = new WeightedString(builder.toString(), info.mProbabilityInfo); + break; // and return + } + if (BinaryDictIOUtils.hasChildrenAddress(info.mChildrenAddress)) { + if (info.mChildrenAddress > pos) { + if (null == last) continue; + builder.append(new String(last.mCharacters, 0, last.mCharacters.length)); + dictDecoder.setPosition(last.mChildrenAddress); + i = dictDecoder.readPtNodeCount(); + groupPos = last.mChildrenAddress + BinaryDictIOUtils.getPtNodeCountSize(i); + last = null; + continue; + } + last = info; + } + if (0 == i && BinaryDictIOUtils.hasChildrenAddress(last.mChildrenAddress)) { + builder.append(new String(last.mCharacters, 0, last.mCharacters.length)); + dictDecoder.setPosition(last.mChildrenAddress); + i = dictDecoder.readPtNodeCount(); + groupPos = last.mChildrenAddress + BinaryDictIOUtils.getPtNodeCountSize(i); + last = null; + continue; + } + } + return result; + } + + /** + * Helper method that brutally decodes a header from a byte array. + * + * @param headerBuffer a buffer containing the bytes of the header. + * @return a hashmap of the attributes stored in the header + */ + @Nonnull + public static HashMap<String, String> decodeHeaderAttributes(@Nonnull final byte[] headerBuffer) + throws UnsupportedFormatException { + final StringBuilder sb = new StringBuilder(); + final LinkedList<String> keyValues = new LinkedList<>(); + int index = 0; + while (index < headerBuffer.length) { + if (headerBuffer[index] == FormatSpec.PTNODE_CHARACTERS_TERMINATOR) { + keyValues.add(sb.toString()); + sb.setLength(0); + } else if (CharEncoding.fitsOnOneByte(headerBuffer[index] & 0xFF, + null /* codePointTable */)) { + sb.appendCodePoint(headerBuffer[index] & 0xFF); + } else { + sb.appendCodePoint(((headerBuffer[index] & 0xFF) << 16) + + ((headerBuffer[index + 1] & 0xFF) << 8) + + (headerBuffer[index + 2] & 0xFF)); + index += 2; + } + index += 1; + } + if ((keyValues.size() & 1) != 0) { + throw new UnsupportedFormatException("Odd number of attributes"); + } + final HashMap<String, String> attributes = new HashMap<>(); + for (int i = 0; i < keyValues.size(); i += 2) { + attributes.put(keyValues.get(i), keyValues.get(i + 1)); + } + return attributes; + } + + /** + * Helper method to pass a file name instead of a File object to isBinaryDictionary. + */ + public static boolean isBinaryDictionary(final String filename) { + final File file = new File(filename); + return isBinaryDictionary(file); + } + + /** + * Basic test to find out whether the file is a binary dictionary or not. + * + * @param file The file to test. + * @return true if it's a binary dictionary, false otherwise + */ + public static boolean isBinaryDictionary(final File file) { + final DictDecoder dictDecoder = BinaryDictIOUtils.getDictDecoder(file, 0, file.length()); + if (dictDecoder == null) { + return false; + } + return dictDecoder.hasValidRawBinaryDictionary(); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictEncoderUtils.java b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictEncoderUtils.java new file mode 100644 index 000000000..3b35288d7 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictEncoderUtils.java @@ -0,0 +1,839 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding; +import org.kelar.inputmethod.latin.makedict.FormatSpec.FormatOptions; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNode; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; + +/** + * Encodes binary files for a FusionDictionary. + * + * All the methods in this class are static. + * + * TODO: Rename this class to DictEncoderUtils. + */ +public class BinaryDictEncoderUtils { + + private static final boolean DBG = MakedictLog.DBG; + + private BinaryDictEncoderUtils() { + // This utility class is not publicly instantiable. + } + + // Arbitrary limit to how much passes we consider address size compression should + // terminate in. At the time of this writing, our largest dictionary completes + // compression in five passes. + // If the number of passes exceeds this number, makedict bails with an exception on + // suspicion that a bug might be causing an infinite loop. + private static final int MAX_PASSES = 24; + + /** + * Compute the binary size of the character array. + * + * If only one character, this is the size of this character. If many, it's the sum of their + * sizes + 1 byte for the terminator. + * + * @param characters the character array + * @return the size of the char array, including the terminator if any + */ + static int getPtNodeCharactersSize(final int[] characters, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + int size = CharEncoding.getCharArraySize(characters, codePointToOneByteCodeMap); + if (characters.length > 1) size += FormatSpec.PTNODE_TERMINATOR_SIZE; + return size; + } + + /** + * Compute the binary size of the character array in a PtNode + * + * If only one character, this is the size of this character. If many, it's the sum of their + * sizes + 1 byte for the terminator. + * + * @param ptNode the PtNode + * @return the size of the char array, including the terminator if any + */ + private static int getPtNodeCharactersSize(final PtNode ptNode, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + return getPtNodeCharactersSize(ptNode.mChars, codePointToOneByteCodeMap); + } + + /** + * Compute the binary size of the PtNode count for a node array. + * @param nodeArray the nodeArray + * @return the size of the PtNode count, either 1 or 2 bytes. + */ + private static int getPtNodeCountSize(final PtNodeArray nodeArray) { + return BinaryDictIOUtils.getPtNodeCountSize(nodeArray.mData.size()); + } + + /** + * Compute the maximum size of a PtNode, assuming 3-byte addresses for everything. + * + * @param ptNode the PtNode to compute the size of. + * @return the maximum size of the PtNode. + */ + private static int getPtNodeMaximumSize(final PtNode ptNode, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + int size = getNodeHeaderSize(ptNode, codePointToOneByteCodeMap); + if (ptNode.isTerminal()) { + // If terminal, one byte for the frequency. + size += FormatSpec.PTNODE_FREQUENCY_SIZE; + } + size += FormatSpec.PTNODE_MAX_ADDRESS_SIZE; // For children address + if (null != ptNode.mBigrams) { + size += (FormatSpec.PTNODE_ATTRIBUTE_FLAGS_SIZE + + FormatSpec.PTNODE_ATTRIBUTE_MAX_ADDRESS_SIZE) + * ptNode.mBigrams.size(); + } + return size; + } + + /** + * Compute the maximum size of each PtNode of a PtNode array, assuming 3-byte addresses for + * everything, and caches it in the `mCachedSize' member of the nodes; deduce the size of + * the containing node array, and cache it it its 'mCachedSize' member. + * + * @param ptNodeArray the node array to compute the maximum size of. + */ + private static void calculatePtNodeArrayMaximumSize(final PtNodeArray ptNodeArray, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + int size = getPtNodeCountSize(ptNodeArray); + for (PtNode node : ptNodeArray.mData) { + final int nodeSize = getPtNodeMaximumSize(node, codePointToOneByteCodeMap); + node.mCachedSize = nodeSize; + size += nodeSize; + } + ptNodeArray.mCachedSize = size; + } + + /** + * Compute the size of the header (flag + [parent address] + characters size) of a PtNode. + * + * @param ptNode the PtNode of which to compute the size of the header + */ + private static int getNodeHeaderSize(final PtNode ptNode, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + return FormatSpec.PTNODE_FLAGS_SIZE + getPtNodeCharactersSize(ptNode, + codePointToOneByteCodeMap); + } + + /** + * Compute the size, in bytes, that an address will occupy. + * + * This can be used either for children addresses (which are always positive) or for + * attribute, which may be positive or negative but + * store their sign bit separately. + * + * @param address the address + * @return the byte size. + */ + static int getByteSize(final int address) { + assert(address <= FormatSpec.UINT24_MAX); + if (!BinaryDictIOUtils.hasChildrenAddress(address)) { + return 0; + } else if (Math.abs(address) <= FormatSpec.UINT8_MAX) { + return 1; + } else if (Math.abs(address) <= FormatSpec.UINT16_MAX) { + return 2; + } else { + return 3; + } + } + + static int writeUIntToBuffer(final byte[] buffer, final int fromPosition, final int value, + final int size) { + int position = fromPosition; + switch(size) { + case 4: + buffer[position++] = (byte) ((value >> 24) & 0xFF); + /* fall through */ + case 3: + buffer[position++] = (byte) ((value >> 16) & 0xFF); + /* fall through */ + case 2: + buffer[position++] = (byte) ((value >> 8) & 0xFF); + /* fall through */ + case 1: + buffer[position++] = (byte) (value & 0xFF); + break; + default: + /* nop */ + } + return position; + } + + static void writeUIntToStream(final OutputStream stream, final int value, final int size) + throws IOException { + switch(size) { + case 4: + stream.write((value >> 24) & 0xFF); + /* fall through */ + case 3: + stream.write((value >> 16) & 0xFF); + /* fall through */ + case 2: + stream.write((value >> 8) & 0xFF); + /* fall through */ + case 1: + stream.write(value & 0xFF); + break; + default: + /* nop */ + } + } + + // End utility methods + + // This method is responsible for finding a nice ordering of the nodes that favors run-time + // cache performance and dictionary size. + /* package for tests */ static ArrayList<PtNodeArray> flattenTree( + final PtNodeArray rootNodeArray) { + final int treeSize = FusionDictionary.countPtNodes(rootNodeArray); + MakedictLog.i("Counted nodes : " + treeSize); + final ArrayList<PtNodeArray> flatTree = new ArrayList<>(treeSize); + return flattenTreeInner(flatTree, rootNodeArray); + } + + private static ArrayList<PtNodeArray> flattenTreeInner(final ArrayList<PtNodeArray> list, + final PtNodeArray ptNodeArray) { + // Removing the node is necessary if the tails are merged, because we would then + // add the same node several times when we only want it once. A number of places in + // the code also depends on any node being only once in the list. + // Merging tails can only be done if there are no attributes. Searching for attributes + // in LatinIME code depends on a total breadth-first ordering, which merging tails + // breaks. If there are no attributes, it should be fine (and reduce the file size) + // to merge tails, and removing the node from the list would be necessary. However, + // we don't merge tails because breaking the breadth-first ordering would result in + // extreme overhead at bigram lookup time (it would make the search function O(n) instead + // of the current O(log(n)), where n=number of nodes in the dictionary which is pretty + // high). + // If no nodes are ever merged, we can't have the same node twice in the list, hence + // searching for duplicates in unnecessary. It is also very performance consuming, + // since `list' is an ArrayList so it's an O(n) operation that runs on all nodes, making + // this simple list.remove operation O(n*n) overall. On Android this overhead is very + // high. + // For future reference, the code to remove duplicate is a simple : list.remove(node); + list.add(ptNodeArray); + final ArrayList<PtNode> branches = ptNodeArray.mData; + for (PtNode ptNode : branches) { + if (null != ptNode.mChildren) flattenTreeInner(list, ptNode.mChildren); + } + return list; + } + + /** + * Get the offset from a position inside a current node array to a target node array, during + * update. + * + * If the current node array is before the target node array, the target node array has not + * been updated yet, so we should return the offset from the old position of the current node + * array to the old position of the target node array. If on the other hand the target is + * before the current node array, it already has been updated, so we should return the offset + * from the new position in the current node array to the new position in the target node + * array. + * + * @param currentNodeArray node array containing the PtNode where the offset will be written + * @param offsetFromStartOfCurrentNodeArray offset, in bytes, from the start of currentNodeArray + * @param targetNodeArray the target node array to get the offset to + * @return the offset to the target node array + */ + private static int getOffsetToTargetNodeArrayDuringUpdate(final PtNodeArray currentNodeArray, + final int offsetFromStartOfCurrentNodeArray, final PtNodeArray targetNodeArray) { + final boolean isTargetBeforeCurrent = (targetNodeArray.mCachedAddressBeforeUpdate + < currentNodeArray.mCachedAddressBeforeUpdate); + if (isTargetBeforeCurrent) { + return targetNodeArray.mCachedAddressAfterUpdate + - (currentNodeArray.mCachedAddressAfterUpdate + + offsetFromStartOfCurrentNodeArray); + } + return targetNodeArray.mCachedAddressBeforeUpdate + - (currentNodeArray.mCachedAddressBeforeUpdate + offsetFromStartOfCurrentNodeArray); + } + + /** + * Get the offset from a position inside a current node array to a target PtNode, during + * update. + * + * @param currentNodeArray node array containing the PtNode where the offset will be written + * @param offsetFromStartOfCurrentNodeArray offset, in bytes, from the start of currentNodeArray + * @param targetPtNode the target PtNode to get the offset to + * @return the offset to the target PtNode + */ + // TODO: is there any way to factorize this method with the one above? + private static int getOffsetToTargetPtNodeDuringUpdate(final PtNodeArray currentNodeArray, + final int offsetFromStartOfCurrentNodeArray, final PtNode targetPtNode) { + final int oldOffsetBasePoint = currentNodeArray.mCachedAddressBeforeUpdate + + offsetFromStartOfCurrentNodeArray; + final boolean isTargetBeforeCurrent = (targetPtNode.mCachedAddressBeforeUpdate + < oldOffsetBasePoint); + // If the target is before the current node array, then its address has already been + // updated. We can use the AfterUpdate member, and compare it to our own member after + // update. Otherwise, the AfterUpdate member is not updated yet, so we need to use the + // BeforeUpdate member, and of course we have to compare this to our own address before + // update. + if (isTargetBeforeCurrent) { + final int newOffsetBasePoint = currentNodeArray.mCachedAddressAfterUpdate + + offsetFromStartOfCurrentNodeArray; + return targetPtNode.mCachedAddressAfterUpdate - newOffsetBasePoint; + } + return targetPtNode.mCachedAddressBeforeUpdate - oldOffsetBasePoint; + } + + /** + * Computes the actual node array size, based on the cached addresses of the children nodes. + * + * Each node array stores its tentative address. During dictionary address computing, these + * are not final, but they can be used to compute the node array size (the node array size + * depends on the address of the children because the number of bytes necessary to store an + * address depends on its numeric value. The return value indicates whether the node array + * contents (as in, any of the addresses stored in the cache fields) have changed with + * respect to their previous value. + * + * @param ptNodeArray the node array to compute the size of. + * @param dict the dictionary in which the word/attributes are to be found. + * @return false if none of the cached addresses inside the node array changed, true otherwise. + */ + private static boolean computeActualPtNodeArraySize(final PtNodeArray ptNodeArray, + final FusionDictionary dict, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + boolean changed = false; + int size = getPtNodeCountSize(ptNodeArray); + for (PtNode ptNode : ptNodeArray.mData) { + ptNode.mCachedAddressAfterUpdate = ptNodeArray.mCachedAddressAfterUpdate + size; + if (ptNode.mCachedAddressAfterUpdate != ptNode.mCachedAddressBeforeUpdate) { + changed = true; + } + int nodeSize = getNodeHeaderSize(ptNode, codePointToOneByteCodeMap); + if (ptNode.isTerminal()) { + nodeSize += FormatSpec.PTNODE_FREQUENCY_SIZE; + } + if (null != ptNode.mChildren) { + nodeSize += getByteSize(getOffsetToTargetNodeArrayDuringUpdate(ptNodeArray, + nodeSize + size, ptNode.mChildren)); + } + if (null != ptNode.mBigrams) { + for (WeightedString bigram : ptNode.mBigrams) { + final int offset = getOffsetToTargetPtNodeDuringUpdate(ptNodeArray, + nodeSize + size + FormatSpec.PTNODE_ATTRIBUTE_FLAGS_SIZE, + FusionDictionary.findWordInTree(dict.mRootNodeArray, bigram.mWord)); + nodeSize += getByteSize(offset) + FormatSpec.PTNODE_ATTRIBUTE_FLAGS_SIZE; + } + } + ptNode.mCachedSize = nodeSize; + size += nodeSize; + } + if (ptNodeArray.mCachedSize != size) { + ptNodeArray.mCachedSize = size; + changed = true; + } + return changed; + } + + /** + * Initializes the cached addresses of node arrays and their containing nodes from their size. + * + * @param flatNodes the list of node arrays. + * @return the byte size of the entire stack. + */ + private static int initializePtNodeArraysCachedAddresses( + final ArrayList<PtNodeArray> flatNodes) { + int nodeArrayOffset = 0; + for (final PtNodeArray nodeArray : flatNodes) { + nodeArray.mCachedAddressBeforeUpdate = nodeArrayOffset; + int nodeCountSize = getPtNodeCountSize(nodeArray); + int nodeffset = 0; + for (final PtNode ptNode : nodeArray.mData) { + ptNode.mCachedAddressBeforeUpdate = ptNode.mCachedAddressAfterUpdate = + nodeCountSize + nodeArrayOffset + nodeffset; + nodeffset += ptNode.mCachedSize; + } + nodeArrayOffset += nodeArray.mCachedSize; + } + return nodeArrayOffset; + } + + /** + * Updates the cached addresses of node arrays after recomputing their new positions. + * + * @param flatNodes the list of node arrays. + */ + private static void updatePtNodeArraysCachedAddresses(final ArrayList<PtNodeArray> flatNodes) { + for (final PtNodeArray nodeArray : flatNodes) { + nodeArray.mCachedAddressBeforeUpdate = nodeArray.mCachedAddressAfterUpdate; + for (final PtNode ptNode : nodeArray.mData) { + ptNode.mCachedAddressBeforeUpdate = ptNode.mCachedAddressAfterUpdate; + } + } + } + + /** + * Compute the addresses and sizes of an ordered list of PtNode arrays. + * + * This method takes a list of PtNode arrays and will update their cached address and size + * values so that they can be written into a file. It determines the smallest size each of the + * PtNode arrays can be given the addresses of its children and attributes, and store that into + * each PtNode. + * The order of the PtNode is given by the order of the array. This method makes no effort + * to find a good order; it only mechanically computes the size this order results in. + * + * @param dict the dictionary + * @param flatNodes the ordered list of PtNode arrays + * @return the same array it was passed. The nodes have been updated for address and size. + */ + /* package */ static ArrayList<PtNodeArray> computeAddresses(final FusionDictionary dict, + final ArrayList<PtNodeArray> flatNodes, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + // First get the worst possible sizes and offsets + for (final PtNodeArray n : flatNodes) { + calculatePtNodeArrayMaximumSize(n, codePointToOneByteCodeMap); + } + final int offset = initializePtNodeArraysCachedAddresses(flatNodes); + + MakedictLog.i("Compressing the array addresses. Original size : " + offset); + MakedictLog.i("(Recursively seen size : " + offset + ")"); + + int passes = 0; + boolean changesDone = false; + do { + changesDone = false; + int ptNodeArrayStartOffset = 0; + for (final PtNodeArray ptNodeArray : flatNodes) { + ptNodeArray.mCachedAddressAfterUpdate = ptNodeArrayStartOffset; + final int oldNodeArraySize = ptNodeArray.mCachedSize; + final boolean changed = computeActualPtNodeArraySize(ptNodeArray, dict, + codePointToOneByteCodeMap); + final int newNodeArraySize = ptNodeArray.mCachedSize; + if (oldNodeArraySize < newNodeArraySize) { + throw new RuntimeException("Increased size ?!"); + } + ptNodeArrayStartOffset += newNodeArraySize; + changesDone |= changed; + } + updatePtNodeArraysCachedAddresses(flatNodes); + ++passes; + if (passes > MAX_PASSES) throw new RuntimeException("Too many passes - probably a bug"); + } while (changesDone); + + final PtNodeArray lastPtNodeArray = flatNodes.get(flatNodes.size() - 1); + MakedictLog.i("Compression complete in " + passes + " passes."); + MakedictLog.i("After address compression : " + + (lastPtNodeArray.mCachedAddressAfterUpdate + lastPtNodeArray.mCachedSize)); + + return flatNodes; + } + + /** + * Validity-checking method. + * + * This method checks a list of PtNode arrays for juxtaposition, that is, it will do + * nothing if each node array's cached address is actually the previous node array's address + * plus the previous node's size. + * If this is not the case, it will throw an exception. + * + * @param arrays the list of node arrays to check + */ + /* package */ static void checkFlatPtNodeArrayList(final ArrayList<PtNodeArray> arrays) { + int offset = 0; + int index = 0; + for (final PtNodeArray ptNodeArray : arrays) { + // BeforeUpdate and AfterUpdate addresses are the same here, so it does not matter + // which we use. + if (ptNodeArray.mCachedAddressAfterUpdate != offset) { + throw new RuntimeException("Wrong address for node " + index + + " : expected " + offset + ", got " + + ptNodeArray.mCachedAddressAfterUpdate); + } + ++index; + offset += ptNodeArray.mCachedSize; + } + } + + /** + * Helper method to write a children position to a file. + * + * @param buffer the buffer to write to. + * @param fromIndex the index in the buffer to write the address to. + * @param position the position to write. + * @return the size in bytes the address actually took. + */ + /* package */ static int writeChildrenPosition(final byte[] buffer, final int fromIndex, + final int position) { + int index = fromIndex; + switch (getByteSize(position)) { + case 1: + buffer[index++] = (byte)position; + return 1; + case 2: + buffer[index++] = (byte)(0xFF & (position >> 8)); + buffer[index++] = (byte)(0xFF & position); + return 2; + case 3: + buffer[index++] = (byte)(0xFF & (position >> 16)); + buffer[index++] = (byte)(0xFF & (position >> 8)); + buffer[index++] = (byte)(0xFF & position); + return 3; + case 0: + return 0; + default: + throw new RuntimeException("Position " + position + " has a strange size"); + } + } + + /** + * Makes the flag value for a PtNode. + * + * @param hasMultipleChars whether the PtNode has multiple chars. + * @param isTerminal whether the PtNode is terminal. + * @param childrenAddressSize the size of a children address. + * @param hasBigrams whether the PtNode has bigrams. + * @param isNotAWord whether the PtNode is not a word. + * @param isPossiblyOffensive whether the PtNode is a possibly offensive entry. + * @return the flags + */ + static int makePtNodeFlags(final boolean hasMultipleChars, final boolean isTerminal, + final int childrenAddressSize, final boolean hasBigrams, + final boolean isNotAWord, final boolean isPossiblyOffensive) { + byte flags = 0; + if (hasMultipleChars) flags |= FormatSpec.FLAG_HAS_MULTIPLE_CHARS; + if (isTerminal) flags |= FormatSpec.FLAG_IS_TERMINAL; + switch (childrenAddressSize) { + case 1: + flags |= FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_ONEBYTE; + break; + case 2: + flags |= FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_TWOBYTES; + break; + case 3: + flags |= FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_THREEBYTES; + break; + case 0: + flags |= FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_NOADDRESS; + break; + default: + throw new RuntimeException("Node with a strange address"); + } + if (hasBigrams) flags |= FormatSpec.FLAG_HAS_BIGRAMS; + if (isNotAWord) flags |= FormatSpec.FLAG_IS_NOT_A_WORD; + if (isPossiblyOffensive) flags |= FormatSpec.FLAG_IS_POSSIBLY_OFFENSIVE; + return flags; + } + + /* package */ static byte makePtNodeFlags(final PtNode node, final int childrenOffset) { + return (byte) makePtNodeFlags(node.mChars.length > 1, node.isTerminal(), + getByteSize(childrenOffset), + node.mBigrams != null && !node.mBigrams.isEmpty(), + node.mIsNotAWord, node.mIsPossiblyOffensive); + } + + /** + * Makes the flag value for a bigram. + * + * @param more whether there are more bigrams after this one. + * @param offset the offset of the bigram. + * @param bigramFrequency the frequency of the bigram, 0..255. + * @param unigramFrequency the unigram frequency of the same word, 0..255. + * @param word the second bigram, for debugging purposes + * @return the flags + */ + /* package */ static int makeBigramFlags(final boolean more, final int offset, + final int bigramFrequency, final int unigramFrequency, final String word) { + int bigramFlags = (more ? FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_HAS_NEXT : 0) + + (offset < 0 ? FormatSpec.FLAG_BIGRAM_ATTR_OFFSET_NEGATIVE : 0); + switch (getByteSize(offset)) { + case 1: + bigramFlags |= FormatSpec.FLAG_BIGRAM_ATTR_ADDRESS_TYPE_ONEBYTE; + break; + case 2: + bigramFlags |= FormatSpec.FLAG_BIGRAM_ATTR_ADDRESS_TYPE_TWOBYTES; + break; + case 3: + bigramFlags |= FormatSpec.FLAG_BIGRAM_ATTR_ADDRESS_TYPE_THREEBYTES; + break; + default: + throw new RuntimeException("Strange offset size"); + } + final int frequency; + if (unigramFrequency > bigramFrequency) { + MakedictLog.e("Unigram freq is superior to bigram freq for \"" + word + + "\". Bigram freq is " + bigramFrequency + ", unigram freq for " + + word + " is " + unigramFrequency); + frequency = unigramFrequency; + } else { + frequency = bigramFrequency; + } + bigramFlags += getBigramFrequencyDiff(unigramFrequency, frequency) + & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_FREQUENCY; + return bigramFlags; + } + + public static int getBigramFrequencyDiff(final int unigramFrequency, + final int bigramFrequency) { + // We compute the difference between 255 (which means probability = 1) and the + // unigram score. We split this into a number of discrete steps. + // Now, the steps are numbered 0~15; 0 represents an increase of 1 step while 15 + // represents an increase of 16 steps: a value of 15 will be interpreted as the median + // value of the 16th step. In all justice, if the bigram frequency is low enough to be + // rounded below the first step (which means it is less than half a step higher than the + // unigram frequency) then the unigram frequency itself is the best approximation of the + // bigram freq that we could possibly supply, hence we should *not* include this bigram + // in the file at all. + // until this is done, we'll write 0 and slightly overestimate this case. + // In other words, 0 means "between 0.5 step and 1.5 step", 1 means "between 1.5 step + // and 2.5 steps", and 15 means "between 15.5 steps and 16.5 steps". So we want to + // divide our range [unigramFreq..MAX_TERMINAL_FREQUENCY] in 16.5 steps to get the + // step size. Then we compute the start of the first step (the one where value 0 starts) + // by adding half-a-step to the unigramFrequency. From there, we compute the integer + // number of steps to the bigramFrequency. One last thing: we want our steps to include + // their lower bound and exclude their higher bound so we need to have the first step + // start at exactly 1 unit higher than floor(unigramFreq + half a step). + // Note : to reconstruct the score, the dictionary reader will need to divide + // MAX_TERMINAL_FREQUENCY - unigramFreq by 16.5 likewise to get the value of the step, + // and add (discretizedFrequency + 0.5 + 0.5) times this value to get the best + // approximation. (0.5 to get the first step start, and 0.5 to get the middle of the + // step pointed by the discretized frequency. + final float stepSize = + (FormatSpec.MAX_TERMINAL_FREQUENCY - unigramFrequency) + / (1.5f + FormatSpec.MAX_BIGRAM_FREQUENCY); + final float firstStepStart = 1 + unigramFrequency + (stepSize / 2.0f); + final int discretizedFrequency = (int)((bigramFrequency - firstStepStart) / stepSize); + // If the bigram freq is less than half-a-step higher than the unigram freq, we get -1 + // here. The best approximation would be the unigram freq itself, so we should not + // include this bigram in the dictionary. For now, register as 0, and live with the + // small over-estimation that we get in this case. TODO: actually remove this bigram + // if discretizedFrequency < 0. + return discretizedFrequency > 0 ? discretizedFrequency : 0; + } + + /* package */ static int getChildrenPosition(final PtNode ptNode, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + int positionOfChildrenPosField = ptNode.mCachedAddressAfterUpdate + + getNodeHeaderSize(ptNode, codePointToOneByteCodeMap); + if (ptNode.isTerminal()) { + // A terminal node has the frequency. + // If positionOfChildrenPosField is incorrect, we may crash when jumping to the children + // position. + positionOfChildrenPosField += FormatSpec.PTNODE_FREQUENCY_SIZE; + } + return null == ptNode.mChildren ? FormatSpec.NO_CHILDREN_ADDRESS + : ptNode.mChildren.mCachedAddressAfterUpdate - positionOfChildrenPosField; + } + + /** + * Write a PtNodeArray. The PtNodeArray is expected to have its final position cached. + * + * @param dict the dictionary the node array is a part of (for relative offsets). + * @param dictEncoder the dictionary encoder. + * @param ptNodeArray the node array to write. + * @param codePointToOneByteCodeMap the map to convert the code points. + */ + /* package */ static void writePlacedPtNodeArray(final FusionDictionary dict, + final DictEncoder dictEncoder, final PtNodeArray ptNodeArray, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + // TODO: Make the code in common with BinaryDictIOUtils#writePtNode + dictEncoder.setPosition(ptNodeArray.mCachedAddressAfterUpdate); + + final int ptNodeCount = ptNodeArray.mData.size(); + dictEncoder.writePtNodeCount(ptNodeCount); + for (int i = 0; i < ptNodeCount; ++i) { + final PtNode ptNode = ptNodeArray.mData.get(i); + if (dictEncoder.getPosition() != ptNode.mCachedAddressAfterUpdate) { + throw new RuntimeException("Bug: write index is not the same as the cached address " + + "of the node : " + dictEncoder.getPosition() + " <> " + + ptNode.mCachedAddressAfterUpdate); + } + // Validity checks. + if (DBG && ptNode.getProbability() > FormatSpec.MAX_TERMINAL_FREQUENCY) { + throw new RuntimeException("A node has a frequency > " + + FormatSpec.MAX_TERMINAL_FREQUENCY + + " : " + ptNode.mProbabilityInfo.toString()); + } + dictEncoder.writePtNode(ptNode, dict, codePointToOneByteCodeMap); + } + if (dictEncoder.getPosition() != ptNodeArray.mCachedAddressAfterUpdate + + ptNodeArray.mCachedSize) { + throw new RuntimeException("Not the same size : written " + + (dictEncoder.getPosition() - ptNodeArray.mCachedAddressAfterUpdate) + + " bytes from a node that should have " + ptNodeArray.mCachedSize + " bytes"); + } + } + + /** + * Dumps a collection of useful statistics about a list of PtNode arrays. + * + * This prints purely informative stuff, like the total estimated file size, the + * number of PtNode arrays, of PtNodes, the repartition of each address size, etc + * + * @param ptNodeArrays the list of PtNode arrays. + */ + /* package */ static void showStatistics(ArrayList<PtNodeArray> ptNodeArrays) { + int firstTerminalAddress = Integer.MAX_VALUE; + int lastTerminalAddress = Integer.MIN_VALUE; + int size = 0; + int ptNodes = 0; + int maxNodes = 0; + int maxRuns = 0; + for (final PtNodeArray ptNodeArray : ptNodeArrays) { + if (maxNodes < ptNodeArray.mData.size()) maxNodes = ptNodeArray.mData.size(); + for (final PtNode ptNode : ptNodeArray.mData) { + ++ptNodes; + if (ptNode.mChars.length > maxRuns) maxRuns = ptNode.mChars.length; + if (ptNode.isTerminal()) { + if (ptNodeArray.mCachedAddressAfterUpdate < firstTerminalAddress) + firstTerminalAddress = ptNodeArray.mCachedAddressAfterUpdate; + if (ptNodeArray.mCachedAddressAfterUpdate > lastTerminalAddress) + lastTerminalAddress = ptNodeArray.mCachedAddressAfterUpdate; + } + } + if (ptNodeArray.mCachedAddressAfterUpdate + ptNodeArray.mCachedSize > size) { + size = ptNodeArray.mCachedAddressAfterUpdate + ptNodeArray.mCachedSize; + } + } + final int[] ptNodeCounts = new int[maxNodes + 1]; + final int[] runCounts = new int[maxRuns + 1]; + for (final PtNodeArray ptNodeArray : ptNodeArrays) { + ++ptNodeCounts[ptNodeArray.mData.size()]; + for (final PtNode ptNode : ptNodeArray.mData) { + ++runCounts[ptNode.mChars.length]; + } + } + + MakedictLog.i("Statistics:\n" + + " Total file size " + size + "\n" + + " " + ptNodeArrays.size() + " node arrays\n" + + " " + ptNodes + " PtNodes (" + ((float)ptNodes / ptNodeArrays.size()) + + " PtNodes per node)\n" + + " First terminal at " + firstTerminalAddress + "\n" + + " Last terminal at " + lastTerminalAddress + "\n" + + " PtNode stats : max = " + maxNodes); + } + + /** + * Writes a file header to an output stream. + * + * @param destination the stream to write the file header to. + * @param dict the dictionary to write. + * @param formatOptions file format options. + * @param codePointOccurrenceArray code points ordered by occurrence count. + * @return the size of the header. + */ + /* package */ static int writeDictionaryHeader(final OutputStream destination, + final FusionDictionary dict, final FormatOptions formatOptions, + final ArrayList<Entry<Integer, Integer>> codePointOccurrenceArray) + throws IOException, UnsupportedFormatException { + final int version = formatOptions.mVersion; + if ((version >= FormatSpec.MINIMUM_SUPPORTED_STATIC_VERSION && + version <= FormatSpec.MAXIMUM_SUPPORTED_STATIC_VERSION) || ( + version >= FormatSpec.MINIMUM_SUPPORTED_DYNAMIC_VERSION && + version <= FormatSpec.MAXIMUM_SUPPORTED_DYNAMIC_VERSION)) { + // Dictionary is valid + } else { + throw new UnsupportedFormatException("Requested file format version " + version + + ", but this implementation only supports static versions " + + FormatSpec.MINIMUM_SUPPORTED_STATIC_VERSION + " through " + + FormatSpec.MAXIMUM_SUPPORTED_STATIC_VERSION + " and dynamic versions " + + FormatSpec.MINIMUM_SUPPORTED_DYNAMIC_VERSION + " through " + + FormatSpec.MAXIMUM_SUPPORTED_DYNAMIC_VERSION); + } + + ByteArrayOutputStream headerBuffer = new ByteArrayOutputStream(256); + + // The magic number in big-endian order. + // Magic number for all versions. + headerBuffer.write((byte) (0xFF & (FormatSpec.MAGIC_NUMBER >> 24))); + headerBuffer.write((byte) (0xFF & (FormatSpec.MAGIC_NUMBER >> 16))); + headerBuffer.write((byte) (0xFF & (FormatSpec.MAGIC_NUMBER >> 8))); + headerBuffer.write((byte) (0xFF & FormatSpec.MAGIC_NUMBER)); + // Dictionary version. + headerBuffer.write((byte) (0xFF & (version >> 8))); + headerBuffer.write((byte) (0xFF & version)); + + // Options flags + // TODO: Remove this field. + final int options = 0; + headerBuffer.write((byte) (0xFF & (options >> 8))); + headerBuffer.write((byte) (0xFF & options)); + final int headerSizeOffset = headerBuffer.size(); + // Placeholder to be written later with header size. + for (int i = 0; i < 4; ++i) { + headerBuffer.write(0); + } + // Write out the options. + for (final String key : dict.mOptions.mAttributes.keySet()) { + final String value = dict.mOptions.mAttributes.get(key); + CharEncoding.writeString(headerBuffer, key, null); + CharEncoding.writeString(headerBuffer, value, null); + } + // Write out the codePointTable if there is codePointOccurrenceArray. + if (codePointOccurrenceArray != null) { + final String codePointTableString = + encodeCodePointTable(codePointOccurrenceArray); + CharEncoding.writeString(headerBuffer, DictionaryHeader.CODE_POINT_TABLE_KEY, null); + CharEncoding.writeString(headerBuffer, codePointTableString, null); + } + final int size = headerBuffer.size(); + final byte[] bytes = headerBuffer.toByteArray(); + // Write out the header size. + bytes[headerSizeOffset] = (byte) (0xFF & (size >> 24)); + bytes[headerSizeOffset + 1] = (byte) (0xFF & (size >> 16)); + bytes[headerSizeOffset + 2] = (byte) (0xFF & (size >> 8)); + bytes[headerSizeOffset + 3] = (byte) (0xFF & (size >> 0)); + destination.write(bytes); + + headerBuffer.close(); + return size; + } + + static final class CodePointTable { + final HashMap<Integer, Integer> mCodePointToOneByteCodeMap; + final ArrayList<Entry<Integer, Integer>> mCodePointOccurrenceArray; + + // Let code point table empty for version 200 dictionary which used in test + CodePointTable() { + mCodePointToOneByteCodeMap = null; + mCodePointOccurrenceArray = null; + } + + CodePointTable(final HashMap<Integer, Integer> codePointToOneByteCodeMap, + final ArrayList<Entry<Integer, Integer>> codePointOccurrenceArray) { + mCodePointToOneByteCodeMap = codePointToOneByteCodeMap; + mCodePointOccurrenceArray = codePointOccurrenceArray; + } + } + + private static String encodeCodePointTable( + final ArrayList<Entry<Integer, Integer>> codePointOccurrenceArray) { + final StringBuilder codePointTableString = new StringBuilder(); + int currentCodePointTableIndex = FormatSpec.MINIMAL_ONE_BYTE_CHARACTER_VALUE; + for (final Entry<Integer, Integer> entry : codePointOccurrenceArray) { + // Native reads the table as a string + codePointTableString.appendCodePoint(entry.getKey()); + if (FormatSpec.MAXIMAL_ONE_BYTE_CHARACTER_VALUE < ++currentCodePointTableIndex) { + break; + } + } + return codePointTableString.toString(); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictIOUtils.java b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictIOUtils.java new file mode 100644 index 000000000..055d6492d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictIOUtils.java @@ -0,0 +1,292 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; +import org.kelar.inputmethod.latin.define.DecoderSpecificConstants; +import org.kelar.inputmethod.latin.makedict.DictDecoder.DictionaryBufferFactory; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Map; +import java.util.Stack; + +public final class BinaryDictIOUtils { + private static final boolean DBG = false; + + private BinaryDictIOUtils() { + // This utility class is not publicly instantiable. + } + + /** + * Returns new dictionary decoder. + * + * @param dictFile the dictionary file. + * @param bufferType The type of buffer, as one of USE_* in DictDecoder. + * @return new dictionary decoder if the dictionary file exists, otherwise null. + */ + public static DictDecoder getDictDecoder(final File dictFile, final long offset, + final long length, final int bufferType) { + return new Ver4DictDecoder(dictFile); + } + + public static DictDecoder getDictDecoder(final File dictFile, final long offset, + final long length, final DictionaryBufferFactory factory) { + return new Ver4DictDecoder(dictFile); + } + + public static DictDecoder getDictDecoder(final File dictFile, final long offset, + final long length) { + return getDictDecoder(dictFile, offset, length, DictDecoder.USE_READONLY_BYTEBUFFER); + } + + private static final class Position { + public static final int NOT_READ_PTNODE_COUNT = -1; + + public int mAddress; + public int mNumOfPtNode; + public int mPosition; + public int mLength; + + public Position(int address, int length) { + mAddress = address; + mLength = length; + mNumOfPtNode = NOT_READ_PTNODE_COUNT; + } + } + + /** + * Retrieves all node arrays without recursive call. + */ + private static void readUnigramsAndBigramsBinaryInner(final DictDecoder dictDecoder, + final int bodyOffset, final Map<Integer, String> words, + final Map<Integer, Integer> frequencies, + final Map<Integer, ArrayList<PendingAttribute>> bigrams) { + int[] pushedChars = new int[FormatSpec.MAX_WORD_LENGTH + 1]; + + Stack<Position> stack = new Stack<>(); + int index = 0; + + Position initPos = new Position(bodyOffset, 0); + stack.push(initPos); + + while (!stack.empty()) { + Position p = stack.peek(); + + if (DBG) { + MakedictLog.d("read: address=" + p.mAddress + ", numOfPtNode=" + + p.mNumOfPtNode + ", position=" + p.mPosition + ", length=" + p.mLength); + } + + if (dictDecoder.getPosition() != p.mAddress) dictDecoder.setPosition(p.mAddress); + if (index != p.mLength) index = p.mLength; + + if (p.mNumOfPtNode == Position.NOT_READ_PTNODE_COUNT) { + p.mNumOfPtNode = dictDecoder.readPtNodeCount(); + p.mAddress = dictDecoder.getPosition(); + p.mPosition = 0; + } + if (p.mNumOfPtNode == 0) { + stack.pop(); + continue; + } + final PtNodeInfo ptNodeInfo = dictDecoder.readPtNode(p.mAddress); + for (int i = 0; i < ptNodeInfo.mCharacters.length; ++i) { + pushedChars[index++] = ptNodeInfo.mCharacters[i]; + } + p.mPosition++; + if (ptNodeInfo.isTerminal()) {// found word + words.put(ptNodeInfo.mOriginalAddress, new String(pushedChars, 0, index)); + frequencies.put( + ptNodeInfo.mOriginalAddress, ptNodeInfo.mProbabilityInfo.mProbability); + if (ptNodeInfo.mBigrams != null) { + bigrams.put(ptNodeInfo.mOriginalAddress, ptNodeInfo.mBigrams); + } + } + + if (p.mPosition == p.mNumOfPtNode) { + stack.pop(); + } else { + // The PtNode array has more PtNodes. + p.mAddress = dictDecoder.getPosition(); + } + + if (hasChildrenAddress(ptNodeInfo.mChildrenAddress)) { + final Position childrenPos = new Position(ptNodeInfo.mChildrenAddress, index); + stack.push(childrenPos); + } + } + } + + /** + * Reads unigrams and bigrams from the binary file. + * Doesn't store a full memory representation of the dictionary. + * + * @param dictDecoder the dict decoder. + * @param words the map to store the address as a key and the word as a value. + * @param frequencies the map to store the address as a key and the frequency as a value. + * @param bigrams the map to store the address as a key and the list of address as a value. + * @throws IOException if the file can't be read. + * @throws UnsupportedFormatException if the format of the file is not recognized. + */ + /* package */ static void readUnigramsAndBigramsBinary(final DictDecoder dictDecoder, + final Map<Integer, String> words, final Map<Integer, Integer> frequencies, + final Map<Integer, ArrayList<PendingAttribute>> bigrams) throws IOException, + UnsupportedFormatException { + // Read header + final DictionaryHeader header = dictDecoder.readHeader(); + readUnigramsAndBigramsBinaryInner(dictDecoder, header.mBodyOffset, words, + frequencies, bigrams); + } + + /** + * Gets the address of the last PtNode of the exact matching word in the dictionary. + * If no match is found, returns NOT_VALID_WORD. + * + * @param dictDecoder the dict decoder. + * @param word the word we search for. + * @return the address of the terminal node. + * @throws IOException if the file can't be read. + * @throws UnsupportedFormatException if the format of the file is not recognized. + */ + @UsedForTesting + /* package */ static int getTerminalPosition(final DictDecoder dictDecoder, + final String word) throws IOException, UnsupportedFormatException { + if (word == null) return FormatSpec.NOT_VALID_WORD; + dictDecoder.setPosition(0); + dictDecoder.readHeader(); + int wordPos = 0; + final int wordLen = word.codePointCount(0, word.length()); + for (int depth = 0; depth < DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH; ++depth) { + if (wordPos >= wordLen) return FormatSpec.NOT_VALID_WORD; + + do { + final int ptNodeCount = dictDecoder.readPtNodeCount(); + boolean foundNextPtNode = false; + for (int i = 0; i < ptNodeCount; ++i) { + final int ptNodePos = dictDecoder.getPosition(); + final PtNodeInfo currentInfo = dictDecoder.readPtNode(ptNodePos); + boolean same = true; + for (int p = 0, j = word.offsetByCodePoints(0, wordPos); + p < currentInfo.mCharacters.length; + ++p, j = word.offsetByCodePoints(j, 1)) { + if (wordPos + p >= wordLen + || word.codePointAt(j) != currentInfo.mCharacters[p]) { + same = false; + break; + } + } + + if (same) { + // found the PtNode matches the word. + if (wordPos + currentInfo.mCharacters.length == wordLen) { + return currentInfo.isTerminal() ? ptNodePos : FormatSpec.NOT_VALID_WORD; + } + wordPos += currentInfo.mCharacters.length; + if (currentInfo.mChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS) { + return FormatSpec.NOT_VALID_WORD; + } + foundNextPtNode = true; + dictDecoder.setPosition(currentInfo.mChildrenAddress); + break; + } + } + if (foundNextPtNode) break; + return FormatSpec.NOT_VALID_WORD; + } while(true); + } + return FormatSpec.NOT_VALID_WORD; + } + + /** + * Writes a PtNodeCount to the stream. + * + * @param destination the stream to write. + * @param ptNodeCount the count. + * @return the size written in bytes. + */ + @UsedForTesting + static int writePtNodeCount(final OutputStream destination, final int ptNodeCount) + throws IOException { + final int countSize = BinaryDictIOUtils.getPtNodeCountSize(ptNodeCount); + // the count must fit on one byte or two bytes. + // Please see comments in FormatSpec. + if (countSize != 1 && countSize != 2) { + throw new RuntimeException("Strange size from getPtNodeCountSize : " + countSize); + } + final int encodedPtNodeCount = (countSize == 2) ? + (ptNodeCount | FormatSpec.LARGE_PTNODE_ARRAY_SIZE_FIELD_SIZE_FLAG) : ptNodeCount; + BinaryDictEncoderUtils.writeUIntToStream(destination, encodedPtNodeCount, countSize); + return countSize; + } + + /** + * Helper method to hide the actual value of the no children address. + */ + public static boolean hasChildrenAddress(final int address) { + return FormatSpec.NO_CHILDREN_ADDRESS != address; + } + + /** + * Compute the binary size of the node count + * @param count the node count + * @return the size of the node count, either 1 or 2 bytes. + */ + public static int getPtNodeCountSize(final int count) { + if (FormatSpec.MAX_PTNODES_FOR_ONE_BYTE_PTNODE_COUNT >= count) { + return 1; + } else if (FormatSpec.MAX_PTNODES_IN_A_PT_NODE_ARRAY >= count) { + return 2; + } else { + throw new RuntimeException("Can't have more than " + + FormatSpec.MAX_PTNODES_IN_A_PT_NODE_ARRAY + " PtNode in a PtNodeArray (found " + + count + ")"); + } + } + + static int getChildrenAddressSize(final int optionFlags) { + switch (optionFlags & FormatSpec.MASK_CHILDREN_ADDRESS_TYPE) { + case FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_ONEBYTE: + return 1; + case FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_TWOBYTES: + return 2; + case FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_THREEBYTES: + return 3; + case FormatSpec.FLAG_CHILDREN_ADDRESS_TYPE_NOADDRESS: + default: + return 0; + } + } + + /** + * Calculate bigram frequency from compressed value + * + * @param unigramFrequency + * @param bigramFrequency compressed frequency + * @return approximate bigram frequency + */ + @UsedForTesting + public static int reconstructBigramFrequency(final int unigramFrequency, + final int bigramFrequency) { + final float stepSize = (FormatSpec.MAX_TERMINAL_FREQUENCY - unigramFrequency) + / (1.5f + FormatSpec.MAX_BIGRAM_FREQUENCY); + final float resultFreqFloat = unigramFrequency + stepSize * (bigramFrequency + 1.0f); + return (int)resultFreqFloat; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictUtils.java b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictUtils.java new file mode 100644 index 000000000..48e3d95f2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/BinaryDictUtils.java @@ -0,0 +1,80 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.latin.makedict.FormatSpec.DictionaryOptions; +import org.kelar.inputmethod.latin.makedict.FormatSpec.FormatOptions; + +import java.io.File; +import java.util.HashMap; + +public class BinaryDictUtils { + public static final int USE_BYTE_ARRAY = 1; + public static final int USE_BYTE_BUFFER = 2; + + public static final String TEST_DICT_FILE_EXTENSION = ".testDict"; + + public static final FormatSpec.FormatOptions STATIC_OPTIONS = + new FormatSpec.FormatOptions(FormatSpec.VERSION202); + public static final FormatSpec.FormatOptions DYNAMIC_OPTIONS_WITHOUT_TIMESTAMP = + new FormatSpec.FormatOptions(FormatSpec.VERSION4, false /* hasTimestamp */); + public static final FormatSpec.FormatOptions DYNAMIC_OPTIONS_WITH_TIMESTAMP = + new FormatSpec.FormatOptions(FormatSpec.VERSION4, true /* hasTimestamp */); + + public static DictionaryOptions makeDictionaryOptions(final String id, final String version, + final FormatSpec.FormatOptions formatOptions) { + final DictionaryOptions options = new DictionaryOptions(new HashMap<String, String>()); + options.mAttributes.put(DictionaryHeader.DICTIONARY_LOCALE_KEY, "en_US"); + options.mAttributes.put(DictionaryHeader.DICTIONARY_ID_KEY, id); + options.mAttributes.put(DictionaryHeader.DICTIONARY_VERSION_KEY, version); + if (formatOptions.mHasTimestamp) { + options.mAttributes.put(DictionaryHeader.HAS_HISTORICAL_INFO_KEY, + DictionaryHeader.ATTRIBUTE_VALUE_TRUE); + options.mAttributes.put(DictionaryHeader.USES_FORGETTING_CURVE_KEY, + DictionaryHeader.ATTRIBUTE_VALUE_TRUE); + } + return options; + } + + public static File getDictFile(final String name, final String version, + final FormatOptions formatOptions, final File directory) { + if (formatOptions.mVersion == FormatSpec.VERSION2 + || formatOptions.mVersion == FormatSpec.VERSION201 + || formatOptions.mVersion == FormatSpec.VERSION202) { + return new File(directory, name + "." + version + TEST_DICT_FILE_EXTENSION); + } else if (formatOptions.mVersion == FormatSpec.VERSION4) { + return new File(directory, name + "." + version); + } else { + throw new RuntimeException("the format option has a wrong version : " + + formatOptions.mVersion); + } + } + + public static DictEncoder getDictEncoder(final File file, final FormatOptions formatOptions) { + if (formatOptions.mVersion == FormatSpec.VERSION4) { + if (!file.isDirectory()) { + file.mkdir(); + } + return new Ver4DictEncoder(file); + } else if (formatOptions.mVersion == FormatSpec.VERSION202) { + return new Ver2DictEncoder(file, Ver2DictEncoder.CODE_POINT_TABLE_OFF); + } else { + throw new RuntimeException("The format option has a wrong version : " + + formatOptions.mVersion); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/DictDecoder.java b/tests/src/org/kelar/inputmethod/latin/makedict/DictDecoder.java new file mode 100644 index 000000000..97fb3596b --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/DictDecoder.java @@ -0,0 +1,222 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; +import org.kelar.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; +import org.kelar.inputmethod.latin.utils.ByteArrayDictBuffer; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.TreeMap; + +/** + * An interface of binary dictionary decoders. + */ +// TODO: Straighten out responsibility for the buffer's file pointer. +public interface DictDecoder { + + /** + * Reads and returns the file header. + */ + public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException; + + /** + * Reads PtNode from ptNodePos. + * @param ptNodePos the position of PtNode. + * @return PtNodeInfo. + */ + public PtNodeInfo readPtNode(final int ptNodePos); + + /** + * Reads a buffer and returns the memory representation of the dictionary. + * + * This high-level method takes a buffer and reads its contents, populating a + * FusionDictionary structure. + * + * @param deleteDictIfBroken a flag indicating whether this method should remove the broken + * dictionary or not. + * @return the created dictionary. + */ + @UsedForTesting + public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken) + throws FileNotFoundException, IOException, UnsupportedFormatException; + + /** + * Gets the address of the last PtNode of the exact matching word in the dictionary. + * If no match is found, returns NOT_VALID_WORD. + * + * @param word the word we search for. + * @return the address of the terminal node. + * @throws IOException if the file can't be read. + * @throws UnsupportedFormatException if the format of the file is not recognized. + */ + @UsedForTesting + public int getTerminalPosition(final String word) + throws IOException, UnsupportedFormatException; + + /** + * Reads unigrams and bigrams from the binary file. + * Doesn't store a full memory representation of the dictionary. + * + * @param words the map to store the address as a key and the word as a value. + * @param frequencies the map to store the address as a key and the frequency as a value. + * @param bigrams the map to store the address as a key and the list of address as a value. + * @throws IOException if the file can't be read. + * @throws UnsupportedFormatException if the format of the file is not recognized. + */ + @UsedForTesting + public void readUnigramsAndBigramsBinary(final TreeMap<Integer, String> words, + final TreeMap<Integer, Integer> frequencies, + final TreeMap<Integer, ArrayList<PendingAttribute>> bigrams) + throws IOException, UnsupportedFormatException; + + /** + * Sets the position of the buffer to the given value. + * + * @param newPos the new position + */ + public void setPosition(final int newPos); + + /** + * Gets the position of the buffer. + * + * @return the position + */ + public int getPosition(); + + /** + * Reads and returns the PtNode count out of a buffer and forwards the pointer. + */ + public int readPtNodeCount(); + + /** + * Opens the dictionary file and makes DictBuffer. + */ + @UsedForTesting + public void openDictBuffer() throws FileNotFoundException, IOException, + UnsupportedFormatException; + @UsedForTesting + public boolean isDictBufferOpen(); + + // Constants for DictionaryBufferFactory. + public static final int USE_READONLY_BYTEBUFFER = 0x01000000; + public static final int USE_BYTEARRAY = 0x02000000; + public static final int USE_WRITABLE_BYTEBUFFER = 0x03000000; + public static final int MASK_DICTBUFFER = 0x0F000000; + + public interface DictionaryBufferFactory { + public DictBuffer getDictionaryBuffer(final File file) + throws FileNotFoundException, IOException; + } + + /** + * Creates DictionaryBuffer using a ByteBuffer + * + * This class uses less memory than DictionaryBufferFromByteArrayFactory, + * but doesn't perform as fast. + * When operating on a big dictionary, this class is preferred. + */ + public static final class DictionaryBufferFromReadOnlyByteBufferFactory + implements DictionaryBufferFactory { + @Override + public DictBuffer getDictionaryBuffer(final File file) + throws FileNotFoundException, IOException { + FileInputStream inStream = null; + ByteBuffer buffer = null; + try { + inStream = new FileInputStream(file); + buffer = inStream.getChannel().map(FileChannel.MapMode.READ_ONLY, + 0, file.length()); + } finally { + if (inStream != null) { + inStream.close(); + } + } + if (buffer != null) { + return new BinaryDictDecoderUtils.ByteBufferDictBuffer(buffer); + } + return null; + } + } + + /** + * Creates DictionaryBuffer using a byte array + * + * This class performs faster than other classes, but consumes more memory. + * When operating on a small dictionary, this class is preferred. + */ + public static final class DictionaryBufferFromByteArrayFactory + implements DictionaryBufferFactory { + @Override + public DictBuffer getDictionaryBuffer(final File file) + throws FileNotFoundException, IOException { + FileInputStream inStream = null; + try { + inStream = new FileInputStream(file); + final byte[] array = new byte[(int) file.length()]; + inStream.read(array); + return new ByteArrayDictBuffer(array); + } finally { + if (inStream != null) { + inStream.close(); + } + } + } + } + + /** + * Creates DictionaryBuffer using a writable ByteBuffer and a RandomAccessFile. + * + * This class doesn't perform as fast as other classes, + * but this class is the only option available for destructive operations (insert or delete) + * on a dictionary. + */ + @UsedForTesting + public static final class DictionaryBufferFromWritableByteBufferFactory + implements DictionaryBufferFactory { + @Override + public DictBuffer getDictionaryBuffer(final File file) + throws FileNotFoundException, IOException { + RandomAccessFile raFile = null; + ByteBuffer buffer = null; + try { + raFile = new RandomAccessFile(file, "rw"); + buffer = raFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, file.length()); + } finally { + if (raFile != null) { + raFile.close(); + } + } + if (buffer != null) { + return new BinaryDictDecoderUtils.ByteBufferDictBuffer(buffer); + } + return null; + } + } + + /** + * @return whether this decoder has a valid binary dictionary that it can decode. + */ + public boolean hasValidRawBinaryDictionary(); +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/DictEncoder.java b/tests/src/org/kelar/inputmethod/latin/makedict/DictEncoder.java new file mode 100644 index 000000000..d637b6d2a --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/DictEncoder.java @@ -0,0 +1,39 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; +import org.kelar.inputmethod.latin.makedict.FormatSpec.FormatOptions; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNode; + +import java.io.IOException; +import java.util.HashMap; + +/** + * An interface of binary dictionary encoder. + */ +public interface DictEncoder { + @UsedForTesting + public void writeDictionary(final FusionDictionary dict, final FormatOptions formatOptions) + throws IOException, UnsupportedFormatException; + + public void setPosition(final int position); + public int getPosition(); + public void writePtNodeCount(final int ptNodeCount); + public void writePtNode(final PtNode ptNode, final FusionDictionary dict, + final HashMap<Integer, Integer> codePointToOneByteCodeMap); +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/FusionDictionary.java b/tests/src/org/kelar/inputmethod/latin/makedict/FusionDictionary.java new file mode 100644 index 000000000..817d69f99 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/FusionDictionary.java @@ -0,0 +1,646 @@ +/* + * Copyright (C) 2011 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; +import org.kelar.inputmethod.latin.define.DecoderSpecificConstants; +import org.kelar.inputmethod.latin.makedict.FormatSpec.DictionaryOptions; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; + +/** + * A dictionary that can fusion heads and tails of words for more compression. + */ +@UsedForTesting +public final class FusionDictionary implements Iterable<WordProperty> { + private static final boolean DBG = MakedictLog.DBG; + + private static int CHARACTER_NOT_FOUND_INDEX = -1; + + /** + * A node array of the dictionary, containing several PtNodes. + * + * A PtNodeArray is but an ordered array of PtNodes, which essentially contain all the + * real information. + * This class also contains fields to cache size and address, to help with binary + * generation. + */ + public static final class PtNodeArray { + ArrayList<PtNode> mData; + // To help with binary generation + int mCachedSize = Integer.MIN_VALUE; + // mCachedAddressBefore/AfterUpdate are helpers for binary dictionary generation. They + // always hold the same value except between dictionary address compression, during which + // the update process needs to know about both values at the same time. Updating will + // update the AfterUpdate value, and the code will move them to BeforeUpdate before + // the next update pass. + int mCachedAddressBeforeUpdate = Integer.MIN_VALUE; + int mCachedAddressAfterUpdate = Integer.MIN_VALUE; + int mCachedParentAddress = 0; + + public PtNodeArray() { + mData = new ArrayList<>(); + } + public PtNodeArray(ArrayList<PtNode> data) { + Collections.sort(data, PTNODE_COMPARATOR); + mData = data; + } + } + + /** + * PtNode is a group of characters, with probability information, shortcut targets, bigrams, + * and children (Pt means Patricia Trie). + * + * This is the central class of the in-memory representation. A PtNode is what can + * be seen as a traditional "trie node", except it can hold several characters at the + * same time. A PtNode essentially represents one or several characters in the middle + * of the trie tree; as such, it can be a terminal, and it can have children. + * In this in-memory representation, whether the PtNode is a terminal or not is represented + * by mProbabilityInfo. The PtNode is a terminal when the mProbabilityInfo is not null and the + * PtNode is not a terminal when the mProbabilityInfo is null. A terminal may have non-null + * shortcuts and/or bigrams, but a non-terminal may not. Moreover, children, if present, + * are non-null. + */ + public static final class PtNode { + private static final int NOT_A_TERMINAL = -1; + final int mChars[]; + ArrayList<WeightedString> mBigrams; + // null == mProbabilityInfo indicates this is not a terminal. + ProbabilityInfo mProbabilityInfo; + int mTerminalId; // NOT_A_TERMINAL == mTerminalId indicates this is not a terminal. + PtNodeArray mChildren; + boolean mIsNotAWord; // Only a shortcut + boolean mIsPossiblyOffensive; + // mCachedSize and mCachedAddressBefore/AfterUpdate are helpers for binary dictionary + // generation. Before and After always hold the same value except during dictionary + // address compression, where the update process needs to know about both values at the + // same time. Updating will update the AfterUpdate value, and the code will move them + // to BeforeUpdate before the next update pass. + // The update process does not need two versions of mCachedSize. + int mCachedSize; // The size, in bytes, of this PtNode. + int mCachedAddressBeforeUpdate; // The address of this PtNode (before update) + int mCachedAddressAfterUpdate; // The address of this PtNode (after update) + + public PtNode(final int[] chars, final ArrayList<WeightedString> bigrams, + final ProbabilityInfo probabilityInfo, final boolean isNotAWord, + final boolean isPossiblyOffensive) { + mChars = chars; + mProbabilityInfo = probabilityInfo; + mTerminalId = probabilityInfo == null ? NOT_A_TERMINAL : probabilityInfo.mProbability; + mBigrams = bigrams; + mChildren = null; + mIsNotAWord = isNotAWord; + mIsPossiblyOffensive = isPossiblyOffensive; + } + + public PtNode(final int[] chars, final ArrayList<WeightedString> bigrams, + final ProbabilityInfo probabilityInfo, final boolean isNotAWord, + final boolean isPossiblyOffensive, final PtNodeArray children) { + mChars = chars; + mProbabilityInfo = probabilityInfo; + mBigrams = bigrams; + mChildren = children; + mIsNotAWord = isNotAWord; + mIsPossiblyOffensive = isPossiblyOffensive; + } + + public void addChild(PtNode n) { + if (null == mChildren) { + mChildren = new PtNodeArray(); + } + mChildren.mData.add(n); + } + + public int getTerminalId() { + return mTerminalId; + } + + public boolean isTerminal() { + return mProbabilityInfo != null; + } + + public int getProbability() { + return isTerminal() ? mProbabilityInfo.mProbability : NOT_A_TERMINAL; + } + + public boolean getIsNotAWord() { + return mIsNotAWord; + } + + public boolean getIsPossiblyOffensive() { + return mIsPossiblyOffensive; + } + + public ArrayList<WeightedString> getBigrams() { + // We don't want write permission to escape outside the package, so we return a copy + if (null == mBigrams) return null; + final ArrayList<WeightedString> copyOfBigrams = new ArrayList<>(mBigrams); + return copyOfBigrams; + } + + public boolean hasSeveralChars() { + assert(mChars.length > 0); + return 1 < mChars.length; + } + + /** + * Adds a word to the bigram list. Updates the probability information if the word already + * exists. + */ + public void addBigram(final String word, final ProbabilityInfo probabilityInfo) { + if (mBigrams == null) { + mBigrams = new ArrayList<>(); + } + WeightedString bigram = getBigram(word); + if (bigram != null) { + bigram.mProbabilityInfo = probabilityInfo; + } else { + bigram = new WeightedString(word, probabilityInfo); + mBigrams.add(bigram); + } + } + + /** + * Gets the bigram for the given word. + * Returns null if the word is not in the bigrams list. + */ + public WeightedString getBigram(final String word) { + // TODO: Don't do a linear search + if (mBigrams != null) { + final int size = mBigrams.size(); + for (int i = 0; i < size; ++i) { + WeightedString bigram = mBigrams.get(i); + if (bigram.mWord.equals(word)) { + return bigram; + } + } + } + return null; + } + + /** + * Updates the PtNode with the given properties. Adds the shortcut and bigram lists to + * the existing ones if any. Note: unigram, bigram, and shortcut frequencies are only + * updated if they are higher than the existing ones. + */ + void update(final ProbabilityInfo probabilityInfo, + final ArrayList<WeightedString> bigrams, + final boolean isNotAWord, final boolean isPossiblyOffensive) { + mProbabilityInfo = ProbabilityInfo.max(mProbabilityInfo, probabilityInfo); + if (bigrams != null) { + if (mBigrams == null) { + mBigrams = bigrams; + } else { + final int size = bigrams.size(); + for (int i = 0; i < size; ++i) { + final WeightedString bigram = bigrams.get(i); + final WeightedString existingBigram = getBigram(bigram.mWord); + if (existingBigram == null) { + mBigrams.add(bigram); + } else { + existingBigram.mProbabilityInfo = ProbabilityInfo.max( + existingBigram.mProbabilityInfo, bigram.mProbabilityInfo); + } + } + } + } + mIsNotAWord = isNotAWord; + mIsPossiblyOffensive = isPossiblyOffensive; + } + } + + public final DictionaryOptions mOptions; + public final PtNodeArray mRootNodeArray; + + public FusionDictionary(final PtNodeArray rootNodeArray, final DictionaryOptions options) { + mRootNodeArray = rootNodeArray; + mOptions = options; + } + + public void addOptionAttribute(final String key, final String value) { + mOptions.mAttributes.put(key, value); + } + + /** + * Helper method to convert a String to an int array. + */ + static int[] getCodePoints(final String word) { + // TODO: this is a copy-paste of the old contents of StringUtils.toCodePointArray, + // which is not visible from the makedict package. Factor this code. + final int length = word.length(); + if (length <= 0) return new int[] {}; + final char[] characters = word.toCharArray(); + final int[] codePoints = new int[Character.codePointCount(characters, 0, length)]; + int codePoint = Character.codePointAt(characters, 0); + int dsti = 0; + for (int srci = Character.charCount(codePoint); + srci < length; srci += Character.charCount(codePoint), ++dsti) { + codePoints[dsti] = codePoint; + codePoint = Character.codePointAt(characters, srci); + } + codePoints[dsti] = codePoint; + return codePoints; + } + + /** + * Helper method to add a word as a string. + * + * This method adds a word to the dictionary with the given frequency. Optional + * lists of bigrams can be passed here. For each word inside, + * they will be added to the dictionary as necessary. + * @param word the word to add. + * @param probabilityInfo probability information of the word. + * @param isNotAWord true if this should not be considered a word (e.g. shortcut only) + * @param isPossiblyOffensive true if this word is possibly offensive + */ + public void add(final String word, final ProbabilityInfo probabilityInfo, + final boolean isNotAWord, final boolean isPossiblyOffensive) { + add(getCodePoints(word), probabilityInfo, isNotAWord, isPossiblyOffensive); + } + + /** + * Validity check for a PtNode array. + * + * This method checks that all PtNodes in a node array are ordered as expected. + * If they are, nothing happens. If they aren't, an exception is thrown. + */ + private static void checkStack(PtNodeArray ptNodeArray) { + ArrayList<PtNode> stack = ptNodeArray.mData; + int lastValue = -1; + for (int i = 0; i < stack.size(); ++i) { + int currentValue = stack.get(i).mChars[0]; + if (currentValue <= lastValue) { + throw new RuntimeException("Invalid stack"); + } + lastValue = currentValue; + } + } + + /** + * Helper method to add a new bigram to the dictionary. + * + * @param word0 the previous word of the context + * @param word1 the next word of the context + * @param probabilityInfo the bigram probability info + */ + public void setBigram(final String word0, final String word1, + final ProbabilityInfo probabilityInfo) { + PtNode ptNode0 = findWordInTree(mRootNodeArray, word0); + if (ptNode0 != null) { + final PtNode ptNode1 = findWordInTree(mRootNodeArray, word1); + if (ptNode1 == null) { + add(getCodePoints(word1), new ProbabilityInfo(0), false /* isNotAWord */, + false /* isPossiblyOffensive */); + // The PtNode for the first word may have moved by the above insertion, + // if word1 and word2 share a common stem that happens not to have been + // a cutting point until now. In this case, we need to refresh ptNode. + ptNode0 = findWordInTree(mRootNodeArray, word0); + } + ptNode0.addBigram(word1, probabilityInfo); + } else { + throw new RuntimeException("First word of bigram not found " + word0); + } + } + + /** + * Add a word to this dictionary. + * + * The shortcuts, if any, have to be in the dictionary already. If they aren't, + * an exception is thrown. + * @param word the word, as an int array. + * @param probabilityInfo the probability information of the word. + * @param isNotAWord true if this is not a word for spellchecking purposes (shortcut only or so) + * @param isPossiblyOffensive true if this word is possibly offensive + */ + private void add(final int[] word, final ProbabilityInfo probabilityInfo, + final boolean isNotAWord, final boolean isPossiblyOffensive) { + assert(probabilityInfo.mProbability <= FormatSpec.MAX_TERMINAL_FREQUENCY); + if (word.length >= DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH) { + MakedictLog.w("Ignoring a word that is too long: word.length = " + word.length); + return; + } + + PtNodeArray currentNodeArray = mRootNodeArray; + int charIndex = 0; + + PtNode currentPtNode = null; + int differentCharIndex = 0; // Set by the loop to the index of the char that differs + int nodeIndex = findIndexOfChar(mRootNodeArray, word[charIndex]); + while (CHARACTER_NOT_FOUND_INDEX != nodeIndex) { + currentPtNode = currentNodeArray.mData.get(nodeIndex); + differentCharIndex = compareCharArrays(currentPtNode.mChars, word, charIndex); + if (ARRAYS_ARE_EQUAL != differentCharIndex + && differentCharIndex < currentPtNode.mChars.length) break; + if (null == currentPtNode.mChildren) break; + charIndex += currentPtNode.mChars.length; + if (charIndex >= word.length) break; + currentNodeArray = currentPtNode.mChildren; + nodeIndex = findIndexOfChar(currentNodeArray, word[charIndex]); + } + + if (CHARACTER_NOT_FOUND_INDEX == nodeIndex) { + // No node at this point to accept the word. Create one. + final int insertionIndex = findInsertionIndex(currentNodeArray, word[charIndex]); + final PtNode newPtNode = new PtNode(Arrays.copyOfRange(word, charIndex, word.length), + null /* bigrams */, probabilityInfo, isNotAWord, + isPossiblyOffensive); + currentNodeArray.mData.add(insertionIndex, newPtNode); + if (DBG) checkStack(currentNodeArray); + } else { + // There is a word with a common prefix. + if (differentCharIndex == currentPtNode.mChars.length) { + if (charIndex + differentCharIndex >= word.length) { + // The new word is a prefix of an existing word, but the node on which it + // should end already exists as is. Since the old PtNode was not a terminal, + // make it one by filling in its frequency and other attributes + currentPtNode.update(probabilityInfo, null, isNotAWord, + isPossiblyOffensive); + } else { + // The new word matches the full old word and extends past it. + // We only have to create a new node and add it to the end of this. + final PtNode newNode = new PtNode( + Arrays.copyOfRange(word, charIndex + differentCharIndex, word.length), + null /* bigrams */, probabilityInfo, + isNotAWord, isPossiblyOffensive); + currentPtNode.mChildren = new PtNodeArray(); + currentPtNode.mChildren.mData.add(newNode); + } + } else { + if (0 == differentCharIndex) { + // Exact same word. Update the frequency if higher. This will also add the + // new shortcuts to the existing shortcut list if it already exists. + currentPtNode.update(probabilityInfo, null, + currentPtNode.mIsNotAWord && isNotAWord, + currentPtNode.mIsPossiblyOffensive || isPossiblyOffensive); + } else { + // Partial prefix match only. We have to replace the current node with a node + // containing the current prefix and create two new ones for the tails. + PtNodeArray newChildren = new PtNodeArray(); + final PtNode newOldWord = new PtNode( + Arrays.copyOfRange(currentPtNode.mChars, differentCharIndex, + currentPtNode.mChars.length), + currentPtNode.mBigrams, currentPtNode.mProbabilityInfo, + currentPtNode.mIsNotAWord, currentPtNode.mIsPossiblyOffensive, + currentPtNode.mChildren); + newChildren.mData.add(newOldWord); + + final PtNode newParent; + if (charIndex + differentCharIndex >= word.length) { + newParent = new PtNode( + Arrays.copyOfRange(currentPtNode.mChars, 0, differentCharIndex), + null /* bigrams */, probabilityInfo, + isNotAWord, isPossiblyOffensive, newChildren); + } else { + newParent = new PtNode( + Arrays.copyOfRange(currentPtNode.mChars, 0, differentCharIndex), + null /* bigrams */, null /* probabilityInfo */, + false /* isNotAWord */, false /* isPossiblyOffensive */, + newChildren); + final PtNode newWord = new PtNode(Arrays.copyOfRange(word, + charIndex + differentCharIndex, word.length), + null /* bigrams */, probabilityInfo, + isNotAWord, isPossiblyOffensive); + final int addIndex = word[charIndex + differentCharIndex] + > currentPtNode.mChars[differentCharIndex] ? 1 : 0; + newChildren.mData.add(addIndex, newWord); + } + currentNodeArray.mData.set(nodeIndex, newParent); + } + if (DBG) checkStack(currentNodeArray); + } + } + } + + private static int ARRAYS_ARE_EQUAL = 0; + + /** + * Custom comparison of two int arrays taken to contain character codes. + * + * This method compares the two arrays passed as an argument in a lexicographic way, + * with an offset in the dst string. + * This method does NOT test for the first character. It is taken to be equal. + * I repeat: this method starts the comparison at 1 <> dstOffset + 1. + * The index where the strings differ is returned. ARRAYS_ARE_EQUAL = 0 is returned if the + * strings are equal. This works BECAUSE we don't look at the first character. + * + * @param src the left-hand side string of the comparison. + * @param dst the right-hand side string of the comparison. + * @param dstOffset the offset in the right-hand side string. + * @return the index at which the strings differ, or ARRAYS_ARE_EQUAL = 0 if they don't. + */ + private static int compareCharArrays(final int[] src, final int[] dst, int dstOffset) { + // We do NOT test the first char, because we come from a method that already + // tested it. + for (int i = 1; i < src.length; ++i) { + if (dstOffset + i >= dst.length) return i; + if (src[i] != dst[dstOffset + i]) return i; + } + if (dst.length > src.length) return src.length; + return ARRAYS_ARE_EQUAL; + } + + /** + * Helper class that compares and sorts two PtNodes according to their + * first element only. I repeat: ONLY the first element is considered, the rest + * is ignored. + * This comparator imposes orderings that are inconsistent with equals. + */ + static final class PtNodeComparator implements java.util.Comparator<PtNode> { + @Override + public int compare(PtNode p1, PtNode p2) { + if (p1.mChars[0] == p2.mChars[0]) return 0; + return p1.mChars[0] < p2.mChars[0] ? -1 : 1; + } + } + final static PtNodeComparator PTNODE_COMPARATOR = new PtNodeComparator(); + + /** + * Finds the insertion index of a character within a node array. + */ + private static int findInsertionIndex(final PtNodeArray nodeArray, int character) { + final ArrayList<PtNode> data = nodeArray.mData; + final PtNode reference = new PtNode(new int[] { character }, + null /* bigrams */, null /* probabilityInfo */, + false /* isNotAWord */, false /* isPossiblyOffensive */); + int result = Collections.binarySearch(data, reference, PTNODE_COMPARATOR); + return result >= 0 ? result : -result - 1; + } + + /** + * Find the index of a char in a node array, if it exists. + * + * @param nodeArray the node array to search in. + * @param character the character to search for. + * @return the position of the character if it's there, or CHARACTER_NOT_FOUND_INDEX = -1 else. + */ + private static int findIndexOfChar(final PtNodeArray nodeArray, int character) { + final int insertionIndex = findInsertionIndex(nodeArray, character); + if (nodeArray.mData.size() <= insertionIndex) return CHARACTER_NOT_FOUND_INDEX; + return character == nodeArray.mData.get(insertionIndex).mChars[0] ? insertionIndex + : CHARACTER_NOT_FOUND_INDEX; + } + + /** + * Helper method to find a word in a given branch. + */ + public static PtNode findWordInTree(final PtNodeArray rootNodeArray, final String string) { + PtNodeArray nodeArray = rootNodeArray; + int index = 0; + final StringBuilder checker = DBG ? new StringBuilder() : null; + final int[] codePoints = getCodePoints(string); + + PtNode currentPtNode; + do { + int indexOfGroup = findIndexOfChar(nodeArray, codePoints[index]); + if (CHARACTER_NOT_FOUND_INDEX == indexOfGroup) return null; + currentPtNode = nodeArray.mData.get(indexOfGroup); + + if (codePoints.length - index < currentPtNode.mChars.length) return null; + int newIndex = index; + while (newIndex < codePoints.length && newIndex - index < currentPtNode.mChars.length) { + if (currentPtNode.mChars[newIndex - index] != codePoints[newIndex]) return null; + newIndex++; + } + index = newIndex; + + if (DBG) { + checker.append(new String(currentPtNode.mChars, 0, currentPtNode.mChars.length)); + } + if (index < codePoints.length) { + nodeArray = currentPtNode.mChildren; + } + } while (null != nodeArray && index < codePoints.length); + + if (index < codePoints.length) return null; + if (!currentPtNode.isTerminal()) return null; + if (DBG && !string.equals(checker.toString())) return null; + return currentPtNode; + } + + /** + * Helper method to find out whether a word is in the dict or not. + */ + public boolean hasWord(final String s) { + if (null == s || "".equals(s)) { + throw new RuntimeException("Can't search for a null or empty string"); + } + return null != findWordInTree(mRootNodeArray, s); + } + + /** + * Recursively count the number of PtNodes in a given branch of the trie. + * + * @param nodeArray the parent node. + * @return the number of PtNodes in all the branch under this node. + */ + public static int countPtNodes(final PtNodeArray nodeArray) { + final int nodeSize = nodeArray.mData.size(); + int size = nodeSize; + for (int i = nodeSize - 1; i >= 0; --i) { + PtNode ptNode = nodeArray.mData.get(i); + if (null != ptNode.mChildren) + size += countPtNodes(ptNode.mChildren); + } + return size; + } + + /** + * Iterator to walk through a dictionary. + * + * This is purely for convenience. + */ + public static final class DictionaryIterator implements Iterator<WordProperty> { + private static final class Position { + public Iterator<PtNode> pos; + public int length; + public Position(ArrayList<PtNode> ptNodes) { + pos = ptNodes.iterator(); + length = 0; + } + } + final StringBuilder mCurrentString; + final LinkedList<Position> mPositions; + + public DictionaryIterator(ArrayList<PtNode> ptRoot) { + mCurrentString = new StringBuilder(); + mPositions = new LinkedList<>(); + final Position rootPos = new Position(ptRoot); + mPositions.add(rootPos); + } + + @Override + public boolean hasNext() { + for (Position p : mPositions) { + if (p.pos.hasNext()) { + return true; + } + } + return false; + } + + @Override + public WordProperty next() { + Position currentPos = mPositions.getLast(); + mCurrentString.setLength(currentPos.length); + + do { + if (currentPos.pos.hasNext()) { + final PtNode currentPtNode = currentPos.pos.next(); + currentPos.length = mCurrentString.length(); + for (int i : currentPtNode.mChars) { + mCurrentString.append(Character.toChars(i)); + } + if (null != currentPtNode.mChildren) { + currentPos = new Position(currentPtNode.mChildren.mData); + currentPos.length = mCurrentString.length(); + mPositions.addLast(currentPos); + } + if (currentPtNode.isTerminal()) { + return new WordProperty(mCurrentString.toString(), + currentPtNode.mProbabilityInfo, currentPtNode.mBigrams, + currentPtNode.mIsNotAWord, currentPtNode.mIsPossiblyOffensive); + } + } else { + mPositions.removeLast(); + currentPos = mPositions.getLast(); + mCurrentString.setLength(mPositions.getLast().length); + } + } while (true); + } + + @Override + public void remove() { + throw new UnsupportedOperationException("Unsupported yet"); + } + + } + + /** + * Method to return an iterator. + * + * This method enables Java's enhanced for loop. With this you can have a FusionDictionary x + * and say : for (Word w : x) {} + */ + @Override + public Iterator<WordProperty> iterator() { + return new DictionaryIterator(mRootNodeArray.mData); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/MakedictLog.java b/tests/src/org/kelar/inputmethod/latin/makedict/MakedictLog.java new file mode 100644 index 000000000..07270d1d0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/MakedictLog.java @@ -0,0 +1,44 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +/** + * Wrapper to redirect log events to the right output medium. + */ +public class MakedictLog { + public static final boolean DBG = true; + + private static void print(String message) { + System.out.println(message); + } + + public static void d(String message) { + print(message); + } + + public static void i(String message) { + print(message); + } + + public static void w(String message) { + print(message); + } + + public static void e(String message) { + print(message); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/PendingAttribute.java b/tests/src/org/kelar/inputmethod/latin/makedict/PendingAttribute.java new file mode 100644 index 000000000..0abce4848 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/PendingAttribute.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2011 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 org.kelar.inputmethod.latin.makedict; + +/** + * A not-yet-resolved attribute. + * + * An attribute is either a bigram or a shortcut. + * All instances of this class are always immutable. + */ +public final class PendingAttribute { + public final int mFrequency; + public final int mAddress; + public PendingAttribute(final int frequency, final int address) { + mFrequency = frequency; + mAddress = address; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/PtNodeInfo.java b/tests/src/org/kelar/inputmethod/latin/makedict/PtNodeInfo.java new file mode 100644 index 000000000..65209a832 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/PtNodeInfo.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011 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 org.kelar.inputmethod.latin.makedict; + +import java.util.ArrayList; + +/** + * Raw PtNode info straight out of a file. This will contain numbers for addresses. + */ +public final class PtNodeInfo { + public final int mOriginalAddress; + public final int mEndAddress; + public final int mFlags; + public final int[] mCharacters; + public final ProbabilityInfo mProbabilityInfo; + public final int mChildrenAddress; + public final ArrayList<WeightedString> mShortcutTargets; + public final ArrayList<PendingAttribute> mBigrams; + + public PtNodeInfo(final int originalAddress, final int endAddress, final int flags, + final int[] characters, final ProbabilityInfo probabilityInfo, + final int childrenAddress, final ArrayList<WeightedString> shortcutTargets, + final ArrayList<PendingAttribute> bigrams) { + mOriginalAddress = originalAddress; + mEndAddress = endAddress; + mFlags = flags; + mCharacters = characters; + mProbabilityInfo = probabilityInfo; + mChildrenAddress = childrenAddress; + mShortcutTargets = shortcutTargets; + mBigrams = bigrams; + } + + public boolean isTerminal() { + return mProbabilityInfo != null; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/Ver2DictEncoder.java b/tests/src/org/kelar/inputmethod/latin/makedict/Ver2DictEncoder.java new file mode 100644 index 000000000..8b3636208 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/Ver2DictEncoder.java @@ -0,0 +1,280 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; +import org.kelar.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding; +import org.kelar.inputmethod.latin.makedict.BinaryDictEncoderUtils.CodePointTable; +import org.kelar.inputmethod.latin.makedict.FormatSpec.FormatOptions; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNode; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Objects; + +/** + * An implementation of DictEncoder for version 2 binary dictionary. + */ +@UsedForTesting +public class Ver2DictEncoder implements DictEncoder { + + private final File mDictFile; + private OutputStream mOutStream; + private byte[] mBuffer; + private int mPosition; + private final int mCodePointTableMode; + public static final int CODE_POINT_TABLE_OFF = 0; + public static final int CODE_POINT_TABLE_ON = 1; + + @UsedForTesting + public Ver2DictEncoder(final File dictFile, final int codePointTableMode) { + mDictFile = dictFile; + mOutStream = null; + mBuffer = null; + mCodePointTableMode = codePointTableMode; + } + + // This constructor is used only by BinaryDictOffdeviceUtilsTests. + // If you want to use this in the production code, you should consider keeping consistency of + // the interface of Ver3DictDecoder by using factory. + @UsedForTesting + public Ver2DictEncoder(final OutputStream outStream) { + mDictFile = null; + mOutStream = outStream; + mCodePointTableMode = CODE_POINT_TABLE_OFF; + } + + private void openStream() throws FileNotFoundException { + mOutStream = new FileOutputStream(mDictFile); + } + + private void close() throws IOException { + if (mOutStream != null) { + mOutStream.close(); + mOutStream = null; + } + } + + // Package for testing + static CodePointTable makeCodePointTable(final FusionDictionary dict) { + final HashMap<Integer, Integer> codePointOccurrenceCounts = new HashMap<>(); + for (final WordProperty word : dict) { + // Store per code point occurrence + final String wordString = word.mWord; + for (int i = 0; i < wordString.length(); ++i) { + final int codePoint = Character.codePointAt(wordString, i); + if (codePointOccurrenceCounts.containsKey(codePoint)) { + codePointOccurrenceCounts.put(codePoint, + codePointOccurrenceCounts.get(codePoint) + 1); + } else { + codePointOccurrenceCounts.put(codePoint, 1); + } + } + } + final ArrayList<Entry<Integer, Integer>> codePointOccurrenceArray = + new ArrayList<>(codePointOccurrenceCounts.entrySet()); + // Descending order sort by occurrence (value side) + Collections.sort(codePointOccurrenceArray, new Comparator<Entry<Integer, Integer>>() { + @Override + public int compare(final Entry<Integer, Integer> a, final Entry<Integer, Integer> b) { + if (!Objects.equals(a.getValue(), b.getValue())) { + return b.getValue().compareTo(a.getValue()); + } + return b.getKey().compareTo(a.getKey()); + } + }); + int currentCodePointTableIndex = FormatSpec.MINIMAL_ONE_BYTE_CHARACTER_VALUE; + // Temporary map for writing of nodes + final HashMap<Integer, Integer> codePointToOneByteCodeMap = new HashMap<>(); + for (final Entry<Integer, Integer> entry : codePointOccurrenceArray) { + // Put a relation from the original code point to the one byte code. + codePointToOneByteCodeMap.put(entry.getKey(), currentCodePointTableIndex); + if (FormatSpec.MAXIMAL_ONE_BYTE_CHARACTER_VALUE < ++currentCodePointTableIndex) { + break; + } + } + // codePointToOneByteCodeMap for writing the trie + // codePointOccurrenceArray for writing the header + return new CodePointTable(codePointToOneByteCodeMap, codePointOccurrenceArray); + } + + @Override + public void writeDictionary(final FusionDictionary dict, final FormatOptions formatOptions) + throws IOException, UnsupportedFormatException { + // We no longer support anything but the latest version of v2. + if (formatOptions.mVersion != FormatSpec.VERSION202) { + throw new UnsupportedFormatException( + "The given format options has wrong version number : " + + formatOptions.mVersion); + } + + if (mOutStream == null) { + openStream(); + } + + // Make code point conversion table ordered by occurrence of code points + // Version 201 or later have codePointTable + final CodePointTable codePointTable; + if (mCodePointTableMode == CODE_POINT_TABLE_OFF || formatOptions.mVersion + < FormatSpec.MINIMUM_SUPPORTED_VERSION_OF_CODE_POINT_TABLE) { + codePointTable = new CodePointTable(); + } else { + codePointTable = makeCodePointTable(dict); + } + + BinaryDictEncoderUtils.writeDictionaryHeader(mOutStream, dict, formatOptions, + codePointTable.mCodePointOccurrenceArray); + + // Addresses are limited to 3 bytes, but since addresses can be relative to each node + // array, the structure itself is not limited to 16MB. However, if it is over 16MB deciding + // the order of the PtNode arrays becomes a quite complicated problem, because though the + // dictionary itself does not have a size limit, each node array must still be within 16MB + // of all its children and parents. As long as this is ensured, the dictionary file may + // grow to any size. + + // Leave the choice of the optimal node order to the flattenTree function. + MakedictLog.i("Flattening the tree..."); + ArrayList<PtNodeArray> flatNodes = BinaryDictEncoderUtils.flattenTree(dict.mRootNodeArray); + + MakedictLog.i("Computing addresses..."); + BinaryDictEncoderUtils.computeAddresses(dict, flatNodes, + codePointTable.mCodePointToOneByteCodeMap); + MakedictLog.i("Checking PtNode array..."); + if (MakedictLog.DBG) BinaryDictEncoderUtils.checkFlatPtNodeArrayList(flatNodes); + + // Create a buffer that matches the final dictionary size. + final PtNodeArray lastNodeArray = flatNodes.get(flatNodes.size() - 1); + final int bufferSize = lastNodeArray.mCachedAddressAfterUpdate + lastNodeArray.mCachedSize; + mBuffer = new byte[bufferSize]; + + MakedictLog.i("Writing file..."); + + for (PtNodeArray nodeArray : flatNodes) { + BinaryDictEncoderUtils.writePlacedPtNodeArray(dict, this, nodeArray, + codePointTable.mCodePointToOneByteCodeMap); + } + if (MakedictLog.DBG) BinaryDictEncoderUtils.showStatistics(flatNodes); + mOutStream.write(mBuffer, 0, mPosition); + + MakedictLog.i("Done"); + close(); + } + + @Override + public void setPosition(final int position) { + if (mBuffer == null || position < 0 || position >= mBuffer.length) return; + mPosition = position; + } + + @Override + public int getPosition() { + return mPosition; + } + + @Override + public void writePtNodeCount(final int ptNodeCount) { + final int countSize = BinaryDictIOUtils.getPtNodeCountSize(ptNodeCount); + if (countSize != 1 && countSize != 2) { + throw new RuntimeException("Strange size from getGroupCountSize : " + countSize); + } + final int encodedPtNodeCount = (countSize == 2) ? + (ptNodeCount | FormatSpec.LARGE_PTNODE_ARRAY_SIZE_FIELD_SIZE_FLAG) : ptNodeCount; + mPosition = BinaryDictEncoderUtils.writeUIntToBuffer(mBuffer, mPosition, encodedPtNodeCount, + countSize); + } + + private void writePtNodeFlags(final PtNode ptNode, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + final int childrenPos = BinaryDictEncoderUtils.getChildrenPosition(ptNode, + codePointToOneByteCodeMap); + mPosition = BinaryDictEncoderUtils.writeUIntToBuffer(mBuffer, mPosition, + BinaryDictEncoderUtils.makePtNodeFlags(ptNode, childrenPos), + FormatSpec.PTNODE_FLAGS_SIZE); + } + + private void writeCharacters(final int[] codePoints, final boolean hasSeveralChars, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + mPosition = CharEncoding.writeCharArray(codePoints, mBuffer, mPosition, + codePointToOneByteCodeMap); + if (hasSeveralChars) { + mBuffer[mPosition++] = FormatSpec.PTNODE_CHARACTERS_TERMINATOR; + } + } + + private void writeFrequency(final int frequency) { + if (frequency >= 0) { + mPosition = BinaryDictEncoderUtils.writeUIntToBuffer(mBuffer, mPosition, frequency, + FormatSpec.PTNODE_FREQUENCY_SIZE); + } + } + + private void writeChildrenPosition(final PtNode ptNode, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + final int childrenPos = BinaryDictEncoderUtils.getChildrenPosition(ptNode, + codePointToOneByteCodeMap); + mPosition += BinaryDictEncoderUtils.writeChildrenPosition(mBuffer, mPosition, + childrenPos); + } + + /** + * Write a bigram attributes list to mBuffer. + * + * @param bigrams the bigram attributes list. + * @param dict the dictionary the node array is a part of (for relative offsets). + */ + private void writeBigrams(final ArrayList<WeightedString> bigrams, + final FusionDictionary dict) { + if (bigrams == null) return; + + final Iterator<WeightedString> bigramIterator = bigrams.iterator(); + while (bigramIterator.hasNext()) { + final WeightedString bigram = bigramIterator.next(); + final PtNode target = + FusionDictionary.findWordInTree(dict.mRootNodeArray, bigram.mWord); + final int addressOfBigram = target.mCachedAddressAfterUpdate; + final int unigramFrequencyForThisWord = target.getProbability(); + final int offset = addressOfBigram + - (mPosition + FormatSpec.PTNODE_ATTRIBUTE_FLAGS_SIZE); + final int bigramFlags = BinaryDictEncoderUtils.makeBigramFlags(bigramIterator.hasNext(), + offset, bigram.getProbability(), unigramFrequencyForThisWord, bigram.mWord); + mPosition = BinaryDictEncoderUtils.writeUIntToBuffer(mBuffer, mPosition, bigramFlags, + FormatSpec.PTNODE_ATTRIBUTE_FLAGS_SIZE); + mPosition += BinaryDictEncoderUtils.writeChildrenPosition(mBuffer, mPosition, + Math.abs(offset)); + } + } + + @Override + public void writePtNode(final PtNode ptNode, final FusionDictionary dict, + final HashMap<Integer, Integer> codePointToOneByteCodeMap) { + writePtNodeFlags(ptNode, codePointToOneByteCodeMap); + writeCharacters(ptNode.mChars, ptNode.hasSeveralChars(), codePointToOneByteCodeMap); + writeFrequency(ptNode.getProbability()); + writeChildrenPosition(ptNode, codePointToOneByteCodeMap); + writeBigrams(ptNode.mBigrams, dict); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/Ver4DictDecoder.java b/tests/src/org/kelar/inputmethod/latin/makedict/Ver4DictDecoder.java new file mode 100644 index 000000000..351fd72c4 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/Ver4DictDecoder.java @@ -0,0 +1,104 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; +import org.kelar.inputmethod.latin.BinaryDictionary; +import org.kelar.inputmethod.latin.common.FileUtils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; + +/** + * An implementation of binary dictionary decoder for version 4 binary dictionary. + */ +@UsedForTesting +public class Ver4DictDecoder extends AbstractDictDecoder { + final File mDictDirectory; + + @UsedForTesting + /* package */ Ver4DictDecoder(final File dictDirectory) { + mDictDirectory = dictDirectory; + + } + + @Override + public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException { + // dictType is not being used in dicttool. Passing an empty string. + final BinaryDictionary binaryDictionary= new BinaryDictionary( + mDictDirectory.getAbsolutePath(), 0 /* offset */, 0 /* length */, + true /* useFullEditDistance */, null /* locale */, + "" /* dictType */, true /* isUpdatable */); + final DictionaryHeader header = binaryDictionary.getHeader(); + binaryDictionary.close(); + if (header == null) { + throw new IOException("Cannot read the dictionary header."); + } + return header; + } + + @Override + public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken) + throws FileNotFoundException, IOException, UnsupportedFormatException { + // dictType is not being used in dicttool. Passing an empty string. + final BinaryDictionary binaryDictionary = new BinaryDictionary( + mDictDirectory.getAbsolutePath(), 0 /* offset */, 0 /* length */, + true /* useFullEditDistance */, null /* locale */, + "" /* dictType */, true /* isUpdatable */); + final DictionaryHeader header = readHeader(); + final FusionDictionary fusionDict = + new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions); + int token = 0; + final ArrayList<WordProperty> wordProperties = new ArrayList<>(); + do { + final BinaryDictionary.GetNextWordPropertyResult result = + binaryDictionary.getNextWordProperty(token); + final WordProperty wordProperty = result.mWordProperty; + if (wordProperty == null) { + binaryDictionary.close(); + if (deleteDictIfBroken) { + FileUtils.deleteRecursively(mDictDirectory); + } + return null; + } + wordProperties.add(wordProperty); + token = result.mNextToken; + } while (token != 0); + + // Insert unigrams into the fusion dictionary. + for (final WordProperty wordProperty : wordProperties) { + fusionDict.add(wordProperty.mWord, wordProperty.mProbabilityInfo, + wordProperty.mIsNotAWord, + wordProperty.mIsPossiblyOffensive); + } + // Insert bigrams into the fusion dictionary. + // TODO: Support ngrams. + for (final WordProperty wordProperty : wordProperties) { + if (!wordProperty.mHasNgrams) { + continue; + } + final String word0 = wordProperty.mWord; + for (final WeightedString bigram : wordProperty.getBigrams()) { + fusionDict.setBigram(word0, bigram.mWord, bigram.mProbabilityInfo); + } + } + binaryDictionary.close(); + return fusionDict; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/makedict/Ver4DictEncoder.java b/tests/src/org/kelar/inputmethod/latin/makedict/Ver4DictEncoder.java new file mode 100644 index 000000000..2eb3010c2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/makedict/Ver4DictEncoder.java @@ -0,0 +1,133 @@ +/* + * 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 org.kelar.inputmethod.latin.makedict; + +import org.kelar.inputmethod.annotations.UsedForTesting; +import org.kelar.inputmethod.latin.BinaryDictionary; +import org.kelar.inputmethod.latin.Dictionary; +import org.kelar.inputmethod.latin.NgramContext; +import org.kelar.inputmethod.latin.common.LocaleUtils; +import org.kelar.inputmethod.latin.makedict.FormatSpec.FormatOptions; +import org.kelar.inputmethod.latin.makedict.FusionDictionary.PtNode; +import org.kelar.inputmethod.latin.utils.BinaryDictionaryUtils; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +/** + * An implementation of DictEncoder for version 4 binary dictionary. + */ +@UsedForTesting +public class Ver4DictEncoder implements DictEncoder { + private final File mDictPlacedDir; + + @UsedForTesting + public Ver4DictEncoder(final File dictPlacedDir) { + mDictPlacedDir = dictPlacedDir; + } + + // TODO: This builds a FusionDictionary first and iterates it to add words to the binary + // dictionary. However, it is possible to just add words directly to the binary dictionary + // instead. + // In the long run, when we stop supporting version 2, FusionDictionary will become deprecated + // and we can remove it. Then we'll be able to just call BinaryDictionary directly. + @Override + public void writeDictionary(FusionDictionary dict, FormatOptions formatOptions) + throws IOException, UnsupportedFormatException { + if (formatOptions.mVersion != FormatSpec.VERSION4) { + throw new UnsupportedFormatException("File header has a wrong version number : " + + formatOptions.mVersion); + } + if (!mDictPlacedDir.isDirectory()) { + throw new UnsupportedFormatException("Given path is not a directory."); + } + if (!BinaryDictionaryUtils.createEmptyDictFile(mDictPlacedDir.getAbsolutePath(), + FormatSpec.VERSION4, LocaleUtils.constructLocaleFromString( + dict.mOptions.mAttributes.get(DictionaryHeader.DICTIONARY_LOCALE_KEY)), + dict.mOptions.mAttributes)) { + throw new IOException("Cannot create dictionary file : " + + mDictPlacedDir.getAbsolutePath()); + } + final BinaryDictionary binaryDict = new BinaryDictionary(mDictPlacedDir.getAbsolutePath(), + 0l, mDictPlacedDir.length(), true /* useFullEditDistance */, + LocaleUtils.constructLocaleFromString(dict.mOptions.mAttributes.get( + DictionaryHeader.DICTIONARY_LOCALE_KEY)), + Dictionary.TYPE_USER /* Dictionary type. Does not matter for us */, + true /* isUpdatable */); + if (!binaryDict.isValidDictionary()) { + // Somehow createEmptyDictFile returned true, but the file was not created correctly + throw new IOException("Cannot create dictionary file"); + } + for (final WordProperty wordProperty : dict) { + if (!binaryDict.addUnigramEntry(wordProperty.mWord, wordProperty.getProbability(), + wordProperty.mIsBeginningOfSentence, wordProperty.mIsNotAWord, + wordProperty.mIsPossiblyOffensive, 0 /* timestamp */)) { + MakedictLog.e("Cannot add unigram entry for " + wordProperty.mWord); + } + if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) { + if (!binaryDict.flushWithGC()) { + MakedictLog.e("Cannot flush dict with GC."); + return; + } + } + } + for (final WordProperty word0Property : dict) { + if (!word0Property.mHasNgrams) continue; + // TODO: Support ngram. + for (final WeightedString word1 : word0Property.getBigrams()) { + final NgramContext ngramContext = + new NgramContext(new NgramContext.WordInfo(word0Property.mWord)); + if (!binaryDict.addNgramEntry(ngramContext, word1.mWord, + word1.getProbability(), 0 /* timestamp */)) { + MakedictLog.e("Cannot add n-gram entry for " + + ngramContext + " -> " + word1.mWord); + return; + } + if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) { + if (!binaryDict.flushWithGC()) { + MakedictLog.e("Cannot flush dict with GC."); + return; + } + } + } + } + if (!binaryDict.flushWithGC()) { + MakedictLog.e("Cannot flush dict with GC."); + return; + } + binaryDict.close(); + } + + @Override + public void setPosition(int position) { + } + + @Override + public int getPosition() { + return 0; + } + + @Override + public void writePtNodeCount(int ptNodeCount) { + } + + @Override + public void writePtNode(PtNode ptNode, FusionDictionary dict, + HashMap<Integer, Integer> codePointToOneByteCodeMap) { + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/network/BlockingHttpClientTests.java b/tests/src/org/kelar/inputmethod/latin/network/BlockingHttpClientTests.java new file mode 100644 index 000000000..941abc606 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/network/BlockingHttpClientTests.java @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.network; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.network.BlockingHttpClient.ResponseProcessor; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.util.Arrays; +import java.util.Random; + +/** + * Tests for {@link BlockingHttpClient}. + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class BlockingHttpClientTests { + @Mock HttpURLConnection mMockHttpConnection; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testError_badGateway() throws IOException, AuthException { + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_GATEWAY); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeErrorResponseProcessor processor = new FakeErrorResponseProcessor(); + + try { + client.execute(null /* empty request */, processor); + fail("Expecting an HttpException"); + } catch (HttpException e) { + // expected HttpException + assertEquals(HttpURLConnection.HTTP_BAD_GATEWAY, e.getHttpStatusCode()); + } + } + + @Test + public void testError_clientTimeout() throws Exception { + when(mMockHttpConnection.getResponseCode()).thenReturn( + HttpURLConnection.HTTP_CLIENT_TIMEOUT); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeErrorResponseProcessor processor = new FakeErrorResponseProcessor(); + + try { + client.execute(null /* empty request */, processor); + fail("Expecting an HttpException"); + } catch (HttpException e) { + // expected HttpException + assertEquals(HttpURLConnection.HTTP_CLIENT_TIMEOUT, e.getHttpStatusCode()); + } + } + + @Test + public void testError_forbiddenWithRequest() throws Exception { + final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN); + when(mMockHttpConnection.getOutputStream()).thenReturn(mockOutputStream); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeErrorResponseProcessor processor = new FakeErrorResponseProcessor(); + + try { + client.execute(new byte[100], processor); + fail("Expecting an HttpException"); + } catch (HttpException e) { + assertEquals(HttpURLConnection.HTTP_FORBIDDEN, e.getHttpStatusCode()); + } + verify(mockOutputStream).write(any(byte[].class), eq(0), eq(100)); + } + + @Test + public void testSuccess_emptyRequest() throws Exception { + final Random rand = new Random(); + byte[] response = new byte[100]; + rand.nextBytes(response); + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); + when(mMockHttpConnection.getInputStream()).thenReturn(new ByteArrayInputStream(response)); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeSuccessResponseProcessor processor = + new FakeSuccessResponseProcessor(response); + + client.execute(null /* empty request */, processor); + assertTrue("ResponseProcessor was not invoked", processor.mInvoked); + } + + @Test + public void testSuccess() throws Exception { + final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); + final Random rand = new Random(); + byte[] response = new byte[100]; + rand.nextBytes(response); + when(mMockHttpConnection.getOutputStream()).thenReturn(mockOutputStream); + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); + when(mMockHttpConnection.getInputStream()).thenReturn(new ByteArrayInputStream(response)); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeSuccessResponseProcessor processor = + new FakeSuccessResponseProcessor(response); + + client.execute(new byte[100], processor); + assertTrue("ResponseProcessor was not invoked", processor.mInvoked); + } + + static class FakeErrorResponseProcessor implements ResponseProcessor<Void> { + @Override + public Void onSuccess(InputStream response) { + fail("Expected an error but received success"); + return null; + } + } + + private static class FakeSuccessResponseProcessor implements ResponseProcessor<Void> { + private final byte[] mExpectedResponse; + + boolean mInvoked; + + FakeSuccessResponseProcessor(byte[] expectedResponse) { + mExpectedResponse = expectedResponse; + } + + @Override + public Void onSuccess(InputStream response) { + try { + mInvoked = true; + BufferedInputStream in = new BufferedInputStream(response); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int read = 0; + while ((read = in.read()) != -1) { + buffer.write(read); + } + byte[] actualResponse = buffer.toByteArray(); + in.close(); + assertTrue("Response doesn't match", + Arrays.equals(mExpectedResponse, actualResponse)); + } catch (IOException ex) { + fail("IOException in onSuccess"); + } + return null; + } + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java b/tests/src/org/kelar/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java new file mode 100644 index 000000000..63a5f6ff0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.network; + +import static org.kelar.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_BI_DIRECTIONAL; +import static org.kelar.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_DOWNLOAD_ONLY; +import static org.kelar.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_UPLOAD_ONLY; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; + +/** + * Tests for {@link HttpUrlConnectionBuilder}. + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class HttpUrlConnectionBuilderTests { + @Test + public void testSetUrl_malformed() { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + try { + builder.setUrl("dadasd!@%@!:11"); + fail("Expected a MalformedURLException."); + } catch (MalformedURLException e) { + // Expected + } + } + + @Test + public void testSetConnectTimeout_invalid() { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + try { + builder.setConnectTimeout(-1); + fail("Expected an IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // Expected + } + } + + @Test + public void testSetConnectTimeout() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setConnectTimeout(8765); + HttpURLConnection connection = builder.build(); + assertEquals(8765, connection.getConnectTimeout()); + } + + @Test + public void testSetReadTimeout_invalid() { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + try { + builder.setReadTimeout(-1); + fail("Expected an IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // Expected + } + } + + @Test + public void testSetReadTimeout() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setReadTimeout(8765); + HttpURLConnection connection = builder.build(); + assertEquals(8765, connection.getReadTimeout()); + } + + @Test + public void testAddHeader() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + builder.addHeader("some-random-key", "some-random-value"); + HttpURLConnection connection = builder.build(); + assertEquals("some-random-value", connection.getRequestProperty("some-random-key")); + } + + @Test + public void testSetUseCache_notSet() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + HttpURLConnection connection = builder.build(); + assertFalse(connection.getUseCaches()); + } + + @Test + public void testSetUseCache_false() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + HttpURLConnection connection = builder.build(); + connection.setUseCaches(false); + assertFalse(connection.getUseCaches()); + } + + @Test + public void testSetUseCache_true() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + HttpURLConnection connection = builder.build(); + connection.setUseCaches(true); + assertTrue(connection.getUseCaches()); + } + + @Test + public void testSetMode_uploadOnly() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + builder.setMode(MODE_UPLOAD_ONLY); + HttpURLConnection connection = builder.build(); + assertTrue(connection.getDoInput()); + assertFalse(connection.getDoOutput()); + } + + @Test + public void testSetMode_downloadOnly() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setMode(MODE_DOWNLOAD_ONLY); + HttpURLConnection connection = builder.build(); + assertFalse(connection.getDoInput()); + assertTrue(connection.getDoOutput()); + } + + @Test + public void testSetMode_bidirectional() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setMode(MODE_BI_DIRECTIONAL); + HttpURLConnection connection = builder.build(); + assertTrue(connection.getDoInput()); + assertTrue(connection.getDoOutput()); + } + + @Test + public void testSetAuthToken() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setAuthToken("some-random-auth-token"); + HttpURLConnection connection = builder.build(); + assertEquals("some-random-auth-token", + connection.getRequestProperty(HttpUrlConnectionBuilder.HTTP_HEADER_AUTHORIZATION)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/org/kelar/inputmethod/latin/personalization/UserHistoryDictionaryTests.java new file mode 100644 index 000000000..9e6a18a13 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -0,0 +1,232 @@ +/* + * 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 org.kelar.inputmethod.latin.personalization; + +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.util.Log; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.ExpandableBinaryDictionary; +import org.kelar.inputmethod.latin.utils.BinaryDictionaryUtils; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.Locale; +import java.util.Random; + +/** + * Unit tests for UserHistoryDictionary + */ +@LargeTest +@RunWith(AndroidJUnit4.class) +public class UserHistoryDictionaryTests { + private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName(); + private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000; + private static final String TEST_ACCOUNT = "account@example.com"; + + private int mCurrentTime = 0; + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + private static void printAllFiles(final File dir) { + Log.d(TAG, dir.getAbsolutePath()); + for (final File file : dir.listFiles()) { + Log.d(TAG, " " + file.getName()); + } + } + + private static void assertDictionaryExists(final UserHistoryDictionary dict, + final File dictFile) { + Log.d(TAG, "waiting for writing ..."); + dict.waitAllTasksForTests(); + if (!dictFile.exists()) { + try { + Log.d(TAG, dictFile + " is not existing. Wait " + + WAIT_FOR_WRITING_FILE_IN_MILLISECONDS + " ms for writing."); + printAllFiles(dictFile.getParentFile()); + Thread.sleep(WAIT_FOR_WRITING_FILE_IN_MILLISECONDS); + } catch (final InterruptedException e) { + Log.e(TAG, "Interrupted during waiting for writing the dict file."); + } + } + assertTrue("Following dictionary file doesn't exist: " + dictFile, dictFile.exists()); + } + + @Before + public void setUp() throws Exception { + resetCurrentTimeForTestMode(); + UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( + UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, getContext()); + } + + @After + public void tearDown() throws Exception { + UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( + UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, getContext()); + stopTestModeInNativeCode(); + } + + private void resetCurrentTimeForTestMode() { + mCurrentTime = 0; + setCurrentTimeForTestMode(mCurrentTime); + } + + private static int setCurrentTimeForTestMode(final int currentTime) { + return BinaryDictionaryUtils.setCurrentTimeForTest(currentTime); + } + + private static int stopTestModeInNativeCode() { + return BinaryDictionaryUtils.setCurrentTimeForTest(-1); + } + + /** + * Clear all entries in the user history dictionary. + * @param dict the user history dictionary. + */ + private static void clearHistory(final UserHistoryDictionary dict) { + dict.waitAllTasksForTests(); + dict.clear(); + dict.close(); + dict.waitAllTasksForTests(); + } + + private void doTestRandomWords(final String testAccount) { + Log.d(TAG, "This test can be used for profiling."); + Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true."); + final Locale fakeLocale = UserHistoryDictionaryTestsHelper.getFakeLocale("random_words"); + final String dictName = UserHistoryDictionary.getUserHistoryDictName( + UserHistoryDictionary.NAME, fakeLocale, + null /* dictFile */, + testAccount /* account */); + final File dictFile = ExpandableBinaryDictionary.getDictFile( + getContext(), dictName, null /* dictFile */); + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + getContext(), fakeLocale, testAccount); + clearHistory(dict); + + final int numberOfWords = 1000; + final Random random = new Random(123456); + assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords( + dict, numberOfWords, random, true /* checksContents */, mCurrentTime)); + assertDictionaryExists(dict, dictFile); + } + + @Test + public void testRandomWords_NullAccount() { + doTestRandomWords(null /* testAccount */); + } + + @Test + public void testRandomWords() { + doTestRandomWords(TEST_ACCOUNT); + } + + @Test + public void testStressTestForSwitchingLanguagesAndAddingWords() { + doTestStressTestForSwitchingLanguagesAndAddingWords(TEST_ACCOUNT); + } + + @Test + public void testStressTestForSwitchingLanguagesAndAddingWords_NullAccount() { + doTestStressTestForSwitchingLanguagesAndAddingWords(null /* testAccount */); + } + + private void doTestStressTestForSwitchingLanguagesAndAddingWords(final String testAccount) { + final int numberOfLanguages = 2; + final int numberOfLanguageSwitching = 80; + final int numberOfWordsInsertedForEachLanguageSwitch = 100; + + final File dictFiles[] = new File[numberOfLanguages]; + final UserHistoryDictionary dicts[] = new UserHistoryDictionary[numberOfLanguages]; + + try { + final Random random = new Random(123456); + + // Create filename suffixes for this test. + for (int i = 0; i < numberOfLanguages; i++) { + final Locale fakeLocale = + UserHistoryDictionaryTestsHelper.getFakeLocale("switching_languages" + i); + final String dictName = UserHistoryDictionary.getUserHistoryDictName( + UserHistoryDictionary.NAME, fakeLocale, null /* dictFile */, + testAccount /* account */); + dictFiles[i] = ExpandableBinaryDictionary.getDictFile( + getContext(), dictName, null /* dictFile */); + dicts[i] = PersonalizationHelper.getUserHistoryDictionary(getContext(), + fakeLocale, testAccount); + clearHistory(dicts[i]); + } + + final long start = System.currentTimeMillis(); + + for (int i = 0; i < numberOfLanguageSwitching; i++) { + final int index = i % numberOfLanguages; + // Switch to dicts[index]. + assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords(dicts[index], + numberOfWordsInsertedForEachLanguageSwitch, + random, + false /* checksContents */, + mCurrentTime)); + } + + final long end = System.currentTimeMillis(); + Log.d(TAG, "testStressTestForSwitchingLanguageAndAddingWords took " + + (end - start) + " ms"); + } finally { + for (int i = 0; i < numberOfLanguages; i++) { + assertDictionaryExists(dicts[i], dictFiles[i]); + } + } + } + + @Test + public void testAddManyWords() { + doTestAddManyWords(TEST_ACCOUNT); + } + + @Test + public void testAddManyWords_NullAccount() { + doTestAddManyWords(null /* testAccount */); + } + + private void doTestAddManyWords(final String testAccount) { + final Locale fakeLocale = + UserHistoryDictionaryTestsHelper.getFakeLocale("many_random_words"); + final String dictName = UserHistoryDictionary.getUserHistoryDictName( + UserHistoryDictionary.NAME, fakeLocale, null /* dictFile */, testAccount); + final File dictFile = ExpandableBinaryDictionary.getDictFile( + getContext(), dictName, null /* dictFile */); + final int numberOfWords = 10000; + final Random random = new Random(123456); + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + getContext(), fakeLocale, testAccount); + clearHistory(dict); + assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords(dict, + numberOfWords, random, true /* checksContents */, mCurrentTime)); + assertDictionaryExists(dict, dictFile); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java b/tests/src/org/kelar/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java new file mode 100644 index 000000000..11e2a7ae5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.personalization; + +import android.content.Context; + +import org.kelar.inputmethod.latin.BinaryDictionary; +import org.kelar.inputmethod.latin.NgramContext; +import org.kelar.inputmethod.latin.NgramContext.WordInfo; +import org.kelar.inputmethod.latin.common.FileUtils; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Random; + +/** + * Utility class for helping while running tests involving {@link UserHistoryDictionary}. + */ +public class UserHistoryDictionaryTestsHelper { + + /** + * Locale prefix for generating placeholder locales for tests. + */ + public static final String TEST_LOCALE_PREFIX = "test-"; + + /** + * Characters for generating random words. + */ + private static final String[] CHARACTERS = { + "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" + }; + + /** + * Remove all the test dictionary files created for the given locale. + */ + public static void removeAllTestDictFiles(final String filter, final Context context) { + final FilenameFilter filenameFilter = new FilenameFilter() { + @Override + public boolean accept(final File dir, final String filename) { + return filename.startsWith(UserHistoryDictionary.NAME + "." + filter); + } + }; + FileUtils.deleteFilteredFiles(context.getFilesDir(), filenameFilter); + } + + /** + * Generates and writes random words to dictionary. Caller can be assured + * that the write tasks would be finished; and its success would be reflected + * in the returned boolean. + * + * @param dict {@link UserHistoryDictionary} to which words should be added. + * @param numberOfWords number of words to be added. + * @param random helps generate random words. + * @param checkContents if true, checks whether written words are actually in the dictionary. + * @param currentTime timestamp that would be used for adding the words. + * @returns true if all words have been written to dictionary successfully. + */ + public static boolean addAndWriteRandomWords(final UserHistoryDictionary dict, + final int numberOfWords, final Random random, final boolean checkContents, + final int currentTime) { + final List<String> words = generateWords(numberOfWords, random); + // Add random words to the user history dictionary. + addWordsToDictionary(dict, words, currentTime); + boolean success = true; + if (checkContents) { + dict.waitAllTasksForTests(); + for (int i = 0; i < numberOfWords; ++i) { + final String word = words.get(i); + if (!dict.isInDictionary(word)) { + success = false; + break; + } + } + } + // write to file. + dict.close(); + dict.waitAllTasksForTests(); + return success; + } + + private static void addWordsToDictionary(final UserHistoryDictionary dict, + final List<String> words, final int timestamp) { + NgramContext ngramContext = NgramContext.getEmptyPrevWordsContext( + BinaryDictionary.MAX_PREV_WORD_COUNT_FOR_N_GRAM); + for (final String word : words) { + UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, timestamp); + ngramContext = ngramContext.getNextNgramContext(new WordInfo(word)); + } + } + + /** + * Creates unique test locale for using within tests. + */ + public static Locale getFakeLocale(final String name) { + return new Locale(TEST_LOCALE_PREFIX + name + System.currentTimeMillis()); + } + + /** + * Generates random words. + * + * @param numberOfWords number of words to generate. + * @param random salt used for generating random words. + */ + public static List<String> generateWords(final int numberOfWords, final Random random) { + final HashSet<String> wordSet = new HashSet<>(); + while (wordSet.size() < numberOfWords) { + wordSet.add(generateWord(random.nextInt())); + } + return new ArrayList<>(wordSet); + } + + /** + * Generates a random word. + */ + private static String generateWord(final int value) { + final int lengthOfChars = CHARACTERS.length; + final StringBuilder builder = new StringBuilder(); + long lvalue = Math.abs((long)value); + while (lvalue > 0) { + builder.append(CHARACTERS[(int)(lvalue % lengthOfChars)]); + lvalue /= lengthOfChars; + } + return builder.toString(); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/settings/AccountsSettingsFragmentTests.java b/tests/src/org/kelar/inputmethod/latin/settings/AccountsSettingsFragmentTests.java new file mode 100644 index 000000000..5eff614df --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/settings/AccountsSettingsFragmentTests.java @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.settings; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.view.View; +import android.widget.ListView; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.utils.ManagedProfileUtils; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +@MediumTest +@RunWith(AndroidJUnit4.class) +public class AccountsSettingsFragmentTests { + private static final String FRAG_NAME = AccountsSettingsFragment.class.getName(); + private static final long TEST_TIMEOUT_MILLIS = 5000; + + @Mock private ManagedProfileUtils mManagedProfileUtils; + + private TestFragmentActivity mActivity; + private TestFragmentActivity getActivity() { + return mActivity; + } + + @Before + public void setUp() throws Exception { + // Initialize the mocks. + MockitoAnnotations.initMocks(this); + ManagedProfileUtils.setTestInstance(mManagedProfileUtils); + + final Intent intent = new Intent() + .setAction(Intent.ACTION_MAIN) + .setClass(InstrumentationRegistry.getTargetContext(), TestFragmentActivity.class) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + .addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) + .putExtra(TestFragmentActivity.EXTRA_SHOW_FRAGMENT, FRAG_NAME); + mActivity = (TestFragmentActivity) InstrumentationRegistry.getInstrumentation() + .startActivitySync(intent); + } + + @After + public void tearDown() throws Exception { + ManagedProfileUtils.setTestInstance(null); + mActivity = null; + } + + @Test + public void testEmptyAccounts() { + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + try { + fragment.createAccountPicker(new String[0], null, null /* listener */); + fail("Expected IllegalArgumentException, never thrown"); + } catch (IllegalArgumentException expected) { + // Expected. + } + } + + private static class DialogHolder { + AlertDialog mDialog; + DialogHolder() {} + } + + @Test + public void testMultipleAccounts_noSettingsForManagedProfile() { + when(mManagedProfileUtils.hasWorkProfile(any(Context.class))).thenReturn(true); + + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + final AlertDialog dialog = initDialog(fragment, null).mDialog; + final ListView lv = dialog.getListView(); + + // Nothing to check/uncheck. + assertNull(fragment.findPreference(AccountsSettingsFragment.PREF_ACCCOUNT_SWITCHER)); + } + + @Test + public void testMultipleAccounts_noCurrentAccount() { + when(mManagedProfileUtils.hasWorkProfile(any(Context.class))).thenReturn(false); + + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + final AlertDialog dialog = initDialog(fragment, null).mDialog; + final ListView lv = dialog.getListView(); + + // The 1st account should be checked by default. + assertEquals("checked-item", 0, lv.getCheckedItemPosition()); + // There should be 4 accounts in the list. + assertEquals("count", 4, lv.getCount()); + // The sign-out button shouldn't exist + assertEquals(View.GONE, + dialog.getButton(DialogInterface.BUTTON_NEUTRAL).getVisibility()); + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility()); + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_POSITIVE).getVisibility()); + } + + @Test + public void testMultipleAccounts_currentAccount() { + when(mManagedProfileUtils.hasWorkProfile(any(Context.class))).thenReturn(false); + + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + final AlertDialog dialog = initDialog(fragment, "3@example.com").mDialog; + final ListView lv = dialog.getListView(); + + // The 3rd account should be checked by default. + assertEquals("checked-item", 2, lv.getCheckedItemPosition()); + // There should be 4 accounts in the list. + assertEquals("count", 4, lv.getCount()); + // The sign-out button should be shown + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_NEUTRAL).getVisibility()); + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility()); + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_POSITIVE).getVisibility()); + } + + private DialogHolder initDialog( + final AccountsSettingsFragment fragment, + final String selectedAccount) { + final DialogHolder dialogHolder = new DialogHolder(); + final CountDownLatch latch = new CountDownLatch(1); + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + final AlertDialog dialog = fragment.createAccountPicker( + new String[] { + "1@example.com", + "2@example.com", + "3@example.com", + "4@example.com"}, + selectedAccount, null /* positiveButtonListner */); + dialog.show(); + dialogHolder.mDialog = dialog; + latch.countDown(); + } + }); + + try { + latch.await(TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); + } catch (InterruptedException ex) { + fail(); + } + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + return dialogHolder; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/settings/SpacingAndPunctuationsTests.java b/tests/src/org/kelar/inputmethod/latin/settings/SpacingAndPunctuationsTests.java new file mode 100644 index 000000000..45a303639 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/settings/SpacingAndPunctuationsTests.java @@ -0,0 +1,499 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.settings; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import android.content.Context; +import android.content.res.Resources; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.SuggestedWords; +import org.kelar.inputmethod.latin.common.Constants; +import org.kelar.inputmethod.latin.utils.RunInLocale; + +import junit.framework.AssertionFailedError; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SpacingAndPunctuationsTests { + private static final int ARMENIAN_FULL_STOP = '\u0589'; + private static final int ARMENIAN_COMMA = '\u055D'; + + private int mScreenMetrics; + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + private boolean isPhone() { + return Constants.isPhone(mScreenMetrics); + } + + private boolean isTablet() { + return Constants.isTablet(mScreenMetrics); + } + + private SpacingAndPunctuations ENGLISH; + private SpacingAndPunctuations FRENCH; + private SpacingAndPunctuations GERMAN; + private SpacingAndPunctuations ARMENIAN; + private SpacingAndPunctuations THAI; + private SpacingAndPunctuations KHMER; + private SpacingAndPunctuations LAO; + private SpacingAndPunctuations ARABIC; + private SpacingAndPunctuations PERSIAN; + private SpacingAndPunctuations HEBREW; + + private SpacingAndPunctuations UNITED_STATES; + private SpacingAndPunctuations UNITED_KINGDOM; + private SpacingAndPunctuations CANADA_FRENCH; + private SpacingAndPunctuations SWISS_GERMAN; + private SpacingAndPunctuations INDIA_ENGLISH; + private SpacingAndPunctuations ARMENIA_ARMENIAN; + private SpacingAndPunctuations CAMBODIA_KHMER; + private SpacingAndPunctuations LAOS_LAO; + + @Before + public void setUp() throws Exception { + mScreenMetrics = Settings.readScreenMetrics(getContext().getResources()); + + // Language only + ENGLISH = getSpacingAndPunctuations(Locale.ENGLISH); + FRENCH = getSpacingAndPunctuations(Locale.FRENCH); + GERMAN = getSpacingAndPunctuations(Locale.GERMAN); + THAI = getSpacingAndPunctuations(new Locale("th")); + ARMENIAN = getSpacingAndPunctuations(new Locale("hy")); + KHMER = getSpacingAndPunctuations(new Locale("km")); + LAO = getSpacingAndPunctuations(new Locale("lo")); + ARABIC = getSpacingAndPunctuations(new Locale("ar")); + PERSIAN = getSpacingAndPunctuations(new Locale("fa")); + HEBREW = getSpacingAndPunctuations(new Locale("iw")); + + // Language and Country + UNITED_STATES = getSpacingAndPunctuations(Locale.US); + UNITED_KINGDOM = getSpacingAndPunctuations(Locale.UK); + CANADA_FRENCH = getSpacingAndPunctuations(Locale.CANADA_FRENCH); + SWISS_GERMAN = getSpacingAndPunctuations(new Locale("de", "CH")); + INDIA_ENGLISH = getSpacingAndPunctuations(new Locale("en", "IN")); + ARMENIA_ARMENIAN = getSpacingAndPunctuations(new Locale("hy", "AM")); + CAMBODIA_KHMER = getSpacingAndPunctuations(new Locale("km", "KH")); + LAOS_LAO = getSpacingAndPunctuations(new Locale("lo", "LA")); + } + + private SpacingAndPunctuations getSpacingAndPunctuations(final Locale locale) { + final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() { + @Override + protected SpacingAndPunctuations job(Resources res) { + return new SpacingAndPunctuations(res); + } + }; + return job.runInLocale(getContext().getResources(), locale); + } + + private static void testingStandardWordSeparator(final SpacingAndPunctuations sp) { + assertTrue("Tab", sp.isWordSeparator('\t')); + assertTrue("Newline", sp.isWordSeparator('\n')); + assertTrue("Space", sp.isWordSeparator(' ')); + assertTrue("Exclamation", sp.isWordSeparator('!')); + assertTrue("Quotation", sp.isWordSeparator('"')); + assertFalse("Number", sp.isWordSeparator('#')); + assertFalse("Dollar", sp.isWordSeparator('$')); + assertFalse("Percent", sp.isWordSeparator('%')); + assertTrue("Ampersand", sp.isWordSeparator('&')); + assertFalse("Apostrophe", sp.isWordSeparator('\'')); + assertTrue("L Paren", sp.isWordSeparator('(')); + assertTrue("R Paren", sp.isWordSeparator(')')); + assertTrue("Asterisk", sp.isWordSeparator('*')); + assertTrue("Plus", sp.isWordSeparator('+')); + assertTrue("Comma", sp.isWordSeparator(',')); + assertFalse("Minus", sp.isWordSeparator('-')); + assertTrue("Period", sp.isWordSeparator('.')); + assertTrue("Slash", sp.isWordSeparator('/')); + assertTrue("Colon", sp.isWordSeparator(':')); + assertTrue("Semicolon", sp.isWordSeparator(';')); + assertTrue("L Angle", sp.isWordSeparator('<')); + assertTrue("Equal", sp.isWordSeparator('=')); + assertTrue("R Angle", sp.isWordSeparator('>')); + assertTrue("Question", sp.isWordSeparator('?')); + assertFalse("Atmark", sp.isWordSeparator('@')); + assertTrue("L S Bracket", sp.isWordSeparator('[')); + assertFalse("B Slash", sp.isWordSeparator('\\')); + assertTrue("R S Bracket", sp.isWordSeparator(']')); + assertFalse("Circumflex", sp.isWordSeparator('^')); + assertTrue("Underscore", sp.isWordSeparator('_')); + assertFalse("Grave", sp.isWordSeparator('`')); + assertTrue("L C Brace", sp.isWordSeparator('{')); + assertTrue("V Line", sp.isWordSeparator('|')); + assertTrue("R C Brace", sp.isWordSeparator('}')); + assertFalse("Tilde", sp.isWordSeparator('~')); + } + + @Test + public void testWordSeparator() { + testingStandardWordSeparator(ENGLISH); + testingStandardWordSeparator(FRENCH); + testingStandardWordSeparator(CANADA_FRENCH); + testingStandardWordSeparator(ARMENIA_ARMENIAN); + assertTrue(ARMENIA_ARMENIAN.isWordSeparator(ARMENIAN_FULL_STOP)); + assertTrue(ARMENIA_ARMENIAN.isWordSeparator(ARMENIAN_COMMA)); + // TODO: We should fix these. + testingStandardWordSeparator(ARMENIAN); + assertFalse(ARMENIAN.isWordSeparator(ARMENIAN_FULL_STOP)); + assertFalse(ARMENIAN.isWordSeparator(ARMENIAN_COMMA)); + } + + private static void testingStandardWordConnector(final SpacingAndPunctuations sp) { + assertFalse("Tab", sp.isWordConnector('\t')); + assertFalse("Newline", sp.isWordConnector('\n')); + assertFalse("Space", sp.isWordConnector(' ')); + assertFalse("Exclamation", sp.isWordConnector('!')); + assertFalse("Quotation", sp.isWordConnector('"')); + assertFalse("Number", sp.isWordConnector('#')); + assertFalse("Dollar", sp.isWordConnector('$')); + assertFalse("Percent", sp.isWordConnector('%')); + assertFalse("Ampersand", sp.isWordConnector('&')); + assertTrue("Apostrophe", sp.isWordConnector('\'')); + assertFalse("L Paren", sp.isWordConnector('(')); + assertFalse("R Paren", sp.isWordConnector(')')); + assertFalse("Asterisk", sp.isWordConnector('*')); + assertFalse("Plus", sp.isWordConnector('+')); + assertFalse("Comma", sp.isWordConnector(',')); + assertTrue("Minus", sp.isWordConnector('-')); + assertFalse("Period", sp.isWordConnector('.')); + assertFalse("Slash", sp.isWordConnector('/')); + assertFalse("Colon", sp.isWordConnector(':')); + assertFalse("Semicolon", sp.isWordConnector(';')); + assertFalse("L Angle", sp.isWordConnector('<')); + assertFalse("Equal", sp.isWordConnector('=')); + assertFalse("R Angle", sp.isWordConnector('>')); + assertFalse("Question", sp.isWordConnector('?')); + assertFalse("Atmark", sp.isWordConnector('@')); + assertFalse("L S Bracket", sp.isWordConnector('[')); + assertFalse("B Slash", sp.isWordConnector('\\')); + assertFalse("R S Bracket", sp.isWordConnector(']')); + assertFalse("Circumflex", sp.isWordConnector('^')); + assertFalse("Underscore", sp.isWordConnector('_')); + assertFalse("Grave", sp.isWordConnector('`')); + assertFalse("L C Brace", sp.isWordConnector('{')); + assertFalse("V Line", sp.isWordConnector('|')); + assertFalse("R C Brace", sp.isWordConnector('}')); + assertFalse("Tilde", sp.isWordConnector('~')); + + } + + @Test + public void testWordConnector() { + testingStandardWordConnector(ENGLISH); + testingStandardWordConnector(FRENCH); + testingStandardWordConnector(CANADA_FRENCH); + testingStandardWordConnector(ARMENIA_ARMENIAN); + } + + private static void testingCommonPrecededBySpace(final SpacingAndPunctuations sp) { + assertFalse("Tab", sp.isUsuallyPrecededBySpace('\t')); + assertFalse("Newline", sp.isUsuallyPrecededBySpace('\n')); + assertFalse("Space", sp.isUsuallyPrecededBySpace(' ')); + //assertFalse("Exclamation", sp.isUsuallyPrecededBySpace('!')); + assertFalse("Quotation", sp.isUsuallyPrecededBySpace('"')); + assertFalse("Number", sp.isUsuallyPrecededBySpace('#')); + assertFalse("Dollar", sp.isUsuallyPrecededBySpace('$')); + assertFalse("Percent", sp.isUsuallyPrecededBySpace('%')); + assertTrue("Ampersand", sp.isUsuallyPrecededBySpace('&')); + assertFalse("Apostrophe", sp.isUsuallyPrecededBySpace('\'')); + assertTrue("L Paren", sp.isUsuallyPrecededBySpace('(')); + assertFalse("R Paren", sp.isUsuallyPrecededBySpace(')')); + assertFalse("Asterisk", sp.isUsuallyPrecededBySpace('*')); + assertFalse("Plus", sp.isUsuallyPrecededBySpace('+')); + assertFalse("Comma", sp.isUsuallyPrecededBySpace(',')); + assertFalse("Minus", sp.isUsuallyPrecededBySpace('-')); + assertFalse("Period", sp.isUsuallyPrecededBySpace('.')); + assertFalse("Slash", sp.isUsuallyPrecededBySpace('/')); + //assertFalse("Colon", sp.isUsuallyPrecededBySpace(':')); + //assertFalse("Semicolon", sp.isUsuallyPrecededBySpace(';')); + assertFalse("L Angle", sp.isUsuallyPrecededBySpace('<')); + assertFalse("Equal", sp.isUsuallyPrecededBySpace('=')); + assertFalse("R Angle", sp.isUsuallyPrecededBySpace('>')); + //assertFalse("Question", sp.isUsuallyPrecededBySpace('?')); + assertFalse("Atmark", sp.isUsuallyPrecededBySpace('@')); + assertTrue("L S Bracket", sp.isUsuallyPrecededBySpace('[')); + assertFalse("B Slash", sp.isUsuallyPrecededBySpace('\\')); + assertFalse("R S Bracket", sp.isUsuallyPrecededBySpace(']')); + assertFalse("Circumflex", sp.isUsuallyPrecededBySpace('^')); + assertFalse("Underscore", sp.isUsuallyPrecededBySpace('_')); + assertFalse("Grave", sp.isUsuallyPrecededBySpace('`')); + assertTrue("L C Brace", sp.isUsuallyPrecededBySpace('{')); + assertFalse("V Line", sp.isUsuallyPrecededBySpace('|')); + assertFalse("R C Brace", sp.isUsuallyPrecededBySpace('}')); + assertFalse("Tilde", sp.isUsuallyPrecededBySpace('~')); + } + + private static void testingStandardPrecededBySpace(final SpacingAndPunctuations sp) { + testingCommonPrecededBySpace(sp); + assertFalse("Exclamation", sp.isUsuallyPrecededBySpace('!')); + assertFalse("Colon", sp.isUsuallyPrecededBySpace(':')); + assertFalse("Semicolon", sp.isUsuallyPrecededBySpace(';')); + assertFalse("Question", sp.isUsuallyPrecededBySpace('?')); + } + + @Test + public void testIsUsuallyPrecededBySpace() { + testingStandardPrecededBySpace(ENGLISH); + testingCommonPrecededBySpace(FRENCH); + assertTrue("Exclamation", FRENCH.isUsuallyPrecededBySpace('!')); + assertTrue("Colon", FRENCH.isUsuallyPrecededBySpace(':')); + assertTrue("Semicolon", FRENCH.isUsuallyPrecededBySpace(';')); + assertTrue("Question", FRENCH.isUsuallyPrecededBySpace('?')); + testingCommonPrecededBySpace(CANADA_FRENCH); + assertFalse("Exclamation", CANADA_FRENCH.isUsuallyPrecededBySpace('!')); + assertTrue("Colon", CANADA_FRENCH.isUsuallyPrecededBySpace(':')); + assertFalse("Semicolon", CANADA_FRENCH.isUsuallyPrecededBySpace(';')); + assertFalse("Question", CANADA_FRENCH.isUsuallyPrecededBySpace('?')); + testingStandardPrecededBySpace(ARMENIA_ARMENIAN); + } + + private static void testingStandardFollowedBySpace(final SpacingAndPunctuations sp) { + assertFalse("Tab", sp.isUsuallyFollowedBySpace('\t')); + assertFalse("Newline", sp.isUsuallyFollowedBySpace('\n')); + assertFalse("Space", sp.isUsuallyFollowedBySpace(' ')); + assertTrue("Exclamation", sp.isUsuallyFollowedBySpace('!')); + assertFalse("Quotation", sp.isUsuallyFollowedBySpace('"')); + assertFalse("Number", sp.isUsuallyFollowedBySpace('#')); + assertFalse("Dollar", sp.isUsuallyFollowedBySpace('$')); + assertFalse("Percent", sp.isUsuallyFollowedBySpace('%')); + assertTrue("Ampersand", sp.isUsuallyFollowedBySpace('&')); + assertFalse("Apostrophe", sp.isUsuallyFollowedBySpace('\'')); + assertFalse("L Paren", sp.isUsuallyFollowedBySpace('(')); + assertTrue("R Paren", sp.isUsuallyFollowedBySpace(')')); + assertFalse("Asterisk", sp.isUsuallyFollowedBySpace('*')); + assertFalse("Plus", sp.isUsuallyFollowedBySpace('+')); + assertTrue("Comma", sp.isUsuallyFollowedBySpace(',')); + assertFalse("Minus", sp.isUsuallyFollowedBySpace('-')); + assertTrue("Period", sp.isUsuallyFollowedBySpace('.')); + assertFalse("Slash", sp.isUsuallyFollowedBySpace('/')); + assertTrue("Colon", sp.isUsuallyFollowedBySpace(':')); + assertTrue("Semicolon", sp.isUsuallyFollowedBySpace(';')); + assertFalse("L Angle", sp.isUsuallyFollowedBySpace('<')); + assertFalse("Equal", sp.isUsuallyFollowedBySpace('=')); + assertFalse("R Angle", sp.isUsuallyFollowedBySpace('>')); + assertTrue("Question", sp.isUsuallyFollowedBySpace('?')); + assertFalse("Atmark", sp.isUsuallyFollowedBySpace('@')); + assertFalse("L S Bracket", sp.isUsuallyFollowedBySpace('[')); + assertFalse("B Slash", sp.isUsuallyFollowedBySpace('\\')); + assertTrue("R S Bracket", sp.isUsuallyFollowedBySpace(']')); + assertFalse("Circumflex", sp.isUsuallyFollowedBySpace('^')); + assertFalse("Underscore", sp.isUsuallyFollowedBySpace('_')); + assertFalse("Grave", sp.isUsuallyFollowedBySpace('`')); + assertFalse("L C Brace", sp.isUsuallyFollowedBySpace('{')); + assertFalse("V Line", sp.isUsuallyFollowedBySpace('|')); + assertTrue("R C Brace", sp.isUsuallyFollowedBySpace('}')); + assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); + } + + @Test + public void testIsUsuallyFollowedBySpace() { + testingStandardFollowedBySpace(ENGLISH); + testingStandardFollowedBySpace(FRENCH); + testingStandardFollowedBySpace(CANADA_FRENCH); + testingStandardFollowedBySpace(ARMENIA_ARMENIAN); + assertTrue(ARMENIA_ARMENIAN.isUsuallyFollowedBySpace(ARMENIAN_FULL_STOP)); + assertTrue(ARMENIA_ARMENIAN.isUsuallyFollowedBySpace(ARMENIAN_COMMA)); + } + + private static void testingStandardSentenceSeparator(final SpacingAndPunctuations sp) { + assertFalse("Tab", sp.isUsuallyFollowedBySpace('\t')); + assertFalse("Newline", sp.isUsuallyFollowedBySpace('\n')); + assertFalse("Space", sp.isUsuallyFollowedBySpace(' ')); + assertFalse("Exclamation", sp.isUsuallyFollowedBySpace('!')); + assertFalse("Quotation", sp.isUsuallyFollowedBySpace('"')); + assertFalse("Number", sp.isUsuallyFollowedBySpace('#')); + assertFalse("Dollar", sp.isUsuallyFollowedBySpace('$')); + assertFalse("Percent", sp.isUsuallyFollowedBySpace('%')); + assertFalse("Ampersand", sp.isUsuallyFollowedBySpace('&')); + assertFalse("Apostrophe", sp.isUsuallyFollowedBySpace('\'')); + assertFalse("L Paren", sp.isUsuallyFollowedBySpace('(')); + assertFalse("R Paren", sp.isUsuallyFollowedBySpace(')')); + assertFalse("Asterisk", sp.isUsuallyFollowedBySpace('*')); + assertFalse("Plus", sp.isUsuallyFollowedBySpace('+')); + assertFalse("Comma", sp.isUsuallyFollowedBySpace(',')); + assertFalse("Minus", sp.isUsuallyFollowedBySpace('-')); + assertTrue("Period", sp.isUsuallyFollowedBySpace('.')); + assertFalse("Slash", sp.isUsuallyFollowedBySpace('/')); + assertFalse("Colon", sp.isUsuallyFollowedBySpace(':')); + assertFalse("Semicolon", sp.isUsuallyFollowedBySpace(';')); + assertFalse("L Angle", sp.isUsuallyFollowedBySpace('<')); + assertFalse("Equal", sp.isUsuallyFollowedBySpace('=')); + assertFalse("R Angle", sp.isUsuallyFollowedBySpace('>')); + assertFalse("Question", sp.isUsuallyFollowedBySpace('?')); + assertFalse("Atmark", sp.isUsuallyFollowedBySpace('@')); + assertFalse("L S Bracket", sp.isUsuallyFollowedBySpace('[')); + assertFalse("B Slash", sp.isUsuallyFollowedBySpace('\\')); + assertFalse("R S Bracket", sp.isUsuallyFollowedBySpace(']')); + assertFalse("Circumflex", sp.isUsuallyFollowedBySpace('^')); + assertFalse("Underscore", sp.isUsuallyFollowedBySpace('_')); + assertFalse("Grave", sp.isUsuallyFollowedBySpace('`')); + assertFalse("L C Brace", sp.isUsuallyFollowedBySpace('{')); + assertFalse("V Line", sp.isUsuallyFollowedBySpace('|')); + assertFalse("R C Brace", sp.isUsuallyFollowedBySpace('}')); + assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); + } + + @Test + public void testIsSentenceSeparator() { + testingStandardSentenceSeparator(ENGLISH); + try { + testingStandardSentenceSeparator(ARMENIA_ARMENIAN); + fail("Armenian Sentence Separator"); + } catch (final AssertionFailedError e) { + assertEquals("Period", e.getMessage()); + } + assertTrue(ARMENIA_ARMENIAN.isSentenceSeparator(ARMENIAN_FULL_STOP)); + assertFalse(ARMENIA_ARMENIAN.isSentenceSeparator(ARMENIAN_COMMA)); + } + + @Test + public void testLanguageHasSpace() { + assertTrue(ENGLISH.mCurrentLanguageHasSpaces); + assertTrue(FRENCH.mCurrentLanguageHasSpaces); + assertTrue(GERMAN.mCurrentLanguageHasSpaces); + assertFalse(THAI.mCurrentLanguageHasSpaces); + assertFalse(CAMBODIA_KHMER.mCurrentLanguageHasSpaces); + assertFalse(LAOS_LAO.mCurrentLanguageHasSpaces); + // TODO: We should fix these. + assertTrue(KHMER.mCurrentLanguageHasSpaces); + assertTrue(LAO.mCurrentLanguageHasSpaces); + } + + @Test + public void testUsesAmericanTypography() { + assertTrue(ENGLISH.mUsesAmericanTypography); + assertTrue(UNITED_STATES.mUsesAmericanTypography); + assertTrue(UNITED_KINGDOM.mUsesAmericanTypography); + assertTrue(INDIA_ENGLISH.mUsesAmericanTypography); + assertFalse(FRENCH.mUsesAmericanTypography); + assertFalse(GERMAN.mUsesAmericanTypography); + assertFalse(SWISS_GERMAN.mUsesAmericanTypography); + } + + @Test + public void testUsesGermanRules() { + assertFalse(ENGLISH.mUsesGermanRules); + assertFalse(FRENCH.mUsesGermanRules); + assertTrue(GERMAN.mUsesGermanRules); + assertTrue(SWISS_GERMAN.mUsesGermanRules); + } + + // Punctuations for phone. + private static final String[] PUNCTUATION_LABELS_PHONE = { + "!", "?", ",", ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_WORDS_PHONE_LTR = PUNCTUATION_LABELS_PHONE; + private static final String[] PUNCTUATION_WORDS_PHONE_HEBREW = { + "!", "?", ",", ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_" + }; + // U+061F: "؟" ARABIC QUESTION MARK + // U+060C: "،" ARABIC COMMA + // U+061B: "؛" ARABIC SEMICOLON + private static final String[] PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN = { + "!", "\u061F", "\u060C", ":", "\u061B", "\"", "(", ")", "'", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN = { + "!", "\u061F", "\u060C", ":", "\u061B", "\"", ")", "(", "'", "-", "/", "@", "_" + }; + + // Punctuations for tablet. + private static final String[] PUNCTUATION_LABELS_TABLET = { + ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_WORDS_TABLET_LTR = PUNCTUATION_LABELS_TABLET; + private static final String[] PUNCTUATION_WORDS_TABLET_HEBREW = { + ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN = { + "!", "\u061F", ":", "\u061B", "\"", "'", "(", ")", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN = { + "!", "\u061F", ":", "\u061B", "\"", "'", ")", "(", "-", "/", "@", "_" + }; + + private static void testingStandardPunctuationSuggestions(final SpacingAndPunctuations sp, + final String[] punctuationLabels, final String[] punctuationWords) { + final SuggestedWords suggestedWords = sp.mSuggestPuncList; + assertFalse("typedWordValid", suggestedWords.mTypedWordValid); + assertFalse("willAutoCorrect", suggestedWords.mWillAutoCorrect); + assertTrue("isPunctuationSuggestions", suggestedWords.isPunctuationSuggestions()); + assertFalse("isObsoleteSuggestions", suggestedWords.mIsObsoleteSuggestions); + assertFalse("isPrediction", suggestedWords.isPrediction()); + assertEquals("size", punctuationLabels.length, suggestedWords.size()); + for (int index = 0; index < suggestedWords.size(); index++) { + assertEquals("punctuation label at " + index, + punctuationLabels[index], suggestedWords.getLabel(index)); + assertEquals("punctuation word at " + index, + punctuationWords[index], suggestedWords.getWord(index)); + } + } + + @Test + public void testPhonePunctuationSuggestions() { + if (!isPhone()) { + return; + } + testingStandardPunctuationSuggestions(ENGLISH, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); + testingStandardPunctuationSuggestions(FRENCH, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); + testingStandardPunctuationSuggestions(GERMAN, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); + testingStandardPunctuationSuggestions(ARABIC, + PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN); + testingStandardPunctuationSuggestions(PERSIAN, + PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN); + testingStandardPunctuationSuggestions(HEBREW, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_HEBREW); + } + + @Test + public void testTabletPunctuationSuggestions() { + if (!isTablet()) { + return; + } + testingStandardPunctuationSuggestions(ENGLISH, + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); + testingStandardPunctuationSuggestions(FRENCH, + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); + testingStandardPunctuationSuggestions(GERMAN, + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); + testingStandardPunctuationSuggestions(ARABIC, + PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN); + testingStandardPunctuationSuggestions(PERSIAN, + PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN); + testingStandardPunctuationSuggestions(HEBREW, + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_HEBREW); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java b/tests/src/org/kelar/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java new file mode 100644 index 000000000..e68670de0 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java @@ -0,0 +1,77 @@ +/* + * 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 org.kelar.inputmethod.latin.spellcheck; + +import android.text.style.SuggestionSpan; + +import androidx.test.filters.LargeTest; + +import org.kelar.inputmethod.latin.InputTestsBase; + +@LargeTest +public class AndroidSpellCheckerServiceTest extends InputTestsBase { + public void testSpellchecker() { + changeLanguage("en_US"); + mEditText.setText("tgis "); + mEditText.setSelection(mEditText.getText().length()); + mEditText.onAttachedToWindow(); + sleep(1000); + runMessages(); + sleep(1000); + + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + // If no span, the following will crash + final String[] suggestions = span.getSuggestions(); + // For this test we consider "tgis" should yield at least 2 suggestions (at this moment + // it yields 5). + assertTrue(suggestions.length >= 2); + // We also assume the top suggestion should be "this". + assertEquals("Test basic spell checking", "this", suggestions[0]); + } + + public void testRussianSpellchecker() { + changeLanguage("ru"); + mEditText.onAttachedToWindow(); + mEditText.setText("годп "); + mEditText.setSelection(mEditText.getText().length()); + mEditText.onAttachedToWindow(); + sleep(1000); + runMessages(); + sleep(1000); + + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + // We don't ship with Russian LM + assertNull(span.getSpan()); + } + + public void testSpellcheckWithPeriods() { + changeLanguage("en_US"); + mEditText.setText("I'm.sure "); + mEditText.setSelection(mEditText.getText().length()); + mEditText.onAttachedToWindow(); + sleep(1000); + runMessages(); + sleep(1000); + + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); + // If no span, the following will crash + final String[] suggestions = span.getSuggestions(); + // The first suggestion should be "I'm sure". + assertEquals("Test spell checking of mistyped period for space", "I'm sure", + suggestions[0]); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java b/tests/src/org/kelar/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java new file mode 100644 index 000000000..e7f140f29 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.suggestions; + +import static junit.framework.TestCase.assertEquals; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.SuggestedWords; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SuggestionStripLayoutHelperTests { + private static void confirmShowTypedWord(final String message, final int inputType) { + assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord( + inputType, + false /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord( + inputType, + true /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord( + inputType, + false /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord( + inputType, + true /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + } + + @Test + public void testShouldShowTypedWord() { + confirmShowTypedWord("no input style", + SuggestedWords.INPUT_STYLE_NONE); + confirmShowTypedWord("application specifed", + SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED); + confirmShowTypedWord("recorrection", + SuggestedWords.INPUT_STYLE_RECORRECTION); + } + + @Test + public void testShouldOmitTypedWordWhileTyping() { + assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TYPING, + false /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TYPING, + true /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertTrue("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TYPING, + false /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + assertTrue("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TYPING, + true /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + } + + @Test + public void testShouldOmitTypedWordWhileGesturing() { + assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_UPDATE_BATCH, + false /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_UPDATE_BATCH, + true /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_UPDATE_BATCH, + false /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + assertTrue("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_UPDATE_BATCH, + true /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + } + + @Test + public void testShouldOmitTypedWordWhenGestured() { + assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TAIL_BATCH, + false /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TAIL_BATCH, + true /* gestureFloatingPreviewTextEnabled */, + false /* shouldShowUiToAcceptTypedWord */)); + assertTrue("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TAIL_BATCH, + false /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + assertTrue("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord( + SuggestedWords.INPUT_STYLE_TAIL_BATCH, + true /* gestureFloatingPreviewTextEnabled */, + true /* shouldShowUiToAcceptTypedWord */)); + } + + // Note that this unit test assumes that the number of suggested words in the suggestion strip + // is 3. + private static final int POSITION_OMIT = -1; + private static final int POSITION_LEFT = 0; + private static final int POSITION_CENTER = 1; + private static final int POSITION_RIGHT = 2; + + @Test + public void testGetPositionInSuggestionStrip() { + assertEquals("1st word without auto correction", POSITION_CENTER, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */, + false /* willAutoCorrect */, + false /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("2nd word without auto correction", POSITION_LEFT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */, + false /* willAutoCorrect */, + false /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("3rd word without auto correction", POSITION_RIGHT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + 2 /* indexInSuggestedWords */, + false /* willAutoCorrect */, + false /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + + assertEquals("typed word with auto correction", POSITION_LEFT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */, + true /* willAutoCorrect */, + false /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("2nd word with auto correction", POSITION_CENTER, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */, + true /* willAutoCorrect */, + false /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("3rd word with auto correction", POSITION_RIGHT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + 2 /* indexInSuggestedWords */, + true /* willAutoCorrect */, + false /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + + assertEquals("1st word without auto correction", POSITION_OMIT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */, + false /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("2nd word without auto correction", POSITION_CENTER, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */, + false /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("3rd word without auto correction", POSITION_LEFT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + 2 /* indexInSuggestedWords */, + false /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("4th word without auto correction", POSITION_RIGHT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + 3 /* indexInSuggestedWords */, + false /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + + assertEquals("typed word with auto correction", POSITION_OMIT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */, + true /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("2nd word with auto correction", POSITION_CENTER, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */, + true /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("3rd word with auto correction", POSITION_LEFT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + 2 /* indexInSuggestedWords */, + true /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + assertEquals("4th word with auto correction", POSITION_RIGHT, + SuggestionStripLayoutHelper.getPositionInSuggestionStrip( + 3 /* indexInSuggestedWords */, + true /* willAutoCorrect */, + true /* omitTypedWord */, + POSITION_CENTER /* centerPositionInStrip */, + POSITION_LEFT /* typedWordPositionWhenAutoCorrect */)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/touchinputconsumer/NullGestureConsumerTests.java b/tests/src/org/kelar/inputmethod/latin/touchinputconsumer/NullGestureConsumerTests.java new file mode 100644 index 000000000..85eeaf86c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/touchinputconsumer/NullGestureConsumerTests.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.touchinputconsumer; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests for GestureConsumer.NULL_GESTURE_CONSUMER. + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class NullGestureConsumerTests { + /** + * Tests that GestureConsumer.NULL_GESTURE_CONSUMER indicates that it won't consume gesture data + * and that its methods don't raise exceptions even for invalid data. + */ + @Test + public void testNullGestureConsumer() { + assertFalse(GestureConsumer.NULL_GESTURE_CONSUMER.willConsume()); + GestureConsumer.NULL_GESTURE_CONSUMER.onInit(null, null); + GestureConsumer.NULL_GESTURE_CONSUMER.onGestureStarted(null, null); + GestureConsumer.NULL_GESTURE_CONSUMER.onGestureCanceled(); + GestureConsumer.NULL_GESTURE_CONSUMER.onGestureCompleted(null); + GestureConsumer.NULL_GESTURE_CONSUMER.onImeSuggestionsProcessed(null, -1, -1, null); + } + + /** + * Tests that newInstance returns NULL_GESTURE_CONSUMER for invalid input. + */ + @Test + public void testNewInstanceGivesNullGestureConsumerForInvalidInputs() { + assertSame(GestureConsumer.NULL_GESTURE_CONSUMER, + GestureConsumer.newInstance(null, null, null, null)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java new file mode 100644 index 000000000..7c929c7a1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.utils; + +import static org.kelar.inputmethod.latin.common.Constants.Subtype.ExtraValue.ASCII_CAPABLE; +import static org.kelar.inputmethod.latin.common.Constants.Subtype.ExtraValue.EMOJI_CAPABLE; +import static org.kelar.inputmethod.latin.common.Constants.Subtype.ExtraValue.IS_ADDITIONAL_SUBTYPE; +import static org.kelar.inputmethod.latin.common.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET; +import static org.kelar.inputmethod.latin.common.Constants.Subtype.ExtraValue.UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME; +import static org.kelar.inputmethod.latin.common.Constants.Subtype.KEYBOARD_MODE; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.os.Build; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.compat.InputMethodSubtypeCompatUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class AdditionalSubtypeUtilsTests { + + /** + * Predictable subtype ID for en_US dvorak layout. This is actually a hash code calculated as + * follows. + * <code> + * final boolean isAuxiliary = false; + * final boolean overrideImplicitlyEnabledSubtype = false; + * final int SUBTYPE_ID_EN_US_DVORAK = Arrays.hashCode(new Object[] { + * "en_US", + * "keyboard", + * "KeyboardLayoutSet=dvorak" + * + ",AsciiCapable" + * + ",UntranslatableReplacementStringInSubtypeName=Dvorak" + * + ",EmojiCapable" + * + ",isAdditionalSubtype", + * isAuxiliary, + * overrideImplicitlyEnabledSubtype }); + * </code> + */ + private static int SUBTYPE_ID_EN_US_DVORAK = 0xb3c0cc56; + private static String EXTRA_VALUE_EN_US_DVORAK_ICS = + "KeyboardLayoutSet=dvorak" + + ",AsciiCapable" + + ",isAdditionalSubtype"; + private static String EXTRA_VALUE_EN_US_DVORAK_JELLY_BEAN = + "KeyboardLayoutSet=dvorak" + + ",AsciiCapable" + + ",UntranslatableReplacementStringInSubtypeName=Dvorak" + + ",isAdditionalSubtype"; + private static String EXTRA_VALUE_EN_US_DVORAK_KITKAT = + "KeyboardLayoutSet=dvorak" + + ",AsciiCapable" + + ",UntranslatableReplacementStringInSubtypeName=Dvorak" + + ",EmojiCapable" + + ",isAdditionalSubtype"; + + /** + * Predictable subtype ID for azerty layout. This is actually a hash code calculated as follows. + * <code> + * final boolean isAuxiliary = false; + * final boolean overrideImplicitlyEnabledSubtype = false; + * final int SUBTYPE_ID_ZZ_AZERTY = Arrays.hashCode(new Object[] { + * "zz", + * "keyboard", + * "KeyboardLayoutSet=azerty" + * + ",AsciiCapable" + * + ",EmojiCapable" + * + ",isAdditionalSubtype", + * isAuxiliary, + * overrideImplicitlyEnabledSubtype }); + * </code> + */ + private static int SUBTYPE_ID_ZZ_AZERTY = 0x5b6be697; + private static String EXTRA_VALUE_ZZ_AZERTY_ICS = + "KeyboardLayoutSet=azerty" + + ",AsciiCapable" + + ",isAdditionalSubtype"; + private static String EXTRA_VALUE_ZZ_AZERTY_KITKAT = + "KeyboardLayoutSet=azerty" + + ",AsciiCapable" + + ",EmojiCapable" + + ",isAdditionalSubtype"; + + @Before + public void setUp() throws Exception { + final Context context = InstrumentationRegistry.getTargetContext(); + SubtypeLocaleUtils.init(context); + } + + private static void assertEnUsDvorak(InputMethodSubtype subtype) { + assertEquals("en_US", subtype.getLocale()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + assertEquals(EXTRA_VALUE_EN_US_DVORAK_KITKAT, subtype.getExtraValue()); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + assertEquals(EXTRA_VALUE_EN_US_DVORAK_JELLY_BEAN, subtype.getExtraValue()); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + assertEquals(EXTRA_VALUE_EN_US_DVORAK_ICS, subtype.getExtraValue()); + } + assertTrue(subtype.containsExtraValueKey(ASCII_CAPABLE)); + assertTrue(InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)); + // TODO: Enable following test + // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + // assertTrue(InputMethodSubtypeCompatUtils.isAsciiCapableWithAPI(subtype)); + // } + assertTrue(subtype.containsExtraValueKey(EMOJI_CAPABLE)); + assertTrue(subtype.containsExtraValueKey(IS_ADDITIONAL_SUBTYPE)); + assertEquals("dvorak", subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET)); + assertEquals("Dvorak", subtype.getExtraValueOf(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)); + assertEquals(KEYBOARD_MODE, subtype.getMode()); + assertEquals(SUBTYPE_ID_EN_US_DVORAK, subtype.hashCode()); + } + + private static void assertAzerty(InputMethodSubtype subtype) { + assertEquals("zz", subtype.getLocale()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + assertEquals(EXTRA_VALUE_ZZ_AZERTY_KITKAT, subtype.getExtraValue()); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + assertEquals(EXTRA_VALUE_ZZ_AZERTY_ICS, subtype.getExtraValue()); + } + assertTrue(subtype.containsExtraValueKey(ASCII_CAPABLE)); + assertTrue(InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)); + // TODO: Enable following test + // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + // assertTrue(InputMethodSubtypeCompatUtils.isAsciiCapableWithAPI(subtype)); + // } + assertTrue(subtype.containsExtraValueKey(EMOJI_CAPABLE)); + assertTrue(subtype.containsExtraValueKey(IS_ADDITIONAL_SUBTYPE)); + assertEquals("azerty", subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET)); + assertFalse(subtype.containsExtraValueKey(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)); + assertEquals(KEYBOARD_MODE, subtype.getMode()); + assertEquals(SUBTYPE_ID_ZZ_AZERTY, subtype.hashCode()); + } + + @Test + public void testRestorable() { + final InputMethodSubtype EN_US_DVORAK = + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.US.toString(), "dvorak"); + final InputMethodSubtype ZZ_AZERTY = + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + SubtypeLocaleUtils.NO_LANGUAGE, "azerty"); + assertEnUsDvorak(EN_US_DVORAK); + assertAzerty(ZZ_AZERTY); + + // Make sure the subtype can be stored and restored in a deterministic manner. + final InputMethodSubtype[] subtypes = { EN_US_DVORAK, ZZ_AZERTY }; + final String prefSubtype = AdditionalSubtypeUtils.createPrefSubtypes(subtypes); + final InputMethodSubtype[] restoredSubtypes = + AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype); + assertEquals(2, restoredSubtypes.length); + final InputMethodSubtype restored_EN_US_DVORAK = restoredSubtypes[0]; + final InputMethodSubtype restored_ZZ_AZERTY = restoredSubtypes[1]; + + assertEnUsDvorak(restored_EN_US_DVORAK); + assertAzerty(restored_ZZ_AZERTY); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/AsyncResultHolderTests.java b/tests/src/org/kelar/inputmethod/latin/utils/AsyncResultHolderTests.java new file mode 100644 index 000000000..b85e4f38c --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/AsyncResultHolderTests.java @@ -0,0 +1,84 @@ +/* + * 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; + +import android.util.Log; + +import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@MediumTest +@RunWith(AndroidJUnit4.class) +public class AsyncResultHolderTests { + static final String TAG = AsyncResultHolderTests.class.getSimpleName(); + + private static final int TIMEOUT_IN_MILLISECONDS = 500; + private static final int MARGIN_IN_MILLISECONDS = 250; + private static final int DEFAULT_VALUE = 2; + private static final int SET_VALUE = 1; + + private static <T> void setAfterGivenTime(final AsyncResultHolder<T> holder, final T value, + final long time) { + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + Log.d(TAG, "Exception while sleeping", e); + } + holder.set(value); + } + }).start(); + } + + @Test + public void testGetWithoutSet() { + final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test"); + final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); + assertEquals(DEFAULT_VALUE, resultValue); + } + + @Test + public void testGetBeforeSet() { + final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test"); + setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS + MARGIN_IN_MILLISECONDS); + final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); + assertEquals(DEFAULT_VALUE, resultValue); + } + + @Test + public void testGetAfterSet() { + final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test"); + holder.set(SET_VALUE); + final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); + assertEquals(SET_VALUE, resultValue); + } + + @Test + public void testGetBeforeTimeout() { + final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test"); + setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS - MARGIN_IN_MILLISECONDS); + final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); + assertEquals(SET_VALUE, resultValue); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/ByteArrayDictBuffer.java b/tests/src/org/kelar/inputmethod/latin/utils/ByteArrayDictBuffer.java new file mode 100644 index 000000000..6c0854824 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/ByteArrayDictBuffer.java @@ -0,0 +1,81 @@ +/* + * 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 org.kelar.inputmethod.latin.utils; + +import org.kelar.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; + +/** + * This class provides an implementation for the FusionDictionary buffer interface that is backed + * by a simpled byte array. It allows to create a binary dictionary in memory. + */ +public final class ByteArrayDictBuffer implements DictBuffer { + private byte[] mBuffer; + private int mPosition; + + public ByteArrayDictBuffer(final byte[] buffer) { + mBuffer = buffer; + mPosition = 0; + } + + @Override + public int readUnsignedByte() { + return mBuffer[mPosition++] & 0xFF; + } + + @Override + public int readUnsignedShort() { + final int retval = readUnsignedByte(); + return (retval << 8) + readUnsignedByte(); + } + + @Override + public int readUnsignedInt24() { + final int retval = readUnsignedShort(); + return (retval << 8) + readUnsignedByte(); + } + + @Override + public int readInt() { + final int retval = readUnsignedShort(); + return (retval << 16) + readUnsignedShort(); + } + + @Override + public int position() { + return mPosition; + } + + @Override + public void position(int position) { + mPosition = position; + } + + @Override + public void put(final byte b) { + mBuffer[mPosition++] = b; + } + + @Override + public int limit() { + return mBuffer.length - 1; + } + + @Override + public int capacity() { + return mBuffer.length; + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/CapsModeUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/CapsModeUtilsTests.java new file mode 100644 index 000000000..75463929f --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/CapsModeUtilsTests.java @@ -0,0 +1,162 @@ +/* + * 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import android.content.res.Resources; +import android.text.TextUtils; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.common.LocaleUtils; +import org.kelar.inputmethod.latin.settings.SpacingAndPunctuations; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class CapsModeUtilsTests { + private static void onePathForCaps(final CharSequence cs, final int expectedResult, + final int mask, final SpacingAndPunctuations sp, final boolean hasSpaceBefore) { + final int oneTimeResult = expectedResult & mask; + assertEquals("After >" + cs + "<", oneTimeResult, + CapsModeUtils.getCapsMode(cs, mask, sp, hasSpaceBefore)); + } + + private static void allPathsForCaps(final CharSequence cs, final int expectedResult, + final SpacingAndPunctuations sp, final boolean hasSpaceBefore) { + final int c = TextUtils.CAP_MODE_CHARACTERS; + final int w = TextUtils.CAP_MODE_WORDS; + final int s = TextUtils.CAP_MODE_SENTENCES; + onePathForCaps(cs, expectedResult, c | w | s, sp, hasSpaceBefore); + onePathForCaps(cs, expectedResult, w | s, sp, hasSpaceBefore); + onePathForCaps(cs, expectedResult, c | s, sp, hasSpaceBefore); + onePathForCaps(cs, expectedResult, c | w, sp, hasSpaceBefore); + onePathForCaps(cs, expectedResult, c, sp, hasSpaceBefore); + onePathForCaps(cs, expectedResult, w, sp, hasSpaceBefore); + onePathForCaps(cs, expectedResult, s, sp, hasSpaceBefore); + } + + @Test + public void testGetCapsMode() { + final int c = TextUtils.CAP_MODE_CHARACTERS; + final int w = TextUtils.CAP_MODE_WORDS; + final int s = TextUtils.CAP_MODE_SENTENCES; + final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() { + @Override + protected SpacingAndPunctuations job(final Resources res) { + return new SpacingAndPunctuations(res); + } + }; + final Resources res = InstrumentationRegistry.getTargetContext().getResources(); + SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH); + allPathsForCaps("", c | w | s, sp, false); + allPathsForCaps("Word", c, sp, false); + allPathsForCaps("Word.", c, sp, false); + allPathsForCaps("Word ", c | w, sp, false); + allPathsForCaps("Word. ", c | w | s, sp, false); + allPathsForCaps("Word..", c, sp, false); + allPathsForCaps("Word.. ", c | w | s, sp, false); + allPathsForCaps("Word... ", c | w | s, sp, false); + allPathsForCaps("Word ... ", c | w | s, sp, false); + allPathsForCaps("Word . ", c | w, sp, false); + allPathsForCaps("In the U.S ", c | w, sp, false); + allPathsForCaps("In the U.S. ", c | w, sp, false); + allPathsForCaps("Some stuff (e.g. ", c | w, sp, false); + allPathsForCaps("In the U.S.. ", c | w | s, sp, false); + allPathsForCaps("\"Word.\" ", c | w | s, sp, false); + allPathsForCaps("\"Word\". ", c | w | s, sp, false); + allPathsForCaps("\"Word\" ", c | w, sp, false); + + // Test for phantom space + allPathsForCaps("Word", c | w, sp, true); + allPathsForCaps("Word.", c | w | s, sp, true); + + // Tests after some whitespace + allPathsForCaps("Word\n", c | w | s, sp, false); + allPathsForCaps("Word\n", c | w | s, sp, true); + allPathsForCaps("Word\n ", c | w | s, sp, true); + allPathsForCaps("Word.\n", c | w | s, sp, false); + allPathsForCaps("Word.\n", c | w | s, sp, true); + allPathsForCaps("Word.\n ", c | w | s, sp, true); + + sp = job.runInLocale(res, Locale.FRENCH); + allPathsForCaps("\"Word.\" ", c | w, sp, false); + allPathsForCaps("\"Word\". ", c | w | s, sp, false); + allPathsForCaps("\"Word\" ", c | w, sp, false); + + // Test special case for German. German does not capitalize at the start of a + // line when the previous line starts with a comma. It does in other cases. + sp = job.runInLocale(res, Locale.GERMAN); + allPathsForCaps("Liebe Sara,\n", c | w, sp, false); + allPathsForCaps("Liebe Sara,\n", c | w, sp, true); + allPathsForCaps("Liebe Sara, \n ", c | w, sp, false); + allPathsForCaps("Liebe Sara \n ", c | w | s, sp, false); + allPathsForCaps("Liebe Sara.\n ", c | w | s, sp, false); + sp = job.runInLocale(res, Locale.ENGLISH); + allPathsForCaps("Liebe Sara,\n", c | w | s, sp, false); + allPathsForCaps("Liebe Sara,\n", c | w | s, sp, true); + allPathsForCaps("Liebe Sara, \n ", c | w | s, sp, false); + allPathsForCaps("Liebe Sara \n ", c | w | s, sp, false); + allPathsForCaps("Liebe Sara.\n ", c | w | s, sp, false); + + // Test armenian period + sp = job.runInLocale(res, LocaleUtils.constructLocaleFromString("hy_AM")); + assertTrue("Period is not sentence separator in Armenian", + !sp.isSentenceSeparator('.')); + assertTrue("Sentence separator is Armenian period in Armenian", + sp.isSentenceSeparator(0x589)); + // No space : capitalize only if MODE_CHARACTERS + allPathsForCaps("Word", c, sp, false); + allPathsForCaps("Word.", c, sp, false); + // Space, but no armenian period : capitalize if MODE_WORDS but not SENTENCES + allPathsForCaps("Word. ", c | w, sp, false); + // Armenian period : capitalize if MODE_SENTENCES + allPathsForCaps("Word\u0589 ", c | w | s, sp, false); + + // Test for sentence terminators + sp = job.runInLocale(res, Locale.ENGLISH); + allPathsForCaps("Word? ", c | w | s, sp, false); + allPathsForCaps("Word?", c | w | s, sp, true); + allPathsForCaps("Word?", c, sp, false); + allPathsForCaps("Word! ", c | w | s, sp, false); + allPathsForCaps("Word!", c | w | s, sp, true); + allPathsForCaps("Word!", c, sp, false); + allPathsForCaps("Word; ", c | w, sp, false); + allPathsForCaps("Word;", c | w, sp, true); + allPathsForCaps("Word;", c, sp, false); + // Test for sentence terminators in Greek + sp = job.runInLocale(res, LocaleUtils.constructLocaleFromString("el")); + allPathsForCaps("Word? ", c | w | s, sp, false); + allPathsForCaps("Word?", c | w | s, sp, true); + allPathsForCaps("Word?", c, sp, false); + allPathsForCaps("Word! ", c | w | s, sp, false); + allPathsForCaps("Word!", c | w | s, sp, true); + allPathsForCaps("Word!", c, sp, false); + // In Greek ";" is the question mark and it terminates the sentence + allPathsForCaps("Word; ", c | w | s, sp, false); + allPathsForCaps("Word;", c | w | s, sp, true); + allPathsForCaps("Word;", c, sp, false); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/CollectionUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/CollectionUtilsTests.java new file mode 100644 index 000000000..390e88828 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/CollectionUtilsTests.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.common.CollectionUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Tests for {@link CollectionUtils}. + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class CollectionUtilsTests { + /** + * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} fails as expected + * with some invalid inputs. + */ + @Test + public void testArrayAsListFailure() { + final String[] array = { "0", "1" }; + // Negative start + try { + CollectionUtils.arrayAsList(array, -1, 1); + fail("Failed to catch start < 0"); + } catch (final IllegalArgumentException e) { + assertEquals("Invalid start: -1 end: 1 with array.length: 2", e.getMessage()); + } + // start > end + try { + CollectionUtils.arrayAsList(array, 1, -1); + fail("Failed to catch start > end"); + } catch (final IllegalArgumentException e) { + assertEquals("Invalid start: 1 end: -1 with array.length: 2", e.getMessage()); + } + // end > array.length + try { + CollectionUtils.arrayAsList(array, 1, 3); + fail("Failed to catch end > array.length"); + } catch (final IllegalArgumentException e) { + assertEquals("Invalid start: 1 end: 3 with array.length: 2", e.getMessage()); + } + } + + /** + * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} gives the expected + * results for a few valid inputs. + */ + @Test + public void testArrayAsList() { + final ArrayList<String> empty = new ArrayList<>(); + assertEquals(empty, CollectionUtils.arrayAsList(new String[] {}, 0, 0)); + final String[] array = { "0", "1", "2", "3", "4" }; + assertEquals(empty, CollectionUtils.arrayAsList(array, 0, 0)); + assertEquals(empty, CollectionUtils.arrayAsList(array, 1, 1)); + assertEquals(empty, CollectionUtils.arrayAsList(array, array.length, array.length)); + final ArrayList<String> expected123 = new ArrayList<>(Arrays.asList("1", "2", "3")); + assertEquals(expected123, CollectionUtils.arrayAsList(array, 1, 4)); + } + + /** + * Tests that {@link CollectionUtils#isNullOrEmpty(java.util.Collection)} gives the expected + * results for a few cases. + */ + @Test + public void testIsNullOrEmpty() { + assertTrue(CollectionUtils.isNullOrEmpty((List<String>) null)); + assertTrue(CollectionUtils.isNullOrEmpty((Map<String, String>) null)); + assertTrue(CollectionUtils.isNullOrEmpty(new ArrayList<String>())); + assertTrue(CollectionUtils.isNullOrEmpty(new HashMap<String, String>())); + assertFalse(CollectionUtils.isNullOrEmpty(Collections.singletonList("Not empty"))); + assertFalse(CollectionUtils.isNullOrEmpty(Collections.singletonMap("Not", "empty"))); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/DictionaryInfoUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/DictionaryInfoUtilsTests.java new file mode 100644 index 000000000..4c30750f5 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/DictionaryInfoUtilsTests.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.content.res.Resources; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.common.LocaleUtils; +import org.kelar.inputmethod.latin.settings.SpacingAndPunctuations; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class DictionaryInfoUtilsTests { + @Test + public void testLooksValidForDictionaryInsertion() { + final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() { + @Override + protected SpacingAndPunctuations job(final Resources res) { + return new SpacingAndPunctuations(res); + } + }; + final Resources res = InstrumentationRegistry.getTargetContext().getResources(); + final SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH); + assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("aochaueo", sp)); + assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("", sp)); + assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("ao-ch'aueo", sp)); + assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("2908743256", sp)); + assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("31aochaueo", sp)); + assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("akeo raeoch oerch .", + sp)); + assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("!!!", sp)); + } + + @Test + public void testGetMainDictId() { + assertEquals("main:en", + DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("en"))); + assertEquals("main:en_us", + DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("en_US"))); + assertEquals("main:en_gb", + DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("en_GB"))); + + assertEquals("main:es", + DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("es"))); + assertEquals("main:es_us", + DictionaryInfoUtils.getMainDictId(LocaleUtils.constructLocaleFromString("es_US"))); + + assertEquals("main:en_us_posix", DictionaryInfoUtils.getMainDictId( + LocaleUtils.constructLocaleFromString("en_US_POSIX"))); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/ExecutorUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/ExecutorUtilsTests.java new file mode 100644 index 000000000..440e527f1 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/ExecutorUtilsTests.java @@ -0,0 +1,65 @@ +/* + * 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; + +import android.util.Log; + +import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Unit tests for {@link ExecutorUtils}. + */ +@MediumTest +@RunWith(AndroidJUnit4.class) +public class ExecutorUtilsTests { + private static final String TAG = ExecutorUtilsTests.class.getSimpleName(); + + private static final int NUM_OF_TASKS = 10; + private static final int DELAY_FOR_WAITING_TASKS_MILLISECONDS = 500; + + @Test + public void testExecute() { + final ExecutorService executor = + ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD); + final AtomicInteger v = new AtomicInteger(0); + for (int i = 0; i < NUM_OF_TASKS; ++i) { + executor.execute(new Runnable() { + @Override + public void run() { + v.incrementAndGet(); + } + }); + } + try { + executor.awaitTermination(DELAY_FOR_WAITING_TASKS_MILLISECONDS, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + Log.d(TAG, "Exception while sleeping.", e); + } + + assertEquals(NUM_OF_TASKS, v.get()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/ImportantNoticeUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/ImportantNoticeUtilsTests.java new file mode 100644 index 000000000..65abd16fd --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/ImportantNoticeUtilsTests.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.utils; + +import static org.kelar.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_CONTACTS_NOTICE; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.content.SharedPreferences; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.settings.SettingsValues; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@MediumTest +@RunWith(AndroidJUnit4.class) +public class ImportantNoticeUtilsTests { + + private ImportantNoticePreferences mImportantNoticePreferences; + + @Mock private SettingsValues mMockSettingsValues; + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + private static class ImportantNoticePreferences { + private final SharedPreferences mPref; + + private Long mLastTime; + + public ImportantNoticePreferences(final Context context) { + mPref = ImportantNoticeUtils.getImportantNoticePreferences(context); + } + + private Integer getInt(final String key) { + if (mPref.contains(key)) { + return mPref.getInt(key, 0); + } + return null; + } + + public Long getLong(final String key) { + if (mPref.contains(key)) { + return mPref.getLong(key, 0); + } + return null; + } + + private void putInt(final String key, final Integer value) { + if (value == null) { + removePreference(key); + } else { + mPref.edit().putInt(key, value).apply(); + } + } + + private void putLong(final String key, final Long value) { + if (value == null) { + removePreference(key); + } else { + mPref.edit().putLong(key, value).apply(); + } + } + + private void removePreference(final String key) { + mPref.edit().remove(key).apply(); + } + + public void save() { + mLastTime = getLong(KEY_TIMESTAMP_OF_CONTACTS_NOTICE); + } + + public void restore() { + putLong(KEY_TIMESTAMP_OF_CONTACTS_NOTICE, mLastTime); + } + + public void clear() { + removePreference(KEY_TIMESTAMP_OF_CONTACTS_NOTICE); + } + } + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + mImportantNoticePreferences = new ImportantNoticePreferences(getContext()); + mImportantNoticePreferences.save(); + when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true); + } + + @After + public void tearDown() throws Exception { + mImportantNoticePreferences.restore(); + } + + @Test + public void testPersonalizationSetting() { + mImportantNoticePreferences.clear(); + + // Personalization enabled. + when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true); + assertEquals("Current boolean with personalization enabled", true, + ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues)); + + // Personalization disabled. + when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(false); + assertEquals("Current boolean with personalization disabled", false, + ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/JsonUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/JsonUtilsTests.java new file mode 100644 index 000000000..5a323ef51 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/JsonUtilsTests.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class JsonUtilsTests { + @Test + public void testJsonUtils() { + final Object[] objs = new Object[] { 1, "aaa", "bbb", 3 }; + final List<Object> objArray = Arrays.asList(objs); + final String str = JsonUtils.listToJsonStr(objArray); + final List<Object> newObjArray = JsonUtils.jsonStrToList(str); + for (int i = 0; i < objs.length; ++i) { + assertEquals(objs[i], newObjArray.get(i)); + } + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java new file mode 100644 index 000000000..007c69fd2 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2014 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 org.kelar.inputmethod.latin.utils; + +import static org.kelar.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_FULL_LOCALE; +import static org.kelar.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_LANGUAGE_ONLY; +import static org.kelar.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_NONE; + +import static org.junit.Assert.assertEquals; + +import android.content.Context; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.RichInputMethodManager; +import org.kelar.inputmethod.latin.RichInputMethodSubtype; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Locale; + +import javax.annotation.Nonnull; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class LanguageOnSpacebarUtilsTests { + private RichInputMethodManager mRichImm; + + RichInputMethodSubtype EN_US_QWERTY; + RichInputMethodSubtype EN_GB_QWERTY; + RichInputMethodSubtype FR_AZERTY; + RichInputMethodSubtype FR_CA_QWERTY; + RichInputMethodSubtype FR_CH_SWISS; + RichInputMethodSubtype FR_CH_QWERTY; + RichInputMethodSubtype FR_CH_QWERTZ; + RichInputMethodSubtype IW_HEBREW; + RichInputMethodSubtype ZZ_QWERTY; + + @Before + public void setUp() throws Exception { + final Context context = InstrumentationRegistry.getTargetContext(); + RichInputMethodManager.init(context); + mRichImm = RichInputMethodManager.getInstance(); + + EN_US_QWERTY = findSubtypeOf(Locale.US.toString(), "qwerty"); + EN_GB_QWERTY = findSubtypeOf(Locale.UK.toString(), "qwerty"); + FR_AZERTY = findSubtypeOf(Locale.FRENCH.toString(), "azerty"); + FR_CA_QWERTY = findSubtypeOf(Locale.CANADA_FRENCH.toString(), "qwerty"); + FR_CH_SWISS = findSubtypeOf("fr_CH", "swiss"); + FR_CH_QWERTZ = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype("fr_CH", "qwertz")); + FR_CH_QWERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype("fr_CH", "qwerty")); + IW_HEBREW = findSubtypeOf("iw", "hebrew"); + ZZ_QWERTY = findSubtypeOf(SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"); + } + + @Nonnull + private RichInputMethodSubtype findSubtypeOf(final String localeString, + final String keyboardLayoutSetName) { + final InputMethodSubtype subtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + localeString, keyboardLayoutSetName); + if (subtype == null) { + throw new RuntimeException("Can't find subtype of " + localeString + " with " + + keyboardLayoutSetName); + } + return new RichInputMethodSubtype(subtype); + } + + private static void enableSubtypes(final RichInputMethodSubtype ... subtypes) { + final ArrayList<InputMethodSubtype> enabledSubtypes = new ArrayList<>(); + for (final RichInputMethodSubtype subtype : subtypes) { + enabledSubtypes.add(subtype.getRawSubtype()); + } + LanguageOnSpacebarUtils.setEnabledSubtypes(enabledSubtypes); + } + + private static void assertFormatType(final RichInputMethodSubtype subtype, + final boolean implicitlyEnabledSubtype, final Locale systemLocale, + final int expectedFormat) { + LanguageOnSpacebarUtils.onSubtypeChanged(subtype, implicitlyEnabledSubtype, systemLocale); + assertEquals(subtype.getLocale() + " implicitly=" + implicitlyEnabledSubtype + + " in " + systemLocale, expectedFormat, + LanguageOnSpacebarUtils.getLanguageOnSpacebarFormatType(subtype)); + } + + @Test + public void testOneSubtypeImplicitlyEnabled() { + enableSubtypes(EN_US_QWERTY); + assertFormatType(EN_US_QWERTY, true, Locale.US, FORMAT_TYPE_NONE); + + enableSubtypes(EN_GB_QWERTY); + assertFormatType(EN_GB_QWERTY, true, Locale.UK, FORMAT_TYPE_NONE); + + enableSubtypes(FR_AZERTY); + assertFormatType(FR_AZERTY, true, Locale.FRANCE, FORMAT_TYPE_NONE); + + enableSubtypes(FR_CA_QWERTY); + assertFormatType(FR_CA_QWERTY, true, Locale.CANADA_FRENCH, FORMAT_TYPE_NONE); + } + + @Test + public void testOneSubtypeExplicitlyEnabled() { + enableSubtypes(EN_US_QWERTY); + assertFormatType(EN_US_QWERTY, false, Locale.UK, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(EN_US_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + + enableSubtypes(EN_GB_QWERTY); + assertFormatType(EN_GB_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(EN_GB_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + + enableSubtypes(FR_AZERTY); + assertFormatType(FR_AZERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_AZERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + + enableSubtypes(FR_CA_QWERTY); + assertFormatType(FR_CA_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CA_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + } + + @Test + public void testOneSubtypeImplicitlyEnabledWithNoLanguageSubtype() { + final Locale Locale_IW = new Locale("iw"); + enableSubtypes(IW_HEBREW, ZZ_QWERTY); + // TODO: Should this be FORMAT_TYPE_NONE? + assertFormatType(IW_HEBREW, true, Locale_IW, FORMAT_TYPE_LANGUAGE_ONLY); + // TODO: Should this be FORMAT_TYPE_NONE? + assertFormatType(ZZ_QWERTY, true, Locale_IW, FORMAT_TYPE_FULL_LOCALE); + } + + @Test + public void testTwoSubtypesExplicitlyEnabled() { + enableSubtypes(EN_US_QWERTY, FR_AZERTY); + assertFormatType(EN_US_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_AZERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(EN_US_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_AZERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(EN_US_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_AZERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + + enableSubtypes(EN_US_QWERTY, ZZ_QWERTY); + assertFormatType(EN_US_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(ZZ_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(EN_US_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(ZZ_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_FULL_LOCALE); + + } + + @Test + public void testMultiSubtypeWithSameLanuageAndSameLayout() { + // Explicitly enable en_US, en_GB, fr_FR, and no language keyboards. + enableSubtypes(EN_US_QWERTY, EN_GB_QWERTY, FR_CA_QWERTY, ZZ_QWERTY); + + assertFormatType(EN_US_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(EN_GB_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CA_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(ZZ_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE); + + assertFormatType(EN_US_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(EN_GB_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CA_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(ZZ_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE); + } + + @Test + public void testMultiSubtypesWithSameLanguageButHaveDifferentLayout() { + enableSubtypes(FR_AZERTY, FR_CA_QWERTY, FR_CH_SWISS, FR_CH_QWERTZ); + + assertFormatType(FR_AZERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CA_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_SWISS, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_QWERTZ, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + + assertFormatType(FR_AZERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CA_QWERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_SWISS, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_QWERTZ, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + + assertFormatType(FR_AZERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CA_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_SWISS, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_QWERTZ, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + } + + @Test + public void testMultiSubtypesWithSameLanguageAndMayHaveSameLayout() { + enableSubtypes(FR_AZERTY, FR_CA_QWERTY, FR_CH_SWISS, FR_CH_QWERTY, FR_CH_QWERTZ); + + assertFormatType(FR_AZERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CA_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CH_SWISS, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CH_QWERTZ, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY); + + assertFormatType(FR_AZERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CA_QWERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CH_SWISS, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_QWERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CH_QWERTZ, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY); + + assertFormatType(FR_AZERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CA_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CH_SWISS, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + assertFormatType(FR_CH_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE); + assertFormatType(FR_CH_QWERTZ, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/RecapitalizeStatusTests.java b/tests/src/org/kelar/inputmethod/latin/utils/RecapitalizeStatusTests.java new file mode 100644 index 000000000..1ce091b0b --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/RecapitalizeStatusTests.java @@ -0,0 +1,207 @@ +/* + * 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.common.Constants; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class RecapitalizeStatusTests { + private static final int[] SPACE = { Constants.CODE_SPACE }; + + @Test + public void testTrim() { + final RecapitalizeStatus status = new RecapitalizeStatus(); + status.start(30, 40, "abcdefghij", Locale.ENGLISH, SPACE); + status.trim(); + assertEquals("abcdefghij", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(40, status.getNewCursorEnd()); + + status.start(30, 44, " abcdefghij", Locale.ENGLISH, SPACE); + status.trim(); + assertEquals("abcdefghij", status.getRecapitalizedString()); + assertEquals(34, status.getNewCursorStart()); + assertEquals(44, status.getNewCursorEnd()); + + status.start(30, 40, "abcdefgh ", Locale.ENGLISH, SPACE); + status.trim(); + assertEquals("abcdefgh", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(38, status.getNewCursorEnd()); + + status.start(30, 45, " abcdefghij ", Locale.ENGLISH, SPACE); + status.trim(); + assertEquals("abcdefghij", status.getRecapitalizedString()); + assertEquals(33, status.getNewCursorStart()); + assertEquals(43, status.getNewCursorEnd()); + } + + @Test + public void testRotate() { + final RecapitalizeStatus status = new RecapitalizeStatus(); + status.start(29, 40, "abcd efghij", Locale.ENGLISH, SPACE); + status.rotate(); + assertEquals("Abcd Efghij", status.getRecapitalizedString()); + assertEquals(29, status.getNewCursorStart()); + assertEquals(40, status.getNewCursorEnd()); + status.rotate(); + assertEquals("ABCD EFGHIJ", status.getRecapitalizedString()); + status.rotate(); + assertEquals("abcd efghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("Abcd Efghij", status.getRecapitalizedString()); + + status.start(29, 40, "Abcd Efghij", Locale.ENGLISH, SPACE); + status.rotate(); + assertEquals("ABCD EFGHIJ", status.getRecapitalizedString()); + assertEquals(29, status.getNewCursorStart()); + assertEquals(40, status.getNewCursorEnd()); + status.rotate(); + assertEquals("abcd efghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("Abcd Efghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("ABCD EFGHIJ", status.getRecapitalizedString()); + + status.start(29, 40, "ABCD EFGHIJ", Locale.ENGLISH, SPACE); + status.rotate(); + assertEquals("abcd efghij", status.getRecapitalizedString()); + assertEquals(29, status.getNewCursorStart()); + assertEquals(40, status.getNewCursorEnd()); + status.rotate(); + assertEquals("Abcd Efghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("ABCD EFGHIJ", status.getRecapitalizedString()); + status.rotate(); + assertEquals("abcd efghij", status.getRecapitalizedString()); + + status.start(29, 39, "AbCDefghij", Locale.ENGLISH, SPACE); + status.rotate(); + assertEquals("abcdefghij", status.getRecapitalizedString()); + assertEquals(29, status.getNewCursorStart()); + assertEquals(39, status.getNewCursorEnd()); + status.rotate(); + assertEquals("Abcdefghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("ABCDEFGHIJ", status.getRecapitalizedString()); + status.rotate(); + assertEquals("AbCDefghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("abcdefghij", status.getRecapitalizedString()); + + status.start(29, 40, "Abcd efghij", Locale.ENGLISH, SPACE); + status.rotate(); + assertEquals("abcd efghij", status.getRecapitalizedString()); + assertEquals(29, status.getNewCursorStart()); + assertEquals(40, status.getNewCursorEnd()); + status.rotate(); + assertEquals("Abcd Efghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("ABCD EFGHIJ", status.getRecapitalizedString()); + status.rotate(); + assertEquals("Abcd efghij", status.getRecapitalizedString()); + status.rotate(); + assertEquals("abcd efghij", status.getRecapitalizedString()); + + status.start(30, 34, "grüß", Locale.GERMAN, SPACE); + status.rotate(); + assertEquals("Grüß", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(34, status.getNewCursorEnd()); + status.rotate(); + assertEquals("GRÜSS", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(35, status.getNewCursorEnd()); + status.rotate(); + assertEquals("grüß", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(34, status.getNewCursorEnd()); + status.rotate(); + assertEquals("Grüß", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(34, status.getNewCursorEnd()); + + status.start(30, 33, "œuf", Locale.FRENCH, SPACE); + status.rotate(); + assertEquals("Œuf", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + status.rotate(); + assertEquals("ŒUF", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + status.rotate(); + assertEquals("œuf", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + status.rotate(); + assertEquals("Œuf", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + + status.start(30, 33, "œUf", Locale.FRENCH, SPACE); + status.rotate(); + assertEquals("œuf", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + status.rotate(); + assertEquals("Œuf", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + status.rotate(); + assertEquals("ŒUF", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + status.rotate(); + assertEquals("œUf", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + status.rotate(); + assertEquals("œuf", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(33, status.getNewCursorEnd()); + + status.start(30, 35, "école", Locale.FRENCH, SPACE); + status.rotate(); + assertEquals("École", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(35, status.getNewCursorEnd()); + status.rotate(); + assertEquals("ÉCOLE", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(35, status.getNewCursorEnd()); + status.rotate(); + assertEquals("école", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(35, status.getNewCursorEnd()); + status.rotate(); + assertEquals("École", status.getRecapitalizedString()); + assertEquals(30, status.getNewCursorStart()); + assertEquals(35, status.getNewCursorEnd()); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/ResourceUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/ResourceUtilsTests.java new file mode 100644 index 000000000..7e7f24d49 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/ResourceUtilsTests.java @@ -0,0 +1,163 @@ +/* + * 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.HashMap; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class ResourceUtilsTests { + @Test + public void testFindConstantForKeyValuePairsSimple() { + final HashMap<String,String> anyKeyValue = new HashMap<>(); + anyKeyValue.put("anyKey", "anyValue"); + final HashMap<String,String> nullKeyValue = null; + final HashMap<String,String> emptyKeyValue = new HashMap<>(); + + final String[] nullArray = null; + assertNull(ResourceUtils.findConstantForKeyValuePairs(anyKeyValue, nullArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(emptyKeyValue, nullArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(nullKeyValue, nullArray)); + + final String[] emptyArray = {}; + assertNull(ResourceUtils.findConstantForKeyValuePairs(anyKeyValue, emptyArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(emptyKeyValue, emptyArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(nullKeyValue, emptyArray)); + + final String HARDWARE_KEY = "HARDWARE"; + final String[] array = { + ",defaultValue", + "HARDWARE=grouper,0.3", + "HARDWARE=mako,0.4", + "HARDWARE=manta,0.2", + "HARDWARE=mako,0.5", + }; + + final HashMap<String,String> keyValues = new HashMap<>(); + keyValues.put(HARDWARE_KEY, "grouper"); + assertEquals("0.3", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + keyValues.put(HARDWARE_KEY, "mako"); + assertEquals("0.4", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + keyValues.put(HARDWARE_KEY, "manta"); + assertEquals("0.2", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + + keyValues.clear(); + keyValues.put("hardware", "grouper"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "MAKO"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + keyValues.put(HARDWARE_KEY, "mantaray"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + + assertNull(ResourceUtils.findConstantForKeyValuePairs(emptyKeyValue, array)); + } + + @Test + public void testFindConstantForKeyValuePairsCombined() { + final String HARDWARE_KEY = "HARDWARE"; + final String MODEL_KEY = "MODEL"; + final String MANUFACTURER_KEY = "MANUFACTURER"; + final String[] array = { + ",defaultValue", + "no_comma", + "error_pattern,0.1", + "HARDWARE=grouper:MANUFACTURER=asus,0.3", + "HARDWARE=mako:MODEL=Nexus 4,0.4", + "HARDWARE=manta:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" + }; + final String[] failArray = { + ",defaultValue", + "HARDWARE=grouper:MANUFACTURER=ASUS,0.3", + "HARDWARE=mako:MODEL=Nexus_4,0.4", + "HARDWARE=mantaray:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" + }; + + final HashMap<String,String> keyValues = new HashMap<>(); + keyValues.put(HARDWARE_KEY, "grouper"); + keyValues.put(MODEL_KEY, "Nexus 7"); + keyValues.put(MANUFACTURER_KEY, "asus"); + assertEquals("0.3", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray)); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "mako"); + keyValues.put(MODEL_KEY, "Nexus 4"); + keyValues.put(MANUFACTURER_KEY, "LGE"); + assertEquals("0.4", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray)); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "manta"); + keyValues.put(MODEL_KEY, "Nexus 10"); + keyValues.put(MANUFACTURER_KEY, "samsung"); + assertEquals("0.2", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray)); + keyValues.put(HARDWARE_KEY, "mantaray"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + assertEquals("0.2", ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray)); + } + + @Test + public void testFindConstantForKeyValuePairsRegexp() { + final String HARDWARE_KEY = "HARDWARE"; + final String MODEL_KEY = "MODEL"; + final String MANUFACTURER_KEY = "MANUFACTURER"; + final String[] array = { + ",defaultValue", + "no_comma", + "HARDWARE=error_regexp:MANUFACTURER=error[regexp,0.1", + "HARDWARE=grouper|tilapia:MANUFACTURER=asus,0.3", + "HARDWARE=[mM][aA][kK][oO]:MODEL=Nexus 4,0.4", + "HARDWARE=manta.*:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" + }; + + final HashMap<String,String> keyValues = new HashMap<>(); + keyValues.put(HARDWARE_KEY, "grouper"); + keyValues.put(MODEL_KEY, "Nexus 7"); + keyValues.put(MANUFACTURER_KEY, "asus"); + assertEquals("0.3", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + keyValues.put(HARDWARE_KEY, "tilapia"); + assertEquals("0.3", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "mako"); + keyValues.put(MODEL_KEY, "Nexus 4"); + keyValues.put(MANUFACTURER_KEY, "LGE"); + assertEquals("0.4", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + keyValues.put(HARDWARE_KEY, "MAKO"); + assertEquals("0.4", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "manta"); + keyValues.put(MODEL_KEY, "Nexus 10"); + keyValues.put(MANUFACTURER_KEY, "samsung"); + assertEquals("0.2", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + keyValues.put(HARDWARE_KEY, "mantaray"); + assertEquals("0.2", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/SpannableStringUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/SpannableStringUtilsTests.java new file mode 100644 index 000000000..f5546a04d --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/SpannableStringUtilsTests.java @@ -0,0 +1,244 @@ +/* + * 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.text.SpannableString; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.SpannedString; +import android.text.style.SuggestionSpan; +import android.text.style.URLSpan; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SpannableStringUtilsTests { + + private Context getContext() { + return InstrumentationRegistry.getTargetContext(); + } + + @Test + public void testConcatWithSuggestionSpansOnly() { + SpannableStringBuilder s = new SpannableStringBuilder("test string\ntest string\n" + + "test string\ntest string\ntest string\ntest string\ntest string\ntest string\n" + + "test string\ntest string\n"); + final int N = 10; + for (int i = 0; i < N; ++i) { + // Put a PARAGRAPH-flagged span that should not be found in the result. + s.setSpan(new SuggestionSpan(getContext(), + new String[] {"" + i}, Spanned.SPAN_PARAGRAPH), + i * 12, i * 12 + 12, Spanned.SPAN_PARAGRAPH); + // Put a normal suggestion span that should be found in the result. + s.setSpan(new SuggestionSpan(getContext(), new String[] {"" + i}, 0), i, i * 2, 0); + // Put a URL span than should not be found in the result. + s.setSpan(new URLSpan("http://a"), i, i * 2, 0); + } + + final CharSequence a = s.subSequence(0, 15); + final CharSequence b = s.subSequence(15, s.length()); + final Spanned result = + (Spanned)SpannableStringUtils.concatWithNonParagraphSuggestionSpansOnly(a, b); + + Object[] spans = result.getSpans(0, result.length(), SuggestionSpan.class); + for (int i = 0; i < spans.length; i++) { + final int flags = result.getSpanFlags(spans[i]); + assertEquals("Should not find a span with PARAGRAPH flag", + flags & Spanned.SPAN_PARAGRAPH, 0); + assertTrue("Should be a SuggestionSpan", spans[i] instanceof SuggestionSpan); + } + } + + private static void assertSpanCount(final int expectedCount, final CharSequence cs) { + final int actualCount; + if (cs instanceof Spanned) { + final Spanned spanned = (Spanned) cs; + actualCount = spanned.getSpans(0, spanned.length(), Object.class).length; + } else { + actualCount = 0; + } + assertEquals(expectedCount, actualCount); + } + + private static void assertSpan(final CharSequence cs, final Object expectedSpan, + final int expectedStart, final int expectedEnd, final int expectedFlags) { + assertTrue(cs instanceof Spanned); + final Spanned spanned = (Spanned) cs; + final Object[] actualSpans = spanned.getSpans(0, spanned.length(), Object.class); + for (Object actualSpan : actualSpans) { + if (actualSpan == expectedSpan) { + final int actualStart = spanned.getSpanStart(actualSpan); + final int actualEnd = spanned.getSpanEnd(actualSpan); + final int actualFlags = spanned.getSpanFlags(actualSpan); + assertEquals(expectedStart, actualStart); + assertEquals(expectedEnd, actualEnd); + assertEquals(expectedFlags, actualFlags); + return; + } + } + assertTrue(false); + } + + @Test + public void testSplitCharSequenceWithSpan() { + // text: " a bcd efg hij " + // span1: ^^^^^^^ + // span2: ^^^^^ + // span3: ^ + final SpannableString spannableString = new SpannableString(" a bcd efg hij "); + final Object span1 = new Object(); + final Object span2 = new Object(); + final Object span3 = new Object(); + final int SPAN1_FLAGS = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; + final int SPAN2_FLAGS = Spanned.SPAN_EXCLUSIVE_INCLUSIVE; + final int SPAN3_FLAGS = Spanned.SPAN_INCLUSIVE_INCLUSIVE; + spannableString.setSpan(span1, 0, 7, SPAN1_FLAGS); + spannableString.setSpan(span2, 0, 5, SPAN2_FLAGS); + spannableString.setSpan(span3, 12, 13, SPAN3_FLAGS); + final CharSequence[] charSequencesFromSpanned = SpannableStringUtils.split( + spannableString, " ", true /* preserveTrailingEmptySegmengs */); + final CharSequence[] charSequencesFromString = SpannableStringUtils.split( + spannableString.toString(), " ", true /* preserveTrailingEmptySegmengs */); + + + assertEquals(7, charSequencesFromString.length); + assertEquals(7, charSequencesFromSpanned.length); + + // text: "" + // span1: ^ + // span2: ^ + // span3: + assertEquals("", charSequencesFromString[0].toString()); + assertSpanCount(0, charSequencesFromString[0]); + assertEquals("", charSequencesFromSpanned[0].toString()); + assertSpanCount(2, charSequencesFromSpanned[0]); + assertSpan(charSequencesFromSpanned[0], span1, 0, 0, SPAN1_FLAGS); + assertSpan(charSequencesFromSpanned[0], span2, 0, 0, SPAN2_FLAGS); + + // text: "a" + // span1: ^ + // span2: ^ + // span3: + assertEquals("a", charSequencesFromString[1].toString()); + assertSpanCount(0, charSequencesFromString[1]); + assertEquals("a", charSequencesFromSpanned[1].toString()); + assertSpanCount(2, charSequencesFromSpanned[1]); + assertSpan(charSequencesFromSpanned[1], span1, 0, 1, SPAN1_FLAGS); + assertSpan(charSequencesFromSpanned[1], span2, 0, 1, SPAN2_FLAGS); + + // text: "bcd" + // span1: ^^^ + // span2: ^^ + // span3: + assertEquals("bcd", charSequencesFromString[2].toString()); + assertSpanCount(0, charSequencesFromString[2]); + assertEquals("bcd", charSequencesFromSpanned[2].toString()); + assertSpanCount(2, charSequencesFromSpanned[2]); + assertSpan(charSequencesFromSpanned[2], span1, 0, 3, SPAN1_FLAGS); + assertSpan(charSequencesFromSpanned[2], span2, 0, 2, SPAN2_FLAGS); + + // text: "efg" + // span1: + // span2: + // span3: + assertEquals("efg", charSequencesFromString[3].toString()); + assertSpanCount(0, charSequencesFromString[3]); + assertEquals("efg", charSequencesFromSpanned[3].toString()); + assertSpanCount(0, charSequencesFromSpanned[3]); + + // text: "hij" + // span1: + // span2: + // span3: ^ + assertEquals("hij", charSequencesFromString[4].toString()); + assertSpanCount(0, charSequencesFromString[4]); + assertEquals("hij", charSequencesFromSpanned[4].toString()); + assertSpanCount(1, charSequencesFromSpanned[4]); + assertSpan(charSequencesFromSpanned[4], span3, 1, 2, SPAN3_FLAGS); + + // text: "" + // span1: + // span2: + // span3: + assertEquals("", charSequencesFromString[5].toString()); + assertSpanCount(0, charSequencesFromString[5]); + assertEquals("", charSequencesFromSpanned[5].toString()); + assertSpanCount(0, charSequencesFromSpanned[5]); + + // text: "" + // span1: + // span2: + // span3: + assertEquals("", charSequencesFromString[6].toString()); + assertSpanCount(0, charSequencesFromString[6]); + assertEquals("", charSequencesFromSpanned[6].toString()); + assertSpanCount(0, charSequencesFromSpanned[6]); + } + + @Test + public void testSplitCharSequencePreserveTrailingEmptySegmengs() { + assertEquals(1, SpannableStringUtils.split("", " ", + false /* preserveTrailingEmptySegmengs */).length); + assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ", + false /* preserveTrailingEmptySegmengs */).length); + + assertEquals(1, SpannableStringUtils.split("", " ", + true /* preserveTrailingEmptySegmengs */).length); + assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ", + true /* preserveTrailingEmptySegmengs */).length); + + assertEquals(0, SpannableStringUtils.split(" ", " ", + false /* preserveTrailingEmptySegmengs */).length); + assertEquals(0, SpannableStringUtils.split(new SpannedString(" "), " ", + false /* preserveTrailingEmptySegmengs */).length); + + assertEquals(2, SpannableStringUtils.split(" ", " ", + true /* preserveTrailingEmptySegmengs */).length); + assertEquals(2, SpannableStringUtils.split(new SpannedString(" "), " ", + true /* preserveTrailingEmptySegmengs */).length); + + assertEquals(3, SpannableStringUtils.split("a b c ", " ", + false /* preserveTrailingEmptySegmengs */).length); + assertEquals(3, SpannableStringUtils.split(new SpannedString("a b c "), " ", + false /* preserveTrailingEmptySegmengs */).length); + + assertEquals(5, SpannableStringUtils.split("a b c ", " ", + true /* preserveTrailingEmptySegmengs */).length); + assertEquals(5, SpannableStringUtils.split(new SpannedString("a b c "), " ", + true /* preserveTrailingEmptySegmengs */).length); + + assertEquals(6, SpannableStringUtils.split("a b ", " ", + false /* preserveTrailingEmptySegmengs */).length); + assertEquals(6, SpannableStringUtils.split(new SpannedString("a b "), " ", + false /* preserveTrailingEmptySegmengs */).length); + + assertEquals(7, SpannableStringUtils.split("a b ", " ", + true /* preserveTrailingEmptySegmengs */).length); + assertEquals(7, SpannableStringUtils.split(new SpannedString("a b "), " ", + true /* preserveTrailingEmptySegmengs */).length); + } +} diff --git a/tests/src/org/kelar/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/org/kelar/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java new file mode 100644 index 000000000..77b960a95 --- /dev/null +++ b/tests/src/org/kelar/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java @@ -0,0 +1,498 @@ +/* + * Copyright (C) 2011 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 org.kelar.inputmethod.latin.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.content.res.Resources; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodSubtype; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.kelar.inputmethod.latin.R; +import org.kelar.inputmethod.latin.RichInputMethodManager; +import org.kelar.inputmethod.latin.RichInputMethodSubtype; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.Locale; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class SubtypeLocaleUtilsTests { + // All input method subtypes of LatinIME. + private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>(); + + private RichInputMethodManager mRichImm; + private Resources mRes; + private InputMethodSubtype mSavedAddtionalSubtypes[]; + + InputMethodSubtype EN_US; + InputMethodSubtype EN_GB; + InputMethodSubtype ES_US; + InputMethodSubtype FR; + InputMethodSubtype FR_CA; + InputMethodSubtype FR_CH; + InputMethodSubtype DE; + InputMethodSubtype DE_CH; + InputMethodSubtype HI; + InputMethodSubtype SR; + InputMethodSubtype ZZ; + InputMethodSubtype DE_QWERTY; + InputMethodSubtype FR_QWERTZ; + InputMethodSubtype EN_US_AZERTY; + InputMethodSubtype EN_UK_DVORAK; + InputMethodSubtype ES_US_COLEMAK; + InputMethodSubtype ZZ_AZERTY; + InputMethodSubtype ZZ_PC; + + // 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 + + @Before + public void setUp() throws Exception { + final Context context = InstrumentationRegistry.getTargetContext(); + mRes = context.getResources(); + RichInputMethodManager.init(context); + mRichImm = RichInputMethodManager.getInstance(); + + // Save and reset additional subtypes + mSavedAddtionalSubtypes = mRichImm.getAdditionalSubtypes(); + 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(); + for (int index = 0; index < subtypeCount; index++) { + final InputMethodSubtype subtype = imi.getSubtypeAt(index); + mSubtypesList.add(new RichInputMethodSubtype(subtype)); + } + + EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.US.toString(), "qwerty"); + EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.UK.toString(), "qwerty"); + ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "es_US", "spanish"); + FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.FRENCH.toString(), "azerty"); + FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.CANADA_FRENCH.toString(), "qwerty"); + FR_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "fr_CH", "swiss"); + DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + 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( + Locale.GERMAN.toString(), "qwerty"); + FR_QWERTZ = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.FRENCH.toString(), "qwertz"); + EN_US_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.US.toString(), "azerty"); + EN_UK_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.UK.toString(), "dvorak"); + ES_US_COLEMAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + "es_US", "colemak"); + ZZ_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + SubtypeLocaleUtils.NO_LANGUAGE, "azerty"); + ZZ_PC = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + 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"); + } + } + + @After + public void tearDown() throws Exception { + // Restore additional subtypes. + mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes); + } + + @Test + public void testAllFullDisplayName() { + for (final RichInputMethodSubtype subtype : mSubtypesList) { + final String subtypeName = SubtypeLocaleUtils + .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype()); + if (subtype.isNoLanguage()) { + final String layoutName = SubtypeLocaleUtils + .getKeyboardLayoutSetDisplayName(subtype.getRawSubtype()); + assertTrue(subtypeName, subtypeName.contains(layoutName)); + } else { + final String languageName = SubtypeLocaleUtils + .getSubtypeLocaleDisplayNameInSystemLocale(subtype.getLocale().toString()); + assertTrue(subtypeName, subtypeName.contains(languageName)); + } + } + } + + @Test + public void testKeyboardLayoutSetName() { + assertEquals("en_US", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_US)); + assertEquals("en_GB", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_GB)); + assertEquals("es_US", "spanish", SubtypeLocaleUtils.getKeyboardLayoutSetName(ES_US)); + assertEquals("fr", "azerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR)); + assertEquals("fr_CA", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_CA)); + 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)); + + assertEquals("de qwerty", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_QWERTY)); + assertEquals("fr qwertz", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_QWERTZ)); + assertEquals("en_US azerty", "azerty", + SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_US_AZERTY)); + assertEquals("en_UK dvorak", "dvorak", + SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_UK_DVORAK)); + assertEquals("es_US colemak", "colemak", + 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 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) + + @Test + public void testPredefinedSubtypesInEnglishSystemLocale() { + final RunInLocale<Void> tests = new RunInLocale<Void>() { + @Override + protected Void job(final Resources res) { + assertEquals("en_US", "English (US)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_US)); + assertEquals("en_GB", "English (UK)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_GB)); + assertEquals("es_US", "Spanish (US)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US)); + assertEquals("fr", "French", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR)); + assertEquals("fr_CA", "French (Canada)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CA)); + assertEquals("fr_CH", "French (Switzerland)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CH)); + assertEquals("de", "German", + 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)); + // 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; + } + }; + tests.runInLocale(mRes, Locale.ENGLISH); + } + + @Test + public void testAdditionalSubtypesInEnglishSystemLocale() { + final RunInLocale<Void> tests = new RunInLocale<Void>() { + @Override + protected Void job(final Resources res) { + assertEquals("fr qwertz", "French (QWERTZ)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_QWERTZ)); + assertEquals("de qwerty", "German (QWERTY)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_QWERTY)); + assertEquals("en_US azerty", "English (US) (AZERTY)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_US_AZERTY)); + assertEquals("en_UK dvorak","English (UK) (Dvorak)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_UK_DVORAK)); + assertEquals("es_US colemak", "Spanish (US) (Colemak)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US_COLEMAK)); + assertEquals("zz azerty", "Alphabet (AZERTY)", + 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; + } + }; + tests.runInLocale(mRes, Locale.ENGLISH); + } + + // InputMethodSubtype's display name in system locale (fr). + // 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 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) + + @Test + public void testPredefinedSubtypesInFrenchSystemLocale() { + final RunInLocale<Void> tests = new RunInLocale<Void>() { + @Override + protected Void job(final Resources res) { + assertEquals("en_US", "Anglais (États-Unis)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_US)); + assertEquals("en_GB", "Anglais (Royaume-Uni)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_GB)); + assertEquals("es_US", "Espagnol (États-Unis)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US)); + assertEquals("fr", "Français", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR)); + assertEquals("fr_CA", "Français (Canada)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CA)); + assertEquals("fr_CH", "Français (Suisse)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CH)); + assertEquals("de", "Allemand", + 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)); + // 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; + } + }; + tests.runInLocale(mRes, Locale.FRENCH); + } + + @Test + public void testAdditionalSubtypesInFrenchSystemLocale() { + final RunInLocale<Void> tests = new RunInLocale<Void>() { + @Override + protected Void job(final Resources res) { + assertEquals("fr qwertz", "Français (QWERTZ)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_QWERTZ)); + assertEquals("de qwerty", "Allemand (QWERTY)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_QWERTY)); + assertEquals("en_US azerty", "Anglais (États-Unis) (AZERTY)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_US_AZERTY)); + assertEquals("en_UK dvorak", "Anglais (Royaume-Uni) (Dvorak)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_UK_DVORAK)); + assertEquals("es_US colemak", "Espagnol (États-Unis) (Colemak)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US_COLEMAK)); + assertEquals("zz azerty", "Alphabet latin (AZERTY)", + 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) + + @Test + 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) + + @Test + 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) { + assertEquals("sr_ZZ", "Српски (латиница)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN)); + assertEquals("sr_ZZ", "Српски (QWERTY)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN_QWERTY)); + } + return null; + } + }; + tests.runInLocale(mRes, new Locale("sr")); + } + + @Test + public void testIsRtlLanguage() { + // Known Right-to-Left language subtypes. + final InputMethodSubtype ARABIC = mRichImm + .findSubtypeByLocaleAndKeyboardLayoutSet("ar", "arabic"); + assertNotNull("Arabic", ARABIC); + final InputMethodSubtype FARSI = mRichImm + .findSubtypeByLocaleAndKeyboardLayoutSet("fa", "farsi"); + assertNotNull("Farsi", FARSI); + final InputMethodSubtype HEBREW = mRichImm + .findSubtypeByLocaleAndKeyboardLayoutSet("iw", "hebrew"); + assertNotNull("Hebrew", HEBREW); + + for (final RichInputMethodSubtype subtype : mSubtypesList) { + final InputMethodSubtype rawSubtype = subtype.getRawSubtype(); + final String subtypeName = SubtypeLocaleUtils + .getSubtypeDisplayNameInSystemLocale(rawSubtype); + if (rawSubtype.equals(ARABIC) || rawSubtype.equals(FARSI) + || rawSubtype.equals(HEBREW)) { + assertTrue(subtypeName, subtype.isRtlSubtype()); + } else { + assertFalse(subtypeName, subtype.isRtlSubtype()); + } + } + } +} |