2010-12-14 06:31:47 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-06-22 02:53:02 +00:00
|
|
|
package com.android.inputmethod.keyboard.internal;
|
2010-12-14 06:31:47 +00:00
|
|
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.test.AndroidTestCase;
|
|
|
|
|
2011-06-21 14:38:42 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
|
|
|
import com.android.inputmethod.latin.R;
|
|
|
|
|
2012-01-30 02:14:45 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2012-02-02 06:41:11 +00:00
|
|
|
public class KeySpecParserTests extends AndroidTestCase {
|
2010-12-14 06:31:47 +00:00
|
|
|
private Resources mRes;
|
|
|
|
|
2011-06-21 14:38:42 +00:00
|
|
|
private static final int ICON_UNDEFINED = KeyboardIconsSet.ICON_UNDEFINED;
|
|
|
|
|
2012-02-03 09:21:19 +00:00
|
|
|
private static final String CODE_SETTINGS_RES = "integer/key_settings";
|
|
|
|
private static final String ICON_SETTINGS_NAME = "settingsKey";
|
|
|
|
|
|
|
|
private static final String CODE_SETTINGS = "@" + CODE_SETTINGS_RES;
|
|
|
|
private static final String ICON_SETTINGS = "@icon/" + ICON_SETTINGS_NAME;
|
2010-12-14 06:31:47 +00:00
|
|
|
private static final String CODE_NON_EXISTING = "@integer/non_existing";
|
2011-06-21 14:38:42 +00:00
|
|
|
private static final String ICON_NON_EXISTING = "@icon/non_existing";
|
2010-12-14 06:31:47 +00:00
|
|
|
|
|
|
|
private int mCodeSettings;
|
2012-02-03 09:21:19 +00:00
|
|
|
private int mSettingsIconId;
|
2010-12-14 06:31:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setUp() {
|
|
|
|
Resources res = getContext().getResources();
|
|
|
|
mRes = res;
|
|
|
|
|
|
|
|
final String packageName = res.getResourcePackageName(R.string.english_ime_name);
|
2012-02-03 09:21:19 +00:00
|
|
|
final int codeId = res.getIdentifier(CODE_SETTINGS_RES, null, packageName);
|
2010-12-14 06:31:47 +00:00
|
|
|
mCodeSettings = res.getInteger(codeId);
|
2012-02-03 09:21:19 +00:00
|
|
|
mSettingsIconId = KeyboardIconsSet.getIconId(ICON_SETTINGS_NAME);
|
2010-12-14 06:31:47 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 06:26:32 +00:00
|
|
|
private void assertParser(String message, String moreKeySpec, String expectedLabel,
|
2011-06-21 14:38:42 +00:00
|
|
|
String expectedOutputText, int expectedIcon, int expectedCode) {
|
2012-02-02 06:41:11 +00:00
|
|
|
String actualLabel = KeySpecParser.getLabel(moreKeySpec);
|
2010-12-14 06:31:47 +00:00
|
|
|
assertEquals(message + ": label:", expectedLabel, actualLabel);
|
|
|
|
|
2012-02-02 06:41:11 +00:00
|
|
|
String actualOutputText = KeySpecParser.getOutputText(moreKeySpec);
|
2010-12-14 06:31:47 +00:00
|
|
|
assertEquals(message + ": ouptputText:", expectedOutputText, actualOutputText);
|
|
|
|
|
2012-02-02 15:18:47 +00:00
|
|
|
int actualIcon = KeySpecParser.getIconId(moreKeySpec);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertEquals(message + ": icon:", expectedIcon, actualIcon);
|
2010-12-14 06:31:47 +00:00
|
|
|
|
2012-02-02 06:41:11 +00:00
|
|
|
int actualCode = KeySpecParser.getCode(mRes, moreKeySpec);
|
2010-12-20 11:30:26 +00:00
|
|
|
assertEquals(message + ": codes value:", expectedCode, actualCode);
|
2010-12-14 06:31:47 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 06:26:32 +00:00
|
|
|
private void assertParserError(String message, String moreKeySpec, String expectedLabel,
|
2011-06-21 14:38:42 +00:00
|
|
|
String expectedOutputText, int expectedIcon, int expectedCode) {
|
2010-12-14 06:31:47 +00:00
|
|
|
try {
|
2011-08-31 06:26:32 +00:00
|
|
|
assertParser(message, moreKeySpec, expectedLabel, expectedOutputText, expectedIcon,
|
2010-12-20 11:30:26 +00:00
|
|
|
expectedCode);
|
2010-12-14 06:31:47 +00:00
|
|
|
fail(message);
|
2012-01-20 06:47:22 +00:00
|
|
|
} catch (Exception pcpe) {
|
2010-12-14 06:31:47 +00:00
|
|
|
// success.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 06:41:11 +00:00
|
|
|
// \U001d11e: MUSICAL SYMBOL G CLEF
|
|
|
|
private static final String PAIR1 = "\ud834\udd1e";
|
|
|
|
private static final int CODE1 = PAIR1.codePointAt(0);
|
|
|
|
// \U001d122: MUSICAL SYMBOL F CLEF
|
|
|
|
private static final String PAIR2 = "\ud834\udd22";
|
|
|
|
private static final int CODE2 = PAIR2.codePointAt(0);
|
|
|
|
// \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;
|
|
|
|
|
2010-12-14 06:31:47 +00:00
|
|
|
public void testSingleLetter() {
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter", "a",
|
|
|
|
"a", null, ICON_UNDEFINED, 'a');
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Single surrogate", PAIR1,
|
|
|
|
PAIR1, null, ICON_UNDEFINED, CODE1);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single escaped 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');
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Single escaped surrogate", "\\" + PAIR2,
|
|
|
|
PAIR2, null, ICON_UNDEFINED, CODE2);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single at", "@",
|
|
|
|
"@", null, ICON_UNDEFINED, '@');
|
|
|
|
assertParser("Single escaped at", "\\@",
|
|
|
|
"@", null, ICON_UNDEFINED, '@');
|
2012-02-07 11:42:07 +00:00
|
|
|
assertParser("Single output text letter", "a|a",
|
|
|
|
"a", null, ICON_UNDEFINED, 'a');
|
|
|
|
assertParser("Single surrogate pair outputText", "G Clef|" + PAIR1,
|
|
|
|
"G Clef", null, ICON_UNDEFINED, CODE1);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with outputText", "a|abc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a", "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Single letter with surrogate outputText", "a|" + SURROGATE1,
|
|
|
|
"a", SURROGATE1, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
|
|
|
assertParser("Single surrogate with outputText", PAIR3 + "|abc",
|
|
|
|
PAIR3, "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with escaped outputText", "a|a\\|c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a", "a|c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Single letter with escaped surrogate outputText",
|
|
|
|
"a|" + PAIR1 + "\\|" + PAIR2,
|
|
|
|
"a", PAIR1 + "|" + PAIR2, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with comma outputText", "a|a,b",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with escaped comma outputText", "a|a\\,b",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with outputText starts with at", "a|@bc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Single letter with surrogate outputText starts with at", "a|@" + SURROGATE2,
|
|
|
|
"a", "@" + SURROGATE2, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with outputText contains at", "a|a@c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with escaped at outputText", "a|\\@bc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2012-02-07 11:42:07 +00:00
|
|
|
assertParser("Single escaped escape with single outputText", "\\\\|\\\\",
|
|
|
|
"\\", null, ICON_UNDEFINED, '\\');
|
|
|
|
assertParser("Single escaped bar with single outputText", "\\||\\|",
|
|
|
|
"|", null, ICON_UNDEFINED, '|');
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Single letter with code", "a|" + CODE_SETTINGS,
|
|
|
|
"a", null, ICON_UNDEFINED, mCodeSettings);
|
2010-12-14 06:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testLabel() {
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Simple label", "abc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Simple surrogate label", SURROGATE1,
|
|
|
|
SURROGATE1, SURROGATE1, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped bar", "a\\|c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a|c", "a|c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Surrogate label with escaped bar", PAIR1 + "\\|" + PAIR2,
|
|
|
|
PAIR1 + "|" + PAIR2, PAIR1 + "|" + PAIR2,
|
|
|
|
ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped escape", "a\\\\c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a\\c", "a\\c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with comma", "a,c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped comma", "a\\,c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label starts with at", "@bc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2012-02-02 06:41:11 +00:00
|
|
|
assertParser("Surrogate label starts with at", "@" + SURROGATE1,
|
|
|
|
"@" + SURROGATE1, "@" + SURROGATE1, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label contains at", "a@c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a@c", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped at", "\\@bc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped letter", "\\abc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with outputText", "abc|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with comma and outputText", "a,c|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a,c", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Escaped comma label with outputText", "a\\,c|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a,c", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Escaped label with outputText", "a\\|c|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a|c", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped bar outputText", "abc|d\\|f",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Escaped escape label with outputText", "a\\\\|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a\\", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label starts with at and outputText", "@bc|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"@bc", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label contains at label and outputText", "a@c|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a@c", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Escaped at label with outputText", "\\@bc|def",
|
2012-01-19 03:42:15 +00:00
|
|
|
"@bc", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with comma outputText", "abc|a,b",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped comma outputText", "abc|a\\,b",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with outputText starts with at", "abc|@bc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with outputText contains at", "abc|a@c",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped at outputText", "abc|\\@bc",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label with escaped bar outputText", "abc|d\\|f",
|
2012-01-19 03:42:15 +00:00
|
|
|
"abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f",
|
2012-01-19 03:42:15 +00:00
|
|
|
"a|c", "d|f", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
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);
|
2010-12-14 06:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testIconAndCode() {
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Icon with outputText", ICON_SETTINGS + "|abc",
|
2012-02-03 09:21:19 +00:00
|
|
|
null, "abc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc",
|
2012-02-03 09:21:19 +00:00
|
|
|
null, "@bc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c",
|
2012-02-03 09:21:19 +00:00
|
|
|
null, "a@c", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc",
|
2012-02-03 09:21:19 +00:00
|
|
|
null, "@bc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS,
|
|
|
|
"@bc", null, ICON_UNDEFINED, mCodeSettings);
|
|
|
|
assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS,
|
|
|
|
"a@c", null, ICON_UNDEFINED, mCodeSettings);
|
|
|
|
assertParser("Escaped at label with code", "\\@bc|" + CODE_SETTINGS,
|
|
|
|
"@bc", null, ICON_UNDEFINED, mCodeSettings);
|
|
|
|
assertParser("Icon with code", ICON_SETTINGS + "|" + CODE_SETTINGS,
|
2012-02-03 09:21:19 +00:00
|
|
|
null, null, mSettingsIconId, mCodeSettings);
|
2010-12-14 06:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testFormatError() {
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParserError("Empty spec", "", null,
|
|
|
|
null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
|
|
|
|
assertParserError("Empty label with outputText", "|a",
|
2012-01-10 08:24:00 +00:00
|
|
|
null, "a", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParserError("Empty label with code", "|" + CODE_SETTINGS,
|
|
|
|
null, null, ICON_UNDEFINED, mCodeSettings);
|
|
|
|
assertParserError("Empty outputText with label", "a|",
|
|
|
|
"a", null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
|
|
|
|
assertParserError("Empty outputText with icon", ICON_SETTINGS + "|",
|
2012-02-03 09:21:19 +00:00
|
|
|
null, null, mSettingsIconId, Keyboard.CODE_UNSPECIFIED);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParserError("Empty icon and code", "|",
|
|
|
|
null, null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
|
|
|
|
assertParserError("Icon without code", ICON_SETTINGS,
|
2012-02-03 09:21:19 +00:00
|
|
|
null, null, mSettingsIconId, Keyboard.CODE_UNSPECIFIED);
|
2012-01-20 10:57:07 +00:00
|
|
|
assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc",
|
2012-01-19 03:42:15 +00:00
|
|
|
null, "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
|
2011-06-21 14:38:42 +00:00
|
|
|
assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING,
|
|
|
|
"abc", null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
|
|
|
|
assertParserError("Third bar at end", "a|b|",
|
|
|
|
"a", null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
|
|
|
|
assertParserError("Multiple bar", "a|b|c",
|
|
|
|
"a", null, ICON_UNDEFINED, Keyboard.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",
|
2012-02-03 09:21:19 +00:00
|
|
|
null, null, mSettingsIconId, Keyboard.CODE_UNSPECIFIED);
|
2010-12-14 06:31:47 +00:00
|
|
|
assertParserError("Multiple bar with icon and code",
|
2011-06-21 14:38:42 +00:00
|
|
|
ICON_SETTINGS + "|" + CODE_SETTINGS + "|c",
|
2012-02-03 09:21:19 +00:00
|
|
|
null, null, mSettingsIconId, mCodeSettings);
|
2010-12-14 06:31:47 +00:00
|
|
|
}
|
2012-01-30 02:14:45 +00:00
|
|
|
|
2012-02-02 06:41:11 +00:00
|
|
|
private static void assertMoreKeys(String message, String[] moreKeys,
|
|
|
|
String[] additionalMoreKeys, String[] expected) {
|
|
|
|
final String[] actual = KeySpecParser.insertAddtionalMoreKeys(
|
2012-01-30 02:14:45 +00:00
|
|
|
moreKeys, additionalMoreKeys);
|
|
|
|
if (expected == null && actual == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (expected == null || actual == null) {
|
|
|
|
assertEquals(message, Arrays.toString(expected), Arrays.toString(actual));
|
|
|
|
} else {
|
|
|
|
if (expected.length != actual.length) {
|
|
|
|
assertEquals(message, Arrays.toString(expected), Arrays.toString(actual));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < expected.length; i++) {
|
|
|
|
if (!actual[i].equals(expected[i])) {
|
|
|
|
assertEquals(message, Arrays.toString(expected), Arrays.toString(actual));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testInsertAdditionalMoreKeys() {
|
|
|
|
// Escaped marker.
|
|
|
|
assertMoreKeys("escaped marker",
|
|
|
|
new String[] { "\\%", "%-)" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "2", "\\%", "%-)" });
|
|
|
|
|
|
|
|
// 0 more key.
|
|
|
|
assertMoreKeys("null & null", null, null, null);
|
|
|
|
assertMoreKeys("null & 1 additional",
|
|
|
|
null,
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "1" });
|
|
|
|
assertMoreKeys("null & 2 additionals",
|
|
|
|
null,
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "2" });
|
|
|
|
|
|
|
|
// 0 additional more key.
|
|
|
|
assertMoreKeys("1 more key & null",
|
|
|
|
new String[] { "A" },
|
|
|
|
null,
|
|
|
|
new String[] { "A" });
|
|
|
|
assertMoreKeys("2 more keys & null",
|
|
|
|
new String[] { "A", "B" },
|
|
|
|
null,
|
|
|
|
new String[] { "A", "B" });
|
|
|
|
|
|
|
|
// No marker.
|
|
|
|
assertMoreKeys("1 more key & 1 addtional & no marker",
|
|
|
|
new String[] { "A" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "1", "A" });
|
|
|
|
assertMoreKeys("1 more key & 2 addtionals & no marker",
|
|
|
|
new String[] { "A" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "2", "A" });
|
|
|
|
assertMoreKeys("2 more keys & 1 addtional & no marker",
|
|
|
|
new String[] { "A", "B" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "1", "A", "B" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtionals & no marker",
|
|
|
|
new String[] { "A", "B" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "2", "A", "B" });
|
|
|
|
|
|
|
|
// 1 marker.
|
|
|
|
assertMoreKeys("1 more key & 1 additional & marker at head",
|
|
|
|
new String[] { "%", "A" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "1", "A" });
|
|
|
|
assertMoreKeys("1 more key & 1 additional & marker at tail",
|
|
|
|
new String[] { "A", "%" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "A", "1" });
|
|
|
|
assertMoreKeys("2 more keys & 1 additional & marker at middle",
|
|
|
|
new String[] { "A", "%", "B" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "A", "1", "B" });
|
|
|
|
|
|
|
|
// 1 marker & excess additional more keys.
|
|
|
|
assertMoreKeys("1 more key & 2 additionals & marker at head",
|
|
|
|
new String[] { "%", "A", "B" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "A", "B", "2" });
|
|
|
|
assertMoreKeys("1 more key & 2 additionals & marker at tail",
|
|
|
|
new String[] { "A", "B", "%" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "A", "B", "1", "2" });
|
|
|
|
assertMoreKeys("2 more keys & 2 additionals & marker at middle",
|
|
|
|
new String[] { "A", "%", "B" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "A", "1", "B", "2" });
|
|
|
|
|
|
|
|
// 2 markers.
|
|
|
|
assertMoreKeys("0 more key & 2 addtional & 2 markers",
|
|
|
|
new String[] { "%", "%" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "2" });
|
|
|
|
assertMoreKeys("1 more key & 2 addtional & 2 markers at head",
|
|
|
|
new String[] { "%", "%", "A" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "2", "A" });
|
|
|
|
assertMoreKeys("1 more key & 2 addtional & 2 markers at tail",
|
|
|
|
new String[] { "A", "%", "%" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "A", "1", "2" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtional & 2 markers at middle",
|
|
|
|
new String[] { "A", "%", "%", "B" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "A", "1", "2", "B" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtional & 2 markers at head & middle",
|
|
|
|
new String[] { "%", "A", "%", "B" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "A", "2", "B" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtional & 2 markers at head & tail",
|
|
|
|
new String[] { "%", "A", "B", "%" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "A", "B", "2" });
|
|
|
|
assertMoreKeys("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 keys.
|
|
|
|
assertMoreKeys("0 more key & 2 addtional & 2 markers",
|
|
|
|
new String[] { "%", "%" },
|
|
|
|
new String[] { "1", "2", "3" },
|
|
|
|
new String[] { "1", "2", "3" });
|
|
|
|
assertMoreKeys("1 more key & 2 addtional & 2 markers at head",
|
|
|
|
new String[] { "%", "%", "A" },
|
|
|
|
new String[] { "1", "2", "3" },
|
|
|
|
new String[] { "1", "2", "A", "3" });
|
|
|
|
assertMoreKeys("1 more key & 2 addtional & 2 markers at tail",
|
|
|
|
new String[] { "A", "%", "%" },
|
|
|
|
new String[] { "1", "2", "3" },
|
|
|
|
new String[] { "A", "1", "2", "3" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtional & 2 markers at middle",
|
|
|
|
new String[] { "A", "%", "%", "B" },
|
|
|
|
new String[] { "1", "2", "3" },
|
|
|
|
new String[] { "A", "1", "2", "B", "3" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtional & 2 markers at head & middle",
|
|
|
|
new String[] { "%", "A", "%", "B" },
|
|
|
|
new String[] { "1", "2", "3" },
|
|
|
|
new String[] { "1", "A", "2", "B", "3" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtional & 2 markers at head & tail",
|
|
|
|
new String[] { "%", "A", "B", "%" },
|
|
|
|
new String[] { "1", "2", "3" },
|
|
|
|
new String[] { "1", "A", "B", "2", "3" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtional & 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.
|
|
|
|
assertMoreKeys("0 more key & null & excess marker",
|
|
|
|
new String[] { "%" },
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
assertMoreKeys("1 more key & null & excess marker at head",
|
|
|
|
new String[] { "%", "A" },
|
|
|
|
null,
|
|
|
|
new String[] { "A" });
|
|
|
|
assertMoreKeys("1 more key & null & excess marker at tail",
|
|
|
|
new String[] { "A", "%" },
|
|
|
|
null,
|
|
|
|
new String[] { "A" });
|
|
|
|
assertMoreKeys("2 more keys & null & excess marker at middle",
|
|
|
|
new String[] { "A", "%", "B" },
|
|
|
|
null,
|
|
|
|
new String[] { "A", "B" });
|
|
|
|
assertMoreKeys("2 more keys & null & excess markers",
|
|
|
|
new String[] { "%", "A", "%", "B", "%" },
|
|
|
|
null,
|
|
|
|
new String[] { "A", "B" });
|
|
|
|
|
|
|
|
// Excess markers.
|
|
|
|
assertMoreKeys("0 more key & 1 addtional & excess marker",
|
|
|
|
new String[] { "%", "%" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "1" });
|
|
|
|
assertMoreKeys("1 more key & 1 addtional & excess marker at head",
|
|
|
|
new String[] { "%", "%", "A" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "1", "A" });
|
|
|
|
assertMoreKeys("1 more key & 1 addtional & excess marker at tail",
|
|
|
|
new String[] { "A", "%", "%" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "A", "1" });
|
|
|
|
assertMoreKeys("2 more keys & 1 addtional & excess marker at middle",
|
|
|
|
new String[] { "A", "%", "%", "B" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "A", "1", "B" });
|
|
|
|
assertMoreKeys("2 more keys & 1 addtional & excess markers",
|
|
|
|
new String[] { "%", "A", "%", "B", "%" },
|
|
|
|
new String[] { "1" },
|
|
|
|
new String[] { "1", "A", "B" });
|
|
|
|
assertMoreKeys("2 more keys & 2 addtionals & excess markers",
|
|
|
|
new String[] { "%", "A", "%", "B", "%" },
|
|
|
|
new String[] { "1", "2" },
|
|
|
|
new String[] { "1", "A", "2", "B" });
|
|
|
|
assertMoreKeys("2 more keys & 3 addtionals & excess markers",
|
|
|
|
new String[] { "%", "A", "%", "%", "B", "%" },
|
|
|
|
new String[] { "1", "2", "3" },
|
|
|
|
new String[] { "1", "A", "2", "3", "B" });
|
|
|
|
}
|
2010-12-14 06:31:47 +00:00
|
|
|
}
|