diff options
author | 2010-12-14 15:31:47 +0900 | |
---|---|---|
committer | 2010-12-17 17:18:28 +0900 | |
commit | 9b6d1d52d91f8f18952ae3841f4bb0d7309bfc0e (patch) | |
tree | 2907b32c1509f69850a3ca6dd6ac36a60341fbd9 /tests/src | |
parent | f61287ae48c17d2afb4c9b971cbdd3ee0cc055e2 (diff) | |
download | latinime-9b6d1d52d91f8f18952ae3841f4bb0d7309bfc0e.tar.gz latinime-9b6d1d52d91f8f18952ae3841f4bb0d7309bfc0e.tar.xz latinime-9b6d1d52d91f8f18952ae3841f4bb0d7309bfc0e.zip |
Add popupKeyboardTemplate attribute to Keyboard
This change
- introduces the popupKeyboardTemplate attribute of Keyboard to
specify XML Keyboard file for popup mini keyboard.
- introduces the maxPopupKeyboardColumn attribute of Keyboard to
specify the maximum column of popup mini keyboard.
- changes the content format of the popupCharacters attribute of Key.
It now represents keyLabel, codes and keyTextOutput of each key of
popup mini keyboard using CSV format.
Bug: 2214959
Change-Id: I539e310f7e38a049ee193de0b4ad5d7afdce37b1
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java | 120 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java | 205 |
2 files changed, 325 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java b/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java new file mode 100644 index 000000000..3f2b7f4d5 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java @@ -0,0 +1,120 @@ +/* + * 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 com.android.inputmethod.keyboard; + +import com.android.inputmethod.keyboard.KeyStyles.EmptyKeyStyle; + +import android.test.AndroidTestCase; +import android.text.TextUtils; + +public class KeyStylesTests extends AndroidTestCase { + private static void assertNumberFormatException(String message, String value) { + try { + EmptyKeyStyle.parseCsvInt(value); + fail(message); + } catch (NumberFormatException nfe) { + // success. + } + } + + private static void assertIntArray(String message, String value, Integer ... expected) { + final int actual[] = EmptyKeyStyle.parseCsvInt(value); + assertSame(message + ": result length", expected.length, actual.length); + for (int i = 0; i < actual.length; i++) { + assertEquals(message + ": result at " + i + ":", (int)expected[i], actual[i]); + } + } + + private static String format(String message, Object expected, Object actual) { + return message + " expected:<" + expected + "> but was:<" + actual + ">"; + } + + private static void assertTextArray(String message, CharSequence value, + CharSequence ... expected) { + final CharSequence actual[] = EmptyKeyStyle.parseCsvText(value); + if (expected.length == 0) { + assertNull(message, actual); + return; + } + assertSame(message + ": result length", expected.length, actual.length); + for (int i = 0; i < actual.length; i++) { + final boolean equals = TextUtils.equals(expected[i], actual[i]); + assertTrue(format(message + ": result at " + i + ":", expected[i], actual[i]), equals); + } + } + + public void testParseCsvInt() { + assertIntArray("Empty string", ""); + assertNumberFormatException("Spaces", " "); + assertNumberFormatException("Non-decimal number", "abc"); + assertIntArray("Single number", "123", 123); + assertIntArray("Negative number", "-123", -123); + assertNumberFormatException("Hexadecimal number", "1b2b"); + assertIntArray("Multiple numbers", "123,456", 123, 456); + assertNumberFormatException("Non-decimal numbers", "123,abc"); + assertNumberFormatException("Escaped comma", "123\\,456"); + assertNumberFormatException("Escaped escape", "123\\\\,456"); + } + + public void testParseCsvTextZero() { + assertTextArray("Empty string", ""); + } + + public void testParseCsvTextSingle() { + assertTextArray("Single char", "a", "a"); + assertTextArray("Space", " ", " "); + assertTextArray("Single label", "abc", "abc"); + 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 "); + } + + public void testParseCsvTextSingleEscaped() { + assertTextArray("Escaped char", "\\a", "a"); + assertTextArray("Escaped comma", "\\,", ","); + assertTextArray("Escaped escape", "\\\\", "\\"); + assertTextArray("Escaped label", "a\\bc", "abc"); + assertTextArray("Escaped label at begininng", "\\abc", "abc"); + assertTextArray("Escaped label with comma", "a\\,c", "a,c"); + assertTextArray("Escaped label with comma at beginning", "\\,bc", ",bc"); + assertTextArray("Escaped label with successive", "\\,\\\\bc", ",\\bc"); + assertTextArray("Escaped label with escape", "a\\\\c", "a\\c"); + } + + public void testParseCsvTextMulti() { + assertTextArray("Multiple chars", "a,b,c", "a", "b", "c"); + assertTextArray("Multiple chars surrounded by spaces", " a , b , c ", " a ", " b ", " c "); + assertTextArray("Multiple labels", "abc,def,ghi", "abc", "def", "ghi"); + assertTextArray("Multiple labels surrounded by spaces", " abc , def , ghi ", + " abc ", " def ", " ghi "); + } + + public void testParseCsvTextMultiEscaped() { + 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", "def", "ghi"); + assertTextArray("Multiple labels with escape surrounded by spaces", + " \\abc , d\\ef , gh\\i ", " abc ", " def ", " ghi "); + 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 "); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java b/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java new file mode 100644 index 000000000..77b62ca5d --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java @@ -0,0 +1,205 @@ +/* + * 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 com.android.inputmethod.keyboard; + +import com.android.inputmethod.latin.R; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.test.AndroidTestCase; + +public class PopupCharactersParserTests extends AndroidTestCase { + private Resources mRes; + + private static final String CODE_SETTINGS = "@integer/key_settings"; + private static final String ICON_SETTINGS = "@drawable/sym_keyboard_settings"; + private static final String CODE_NON_EXISTING = "@integer/non_existing"; + private static final String ICON_NON_EXISTING = "@drawable/non_existing"; + + private int mCodeSettings; + private Drawable mIconSettings; + + private static final Integer[] DUMMY_CODES = { 0 }; + + @Override + protected void setUp() { + Resources res = getContext().getResources(); + mRes = res; + + final String packageName = res.getResourcePackageName(R.string.english_ime_name); + final int codeId = res.getIdentifier(CODE_SETTINGS.substring(1), null, packageName); + final int iconId = res.getIdentifier(ICON_SETTINGS.substring(1), null, packageName); + mCodeSettings = res.getInteger(codeId); + mIconSettings = res.getDrawable(iconId); + } + + private void assertParser(String message, String popupSpec, String expectedLabel, + String expectedOutputText, Drawable expectedIcon, Integer ... expectedCodes) { + String actualLabel = PopupCharactersParser.getLabel(popupSpec); + assertEquals(message + ": label:", expectedLabel, actualLabel); + + String actualOutputText = PopupCharactersParser.getOutputText(popupSpec); + assertEquals(message + ": ouptputText:", expectedOutputText, actualOutputText); + + Drawable actualIcon = PopupCharactersParser.getIcon(mRes, popupSpec); + // We can not compare drawables, checking null or non-null instead. + if (expectedIcon == null) { + assertNull(message + ": icon null:", actualIcon); + } else { + assertNotNull(message + ": icon non-null:", actualIcon); + } + + int[] actualCodes = PopupCharactersParser.getCodes(mRes, popupSpec); + if (expectedCodes == null) { + assertNull(message + ": codes null:", actualCodes); + return; + } + assertSame(message + ": codes length:", expectedCodes.length, actualCodes.length); + for (int i = 0; i < actualCodes.length; i++) { + assertEquals(message + ": codes value at " + i + ":", (int)expectedCodes[i], + actualCodes[i]); + } + } + + private void assertParserError(String message, String popupSpec, String expectedLabel, + String expectedOutputText, Drawable expectedIcon, Integer ... expectedCodes) { + try { + if (expectedCodes.length > 0) { + assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, + expectedCodes); + } else { + assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, + DUMMY_CODES); + } + fail(message); + } catch (PopupCharactersParser.PopupCharactersParserError pcpe) { + // success. + } + } + + public void testSingleLetter() { + assertParser("Single letter", "a", "a", null, null, (int)'a'); + assertParser("Single escaped bar", "\\|", "|", null, null, (int)'|'); + assertParser("Single escaped escape", "\\\\", "\\", null, null, (int)'\\'); + assertParser("Single comma", ",", ",", null, null, (int)','); + assertParser("Single escaped comma", "\\,", ",", null, null, (int)','); + assertParser("Single escaped letter", "\\a", "a", null, null, (int)'a'); + assertParser("Single at", "@", "@", null, null, (int)'@'); + assertParser("Single escaped at", "\\@", "@", null, null, (int)'@'); + assertParser("Single letter with outputText", "a|abc", "a", "abc", null, DUMMY_CODES); + assertParser("Single letter with escaped outputText", "a|a\\|c", "a", "a|c", null, + DUMMY_CODES); + assertParser("Single letter with comma outputText", "a|a,b", "a", "a,b", null, DUMMY_CODES); + assertParser("Single letter with escaped comma outputText", "a|a\\,b", "a", "a,b", null, + DUMMY_CODES); + assertParser("Single letter with outputText starts with at", "a|@bc", "a", "@bc", null, + DUMMY_CODES); + assertParser("Single letter with outputText contains at", "a|a@c", "a", "a@c", null, + DUMMY_CODES); + assertParser("Single letter with escaped at outputText", "a|\\@bc", "a", "@bc", null, + DUMMY_CODES); + assertParser("Single escaped escape with outputText", "\\\\|\\\\", "\\", "\\", null, + DUMMY_CODES); + assertParser("Single escaped bar with outputText", "\\||\\|", "|", "|", null, DUMMY_CODES); + assertParser("Single letter with code", "a|" + CODE_SETTINGS, "a", null, null, + mCodeSettings); + } + + public void testLabel() { + assertParser("Simple label", "abc", "abc", "abc", null, DUMMY_CODES); + assertParser("Label with escaped bar", "a\\|c", "a|c", "a|c", null, DUMMY_CODES); + assertParser("Label with escaped escape", "a\\\\c", "a\\c", "a\\c", null, DUMMY_CODES); + assertParser("Label with comma", "a,c", "a,c", "a,c", null, DUMMY_CODES); + assertParser("Label with escaped comma", "a\\,c", "a,c", "a,c", null, DUMMY_CODES); + assertParser("Label starts with at", "@bc", "@bc", "@bc", null, DUMMY_CODES); + assertParser("Label contains at", "a@c", "a@c", "a@c", null, DUMMY_CODES); + assertParser("Label with escaped at", "\\@bc", "@bc", "@bc", null, DUMMY_CODES); + assertParser("Label with escaped letter", "\\abc", "abc", "abc", null, DUMMY_CODES); + assertParser("Label with outputText", "abc|def", "abc", "def", null, DUMMY_CODES); + assertParser("Label with comma and outputText", "a,c|def", "a,c", "def", null, DUMMY_CODES); + assertParser("Escaped comma label with outputText", "a\\,c|def", "a,c", "def", null, + DUMMY_CODES); + assertParser("Escaped label with outputText", "a\\|c|def", "a|c", "def", null, DUMMY_CODES); + assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", null, + DUMMY_CODES); + assertParser("Escaped escape label with outputText", "a\\\\|def", "a\\", "def", null, + DUMMY_CODES); + assertParser("Label starts with at and outputText", "@bc|def", "@bc", "def", null, + DUMMY_CODES); + assertParser("Label contains at label and outputText", "a@c|def", "a@c", "def", null, + DUMMY_CODES); + assertParser("Escaped at label with outputText", "\\@bc|def", "@bc", "def", null, + DUMMY_CODES); + assertParser("Label with comma outputText", "abc|a,b", "abc", "a,b", null, DUMMY_CODES); + assertParser("Label with escaped comma outputText", "abc|a\\,b", "abc", "a,b", null, + DUMMY_CODES); + assertParser("Label with outputText starts with at", "abc|@bc", "abc", "@bc", null, + DUMMY_CODES); + assertParser("Label with outputText contains at", "abc|a@c", "abc", "a@c", null, + DUMMY_CODES); + assertParser("Label with escaped at outputText", "abc|\\@bc", "abc", "@bc", null, + DUMMY_CODES); + assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", + null, DUMMY_CODES); + assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", "a|c", "d|f", + null, DUMMY_CODES); + assertParser("Label with code", "abc|" + CODE_SETTINGS, "abc", null, null, mCodeSettings); + assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS, "a|c", null, null, + mCodeSettings); + } + + public void testIconAndCode() { + assertParser("Icon with outputText", ICON_SETTINGS + "|abc", null, "abc", mIconSettings, + DUMMY_CODES); + assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", null, "@bc", + mIconSettings, DUMMY_CODES); + assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", null, "a@c", + mIconSettings, DUMMY_CODES); + assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", null, "@bc", + mIconSettings, DUMMY_CODES); + assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS, "@bc", null, null, + mCodeSettings); + assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS, "a@c", null, null, + mCodeSettings); + assertParser("Escaped at label with code", "\\@bc|" + CODE_SETTINGS, "@bc", null, null, + mCodeSettings); + assertParser("Icon with code", ICON_SETTINGS + "|" + CODE_SETTINGS, null, null, + mIconSettings, mCodeSettings); + } + + public void testFormatError() { + assertParserError("Empty spec", "", null, null, null); + assertParserError("Empty label with outputText", "|a", null, "a", null); + assertParserError("Empty label with code", "|" + CODE_SETTINGS, null, null, null, + mCodeSettings); + assertParserError("Empty outputText with label", "a|", "a", null, null); + assertParserError("Empty outputText with icon", ICON_SETTINGS + "|", null, null, + mIconSettings); + assertParserError("Empty icon and code", "|", null, null, null); + assertParserError("Icon without code", ICON_SETTINGS, null, null, mIconSettings); + assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc", null, "abc", null); + assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, "abc", null, null); + assertParserError("Third bar at end", "a|b|", "a", null, null); + assertParserError("Multiple bar", "a|b|c", "a", null, null); + assertParserError("Multiple bar with label and code", "a|" + CODE_SETTINGS + "|c", "a", + null, null, mCodeSettings); + assertParserError("Multiple bar with icon and outputText", ICON_SETTINGS + "|b|c", null, + null, mIconSettings); + assertParserError("Multiple bar with icon and code", + ICON_SETTINGS + "|" + CODE_SETTINGS + "|c", null, null, mIconSettings, + mCodeSettings); + } +} |