aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java148
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java10
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java122
3 files changed, 267 insertions, 13 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java
index 4050a7123..29881d91c 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java
@@ -16,30 +16,53 @@
package com.android.inputmethod.keyboard.internal;
-import com.android.inputmethod.keyboard.internal.KeyStyles.EmptyKeyStyle;
-
+import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.text.TextUtils;
+import com.android.inputmethod.latin.tests.R;
+
+import java.util.Arrays;
+
public class KeyStylesTests extends AndroidTestCase {
+ private Resources mTestResources;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mTestResources = getTestContext().getResources();
+ }
+
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);
+ private void assertTextArray(String message, String value, String ... expected) {
+ final String actual[] = KeyStyles.parseCsvText(value, mTestResources,
+ R.string.empty_string);
if (expected.length == 0) {
assertNull(message, actual);
return;
}
- assertSame(message + ": result length", expected.length, actual.length);
+ assertEquals(message + ": expected=" + Arrays.toString(expected)
+ + " actual=" + Arrays.toString(actual)
+ + ": 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);
}
}
+ private void assertError(String message, String value, String ... expected) {
+ try {
+ assertTextArray(message, value, expected);
+ fail(message);
+ } catch (Exception pcpe) {
+ // success.
+ }
+ }
+
public void testParseCsvTextZero() {
assertTextArray("Empty string", "");
}
@@ -52,7 +75,10 @@ public class KeyStylesTests extends AndroidTestCase {
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("Label surrounded by spaces", " abc ", " abc ");
+
+ assertTextArray("Incomplete resource reference 1", "string", "string");
+ assertTextArray("Incomplete resource reference 2", "@strin", "@strin");
}
public void testParseCsvTextSingleEscaped() {
@@ -60,11 +86,13 @@ public class KeyStylesTests extends AndroidTestCase {
assertTextArray("Escaped comma", "\\,", ",");
assertTextArray("Escaped escape", "\\\\", "\\");
assertTextArray("Escaped label", "a\\bc", "abc");
- assertTextArray("Escaped label at begininng", "\\abc", "abc");
+ assertTextArray("Escaped label at beginning", "\\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");
+
+ assertTextArray("Escaped @string", "\\@string/empty_string", "@string/empty_string");
}
public void testParseCsvTextMulti() {
@@ -86,5 +114,109 @@ public class KeyStylesTests extends AndroidTestCase {
"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 @string", "\\@,\\@string/empty_string",
+ "@", "@string/empty_string");
+ }
+
+ public void testParseCsvResourceError() {
+ assertError("Incomplete resource name 1", "@string", "@string");
+ assertError("Incomplete resource name 2", "@string/", "@string/");
+ assertError("Non existing resource", "@string/non_existing");
+ }
+
+ public void testParseCsvResourceZero() {
+ assertTextArray("Empty string",
+ "@string/empty_string");
+ }
+
+ public void testParseCsvResourceSingle() {
+ 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 ");
+ }
+
+ public void testParseCsvResourceSingleEscaped() {
+ assertTextArray("Escaped char",
+ "@string/escaped_char", "a");
+ assertTextArray("Escaped comma",
+ "@string/escaped_comma", ",");
+ assertTextArray("Escaped escape",
+ "@string/escaped_escape", "\\");
+ assertTextArray("Escaped label",
+ "@string/escaped_label", "abc");
+ assertTextArray("Escaped label at beginning",
+ "@string/escaped_label_at_beginning", "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 successive",
+ "@string/escaped_label_with_successive", ",\\bc");
+ assertTextArray("Escaped label with escape",
+ "@string/escaped_label_with_escape", "a\\c");
+ }
+
+ public void testParseCsvResourceMulti() {
+ 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 ");
+ }
+
+ public void testParseCsvResourcetMultiEscaped() {
+ 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", "def", "ghi");
+ assertTextArray("Multiple labels with escape surrounded by spaces",
+ "@string/multiple_labels_with_escape_surrounded_by_spaces",
+ " abc ", " def ", " ghi ");
+ 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 ");
+ }
+
+ public void testParseMultipleResources() {
+ assertTextArray("Literals and resources",
+ "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 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");
}
}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java
index edccff33a..74aaf9af8 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java
@@ -25,11 +25,11 @@ import com.android.inputmethod.latin.R;
public class MoreKeySpecParserTests extends AndroidTestCase {
private Resources mRes;
- private static final int ICON_SETTINGS_KEY = 5;
+ private static final int ICON_SETTINGS_KEY = R.styleable.Keyboard_iconSettingsKey;
private static final int ICON_UNDEFINED = KeyboardIconsSet.ICON_UNDEFINED;
private static final String CODE_SETTINGS = "@integer/key_settings";
- private static final String ICON_SETTINGS = "@icon/" + ICON_SETTINGS_KEY;
+ private static final String ICON_SETTINGS = "@icon/settingsKey";
private static final String CODE_NON_EXISTING = "@integer/non_existing";
private static final String ICON_NON_EXISTING = "@icon/non_existing";
@@ -53,7 +53,7 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
String actualOutputText = MoreKeySpecParser.getOutputText(moreKeySpec);
assertEquals(message + ": ouptputText:", expectedOutputText, actualOutputText);
- int actualIcon = MoreKeySpecParser.getIconId(moreKeySpec);
+ int actualIcon = MoreKeySpecParser.getIconAttrId(moreKeySpec);
assertEquals(message + ": icon:", expectedIcon, actualIcon);
int actualCode = MoreKeySpecParser.getCode(mRes, moreKeySpec);
@@ -66,7 +66,7 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
assertParser(message, moreKeySpec, expectedLabel, expectedOutputText, expectedIcon,
expectedCode);
fail(message);
- } catch (MoreKeySpecParser.MoreKeySpecParserError pcpe) {
+ } catch (Exception pcpe) {
// success.
}
}
@@ -201,7 +201,7 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
null, null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParserError("Icon without code", ICON_SETTINGS,
null, null, ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED);
- assertParser("Non existing icon", ICON_NON_EXISTING + "|abc",
+ assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc",
null, "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT);
assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING,
"abc", null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
new file mode 100644
index 000000000..06ee5bffa
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -0,0 +1,122 @@
+/*
+ * 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 com.android.inputmethod.latin;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.test.ServiceTestCase;
+import android.text.InputType;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+import android.view.View;
+import android.view.inputmethod.BaseInputConnection;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputConnection;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.keyboard.KeyboardActionListener;
+
+public class InputLogicTests extends ServiceTestCase<LatinIME> {
+
+ private static final String PREF_DEBUG_MODE = "debug_mode";
+
+ private LatinIME mLatinIME;
+ private TextView mTextView;
+
+ public InputLogicTests() {
+ super(LatinIME.class);
+ }
+
+ // returns the previous setting value
+ private boolean setDebugMode(final boolean mode) {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
+ final boolean previousDebugSetting = prefs.getBoolean(PREF_DEBUG_MODE, false);
+ final SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean(PREF_DEBUG_MODE, true);
+ editor.commit();
+ return previousDebugSetting;
+ }
+
+ @Override
+ protected void setUp() {
+ try {
+ super.setUp();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ mTextView = new TextView(getContext());
+ mTextView.setInputType(InputType.TYPE_CLASS_TEXT);
+ mTextView.setEnabled(true);
+ setupService();
+ mLatinIME = getService();
+ final boolean previousDebugSetting = setDebugMode(true);
+ mLatinIME.onCreate();
+ setDebugMode(previousDebugSetting);
+ final EditorInfo ei = new EditorInfo();
+ final InputConnection ic = mTextView.onCreateInputConnection(ei);
+ final LayoutInflater inflater =
+ (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ final ViewGroup vg = new FrameLayout(getContext());
+ final View inputView = inflater.inflate(R.layout.input_view, vg);
+ mLatinIME.setInputView(inputView);
+ mLatinIME.onBindInput();
+ mLatinIME.onCreateInputView();
+ mLatinIME.onStartInputView(ei, false);
+ mLatinIME.onCreateInputMethodInterface().startInput(ic, ei);
+ }
+
+ // type(int) and type(String): helper methods to send a code point resp. a string to LatinIME.
+ private void type(final int codePoint) {
+ // 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);
+ mLatinIME.onCodeInput(codePoint, new int[] { codePoint },
+ KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
+ KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
+ //mLatinIME.onReleaseKey(codePoint, false);
+ }
+
+ private void type(final String stringToType) {
+ for (int i = 0; i < stringToType.length(); ++i) {
+ type(stringToType.codePointAt(i));
+ }
+ }
+
+ public void testTypeWord() {
+ final String wordToType = "abcd";
+ type(wordToType);
+ assertEquals("type word", wordToType, mTextView.getText().toString());
+ }
+
+ public void testPickSuggestionThenBackspace() {
+ final String wordToType = "tgis";
+ type(wordToType);
+ mLatinIME.pickSuggestionManually(0, wordToType);
+ type(Keyboard.CODE_DELETE);
+ assertEquals("press suggestion then backspace", wordToType, mTextView.getText().toString());
+ }
+
+}