aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java23
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java5
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java31
-rw-r--r--native/jni/src/defines.h2
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserBase.java332
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java43
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java307
7 files changed, 432 insertions, 311 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 2e163c4be..8d0f4128e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -75,6 +75,7 @@ import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsActivity;
import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
+import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.CompletionInfoUtils;
@@ -97,7 +98,7 @@ import java.util.concurrent.TimeUnit;
* Input method implementation for Qwerty'ish keyboard.
*/
public class LatinIME extends InputMethodService implements KeyboardActionListener,
- SuggestionStripView.Listener,
+ SuggestionStripView.Listener, SuggestionStripViewAccessor,
DictionaryFacilitatorForSuggest.DictionaryInitializationListener {
private static final String TAG = LatinIME.class.getSimpleName();
private static final boolean TRACE = false;
@@ -1306,8 +1307,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// TODO[IL]: Move this to InputLogic and make it private
- // Outside LatinIME, only used by the test suite.
- @UsedForTesting
+ @Override
public boolean isShowingPunctuationList() {
if (mInputLogic.mSuggestedWords == null) return false;
return mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList
@@ -1330,6 +1330,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return currentSettings.isSuggestionsRequested();
}
+ @Override
+ public boolean hasSuggestionStripView() {
+ return null != mSuggestionStripView;
+ }
+
+ @Override
+ public boolean isShowingAddToDictionaryHint() {
+ return hasSuggestionStripView() && mSuggestionStripView.isShowingAddToDictionaryHint();
+ }
+
+ @Override
public void dismissAddToDictionaryHint() {
if (null != mSuggestionStripView) {
mSuggestionStripView.dismissAddToDictionaryHint();
@@ -1399,8 +1410,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// the "add to dictionary" hint, we need to revert to suggestions - although it is unclear
// how we can come here if it's displayed.
if (suggestedWords.size() > 1 || typedWord.length() <= 1
- || null == mSuggestionStripView
- || mSuggestionStripView.isShowingAddToDictionaryHint()) {
+ || null == mSuggestionStripView || isShowingAddToDictionaryHint()) {
return suggestedWords;
} else {
final SuggestedWords punctuationList =
@@ -1418,7 +1428,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- // TODO[IL]: Define a clean interface for this
+ @Override
public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) {
final SuggestedWords suggestedWords =
sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords;
@@ -1539,6 +1549,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO[IL]: Define a clean interface for this
// This will show either an empty suggestion strip (if prediction is enabled) or
// punctuation suggestions (if it's disabled).
+ @Override
public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent();
if (currentSettings.mBigramPredictionEnabled) {
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index f53183f37..a994a43af 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1616,7 +1616,10 @@ public final class InputLogic {
if (SpaceState.PHANTOM == mSpaceState) {
promotePhantomSpace(settingsValues);
}
- if (settingsValues.mPhraseGestureEnabled) {
+ final SuggestedWordInfo autoCommitCandidate = mSuggestedWords.getAutoCommitCandidate();
+ // Commit except the last word for phrase gesture if the top suggestion is eligible for auto
+ // commit.
+ if (settingsValues.mPhraseGestureEnabled && null != autoCommitCandidate) {
// Find the last space
final int indexOfLastSpace = batchInputText.lastIndexOf(Constants.CODE_SPACE) + 1;
if (0 != indexOfLastSpace) {
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java
new file mode 100644
index 000000000..91bf73d30
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java
@@ -0,0 +1,31 @@
+/*
+ * 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 com.android.inputmethod.latin.suggestions;
+
+import com.android.inputmethod.latin.SuggestedWords;
+
+/**
+ * An object that gives basic control of a suggestion strip and some info on it.
+ */
+public interface SuggestionStripViewAccessor {
+ public boolean hasSuggestionStripView();
+ public boolean isShowingAddToDictionaryHint();
+ public void dismissAddToDictionaryHint();
+ public boolean isShowingPunctuationList();
+ public void setNeutralSuggestionStrip();
+ public void showSuggestionStrip(final SuggestedWords suggestedWords);
+}
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 1969ebae0..22cc4c02b 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -311,7 +311,7 @@ static inline void prof_out(void) {
// A special value to mean the first word confidence makes no sense in this case,
// e.g. this is not a multi-word suggestion.
-#define NOT_A_FIRST_WORD_CONFIDENCE (S_INT_MAX)
+#define NOT_A_FIRST_WORD_CONFIDENCE (S_INT_MIN)
// How high the confidence needs to be for us to auto-commit. Arbitrary.
// This needs to be the same as CONFIDENCE_FOR_AUTO_COMMIT in BinaryDictionary.java
#define CONFIDENCE_FOR_AUTO_COMMIT (1000000)
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserBase.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserBase.java
new file mode 100644
index 000000000..aecef23e8
--- /dev/null
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserBase.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 com.android.inputmethod.keyboard.internal;
+
+import static com.android.inputmethod.keyboard.internal.KeyboardCodesSet.PREFIX_CODE;
+import static com.android.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UNDEFINED;
+import static com.android.inputmethod.keyboard.internal.KeyboardIconsSet.PREFIX_ICON;
+import static com.android.inputmethod.latin.Constants.CODE_OUTPUT_TEXT;
+import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.test.AndroidTestCase;
+
+import com.android.inputmethod.latin.utils.RunInLocale;
+
+import java.util.Locale;
+
+abstract class KeySpecParserBase extends AndroidTestCase {
+ private final static Locale TEST_LOCALE = Locale.ENGLISH;
+ protected final KeyboardCodesSet mCodesSet = new KeyboardCodesSet();
+ 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();
+
+ final String language = TEST_LOCALE.getLanguage();
+ mCodesSet.setLanguage(language);
+ mTextsSet.setLanguage(language);
+ final Context context = getContext();
+ new RunInLocale<Void>() {
+ @Override
+ protected Void job(final Resources res) {
+ mTextsSet.loadStringResources(context);
+ return null;
+ }
+ }.runInLocale(context.getResources(), TEST_LOCALE);
+
+ mCodeSettings = mCodesSet.getCode(CODE_SETTINGS_NAME);
+ mCodeActionNext = mCodesSet.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("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');
+ 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 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/settings_as_more_key",
+ 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/keylabel_for_popular_domain|!text/keylabel_for_popular_domain ",
+ ".com", ".com ", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
+ }
+
+ public void testFormatError() {
+ assertParserError("Empty spec", "", null,
+ null, ICON_UNDEFINED, CODE_UNSPECIFIED);
+ 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("Empty icon and code", "|",
+ null, null, ICON_UNDEFINED, 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/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java
new file mode 100644
index 000000000..e29181c71
--- /dev/null
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.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 com.android.inputmethod.keyboard.internal;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.inputmethod.latin.Constants;
+
+@SmallTest
+public final class KeySpecParserTests extends KeySpecParserBase {
+ @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, mCodesSet);
+ 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));
+ }
+}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java
index 538ba2ccf..213e2d483 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java
@@ -16,63 +16,18 @@
package com.android.inputmethod.keyboard.internal;
-import static com.android.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UNDEFINED;
-import static com.android.inputmethod.latin.Constants.CODE_OUTPUT_TEXT;
-import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.latin.Constants;
-import com.android.inputmethod.latin.utils.RunInLocale;
import java.util.Arrays;
import java.util.Locale;
@SmallTest
-public class MoreKeySpecTests extends AndroidTestCase {
- private final static Locale TEST_LOCALE = Locale.ENGLISH;
- final KeyboardCodesSet mCodesSet = new KeyboardCodesSet();
- final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
-
- private static final String CODE_SETTINGS = "!code/key_settings";
- private static final String ICON_SETTINGS = "!icon/settings_key";
- 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 = "!code/non_existing";
- private static final String ICON_NON_EXISTING = "!icon/non_existing";
-
- private int mCodeSettings;
- private int mCodeActionNext;
- private int mSettingsIconId;
-
+public final class MoreKeySpecTests extends KeySpecParserBase {
@Override
- protected void setUp() throws Exception {
- super.setUp();
-
- final String language = TEST_LOCALE.getLanguage();
- mCodesSet.setLanguage(language);
- mTextsSet.setLanguage(language);
- final Context context = getContext();
- new RunInLocale<Void>() {
- @Override
- protected Void job(final Resources res) {
- mTextsSet.loadStringResources(context);
- return null;
- }
- }.runInLocale(context.getResources(), TEST_LOCALE);
-
- mCodeSettings = KeySpecParser.parseCode(
- CODE_SETTINGS, mCodesSet, CODE_UNSPECIFIED);
- mCodeActionNext = KeySpecParser.parseCode(
- "!code/key_action_next", mCodesSet, CODE_UNSPECIFIED);
- mSettingsIconId = KeySpecParser.getIconId(ICON_SETTINGS);
- }
-
- private void assertParser(final String message, final String moreKeySpec,
- final String expectedLabel, final String expectedOutputText, final int expectedIcon,
+ 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 */,
@@ -80,267 +35,13 @@ public class MoreKeySpecTests extends AndroidTestCase {
assertEquals(message + " [label]", expectedLabel, spec.mLabel);
assertEquals(message + " [ouptputText]", expectedOutputText, spec.mOutputText);
assertEquals(message + " [icon]",
- KeyboardIconsSet.getIconName(expectedIcon),
+ KeyboardIconsSet.getIconName(expectedIconId),
KeyboardIconsSet.getIconName(spec.mIconId));
assertEquals(message + " [code]",
Constants.printableCode(expectedCode),
Constants.printableCode(spec.mCode));
}
- private void assertParserError(final String message, final String moreKeySpec,
- final String expectedLabel, final String expectedOutputText, final int expectedIcon,
- final int expectedCode) {
- try {
- assertParser(message, moreKeySpec, expectedLabel, expectedOutputText, expectedIcon,
- expectedCode);
- fail(message);
- } catch (Exception pcpe) {
- // success.
- }
- }
-
- // \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;
-
- public void testSingleLetter() {
- assertParser("Single letter", "a",
- "a", null, ICON_UNDEFINED, 'a');
- assertParser("Single surrogate", PAIR1,
- PAIR1, null, ICON_UNDEFINED, CODE1);
- 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');
- assertParser("Single escaped surrogate", "\\" + PAIR2,
- PAIR2, null, ICON_UNDEFINED, 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|" + PAIR1,
- "G Clef", null, ICON_UNDEFINED, CODE1);
- assertParser("Single letter with outputText", "a|abc",
- "a", "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
- assertParser("Single letter with surrogate outputText", "a|" + SURROGATE1,
- "a", SURROGATE1, ICON_UNDEFINED, CODE_OUTPUT_TEXT);
- assertParser("Single surrogate with outputText", PAIR3 + "|abc",
- 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|" + PAIR1 + "\\|" + PAIR2,
- "a", PAIR1 + "|" + 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|!" + SURROGATE2,
- "a", "!" + SURROGATE2, 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", SURROGATE1,
- SURROGATE1, SURROGATE1, 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", PAIR1 + "\\|" + PAIR2,
- PAIR1 + "|" + PAIR2, PAIR1 + "|" + 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", "!" + SURROGATE1,
- "!" + SURROGATE1, "!" + SURROGATE1, 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 testIconAndCode() {
- 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/settings_as_more_key",
- 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/keylabel_for_popular_domain|!text/keylabel_for_popular_domain ",
- ".com", ".com ", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
- }
-
- public void testFormatError() {
- assertParserError("Empty spec", "", null,
- null, ICON_UNDEFINED, CODE_UNSPECIFIED);
- 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("Empty icon and code", "|",
- null, null, ICON_UNDEFINED, 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);
- }
-
private static void assertArrayEquals(final String message, final Object[] expected,
final Object[] actual) {
if (expected == actual) {