diff options
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/inputmethod/compat/ArraysCompatUtilsTests.java | 103 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java | 207 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java (renamed from tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java) | 4 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java (renamed from tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java) | 4 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/internal/PopupCharactersParserTests.java | 220 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/EventRingBufferTests.java | 154 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java | 4 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/SuggestHelper.java | 17 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/SuggestTestsBase.java | 12 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/UtilsTests.java | 67 |
10 files changed, 412 insertions, 380 deletions
diff --git a/tests/src/com/android/inputmethod/compat/ArraysCompatUtilsTests.java b/tests/src/com/android/inputmethod/compat/ArraysCompatUtilsTests.java new file mode 100644 index 000000000..93681b616 --- /dev/null +++ b/tests/src/com/android/inputmethod/compat/ArraysCompatUtilsTests.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.compat; + +import android.test.AndroidTestCase; + +public class ArraysCompatUtilsTests extends AndroidTestCase { + // See {@link tests.api.java.util.ArraysTest}. + private static final int ARRAY_SIZE = 100; + private final int[] mIntArray = new int[ARRAY_SIZE]; + + @Override + protected void setUp() throws Exception { + super.setUp(); + for (int counter = 0; counter < ARRAY_SIZE; counter++) { + mIntArray[counter] = counter; + } + } + + public void testEmptyArray() { + final int index = ArraysCompatUtils.binarySearch(mIntArray, 0, 0, 0); + assertEquals("empty", ~0, index); + final int compat = ArraysCompatUtils.compatBinarySearch(mIntArray, 0, 0, 0); + assertEquals("empty compat", ~0, compat); + } + + public void testEmptyRangeArray() { + final int mid = ARRAY_SIZE / 3; + final int index = ArraysCompatUtils.binarySearch(mIntArray, mid, mid, 1); + assertEquals("empty", ~mid, index); + final int compat = ArraysCompatUtils.compatBinarySearch(mIntArray, mid, mid, 1); + assertEquals("empty compat", ~mid, compat); + } + + public void testFind() { + for (int counter = 0; counter < ARRAY_SIZE; counter++) { + final int index = ArraysCompatUtils.binarySearch(mIntArray, 0, ARRAY_SIZE, counter); + assertEquals("found", counter, index); + } + for (int counter = 0; counter < ARRAY_SIZE; counter++) { + final int compat = ArraysCompatUtils.compatBinarySearch( + mIntArray, 0, ARRAY_SIZE, counter); + assertEquals("found compat", counter, compat); + } + } + + public void testFindNegative() { + final int offset = ARRAY_SIZE / 2; + for (int counter = 0; counter < ARRAY_SIZE; counter++) { + mIntArray[counter] -= offset; + } + for (int counter = 0; counter < ARRAY_SIZE; counter++) { + final int index = ArraysCompatUtils.binarySearch( + mIntArray, 0, ARRAY_SIZE, counter - offset); + assertEquals("found", counter, index); + } + for (int counter = 0; counter < ARRAY_SIZE; counter++) { + final int compat = ArraysCompatUtils.compatBinarySearch( + mIntArray, 0, ARRAY_SIZE, counter - offset); + assertEquals("found compat", counter, compat); + } + } + + public void testNotFountAtTop() { + final int index = ArraysCompatUtils.binarySearch(mIntArray, 0, ARRAY_SIZE, -1); + assertEquals("not found top", ~0, index); + final int compat = ArraysCompatUtils.compatBinarySearch( + mIntArray, 0, ARRAY_SIZE, -1); + assertEquals("not found top compat", ~0, compat); + } + + public void testNotFountAtEnd() { + final int index = ArraysCompatUtils.binarySearch(mIntArray, 0, ARRAY_SIZE, ARRAY_SIZE); + assertEquals("not found end", ~ARRAY_SIZE, index); + final int compat = ArraysCompatUtils.compatBinarySearch( + mIntArray, 0, ARRAY_SIZE, ARRAY_SIZE); + assertEquals("not found end compat", ~ARRAY_SIZE, compat); + } + + public void testNotFountAtMid() { + final int mid = ARRAY_SIZE / 3; + mIntArray[mid] = mIntArray[mid + 1]; + final int index = ArraysCompatUtils.binarySearch(mIntArray, 0, ARRAY_SIZE, mid); + assertEquals("not found mid", ~mid, index); + final int compat = ArraysCompatUtils.compatBinarySearch( + mIntArray, 0, ARRAY_SIZE, mid); + assertEquals("not found mid compat", ~mid, compat); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java b/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java deleted file mode 100644 index ae78866e6..000000000 --- a/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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; - - @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, int expectedCode) { - 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 actualCode = PopupCharactersParser.getCode(mRes, popupSpec); - assertEquals(message + ": codes value:", expectedCode, actualCode); - } - - private void assertParserError(String message, String popupSpec, String expectedLabel, - String expectedOutputText, Drawable expectedIcon, int expectedCode) { - try { - assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, - expectedCode); - fail(message); - } catch (PopupCharactersParser.PopupCharactersParserError pcpe) { - // success. - } - } - - public void testSingleLetter() { - assertParser("Single letter", "a", "a", null, null, 'a'); - assertParser("Single escaped bar", "\\|", "|", null, null, '|'); - assertParser("Single escaped escape", "\\\\", "\\", null, null, '\\'); - assertParser("Single comma", ",", ",", null, null, ','); - assertParser("Single escaped comma", "\\,", ",", null, null, ','); - assertParser("Single escaped letter", "\\a", "a", null, null, 'a'); - assertParser("Single at", "@", "@", null, null, '@'); - assertParser("Single escaped at", "\\@", "@", null, null, '@'); - assertParser("Single letter with outputText", "a|abc", "a", "abc", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with escaped outputText", "a|a\\|c", "a", "a|c", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with comma outputText", "a|a,b", "a", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with escaped comma outputText", "a|a\\,b", "a", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with outputText starts with at", "a|@bc", "a", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with outputText contains at", "a|a@c", "a", "a@c", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with escaped at outputText", "a|\\@bc", "a", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Single escaped escape with outputText", "\\\\|\\\\", "\\", "\\", null, - Keyboard.CODE_DUMMY); - assertParser("Single escaped bar with outputText", "\\||\\|", "|", "|", null, - Keyboard.CODE_DUMMY); - assertParser("Single letter with code", "a|" + CODE_SETTINGS, "a", null, null, - mCodeSettings); - } - - public void testLabel() { - assertParser("Simple label", "abc", "abc", "abc", null, Keyboard.CODE_DUMMY); - assertParser("Label with escaped bar", "a\\|c", "a|c", "a|c", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped escape", "a\\\\c", "a\\c", "a\\c", null, - Keyboard.CODE_DUMMY); - assertParser("Label with comma", "a,c", "a,c", "a,c", null, Keyboard.CODE_DUMMY); - assertParser("Label with escaped comma", "a\\,c", "a,c", "a,c", null, - Keyboard.CODE_DUMMY); - assertParser("Label starts with at", "@bc", "@bc", "@bc", null, Keyboard.CODE_DUMMY); - assertParser("Label contains at", "a@c", "a@c", "a@c", null, Keyboard.CODE_DUMMY); - assertParser("Label with escaped at", "\\@bc", "@bc", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped letter", "\\abc", "abc", "abc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with outputText", "abc|def", "abc", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label with comma and outputText", "a,c|def", "a,c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped comma label with outputText", "a\\,c|def", "a,c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped label with outputText", "a\\|c|def", "a|c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped escape label with outputText", "a\\\\|def", "a\\", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label starts with at and outputText", "@bc|def", "@bc", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label contains at label and outputText", "a@c|def", "a@c", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Escaped at label with outputText", "\\@bc|def", "@bc", "def", null, - Keyboard.CODE_DUMMY); - assertParser("Label with comma outputText", "abc|a,b", "abc", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped comma outputText", "abc|a\\,b", "abc", "a,b", null, - Keyboard.CODE_DUMMY); - assertParser("Label with outputText starts with at", "abc|@bc", "abc", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with outputText contains at", "abc|a@c", "abc", "a@c", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped at outputText", "abc|\\@bc", "abc", "@bc", null, - Keyboard.CODE_DUMMY); - assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", - null, Keyboard.CODE_DUMMY); - assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", "a|c", "d|f", - null, Keyboard.CODE_DUMMY); - 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, - Keyboard.CODE_DUMMY); - assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", null, "@bc", - mIconSettings, Keyboard.CODE_DUMMY); - assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", null, "a@c", - mIconSettings, Keyboard.CODE_DUMMY); - assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", null, "@bc", - mIconSettings, Keyboard.CODE_DUMMY); - 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, Keyboard.CODE_UNSPECIFIED); - assertParserError("Empty label with outputText", "|a", null, "a", null, - Keyboard.CODE_DUMMY); - assertParserError("Empty label with code", "|" + CODE_SETTINGS, null, null, null, - mCodeSettings); - assertParserError("Empty outputText with label", "a|", "a", null, null, - Keyboard.CODE_UNSPECIFIED); - assertParserError("Empty outputText with icon", ICON_SETTINGS + "|", null, null, - mIconSettings, Keyboard.CODE_UNSPECIFIED); - assertParserError("Empty icon and code", "|", null, null, null, Keyboard.CODE_UNSPECIFIED); - assertParserError("Icon without code", ICON_SETTINGS, null, null, mIconSettings, - Keyboard.CODE_DUMMY); - assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc", null, "abc", null, - Keyboard.CODE_DUMMY); - assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, "abc", null, null, - Keyboard.CODE_UNSPECIFIED); - assertParserError("Third bar at end", "a|b|", "a", null, null, Keyboard.CODE_UNSPECIFIED); - assertParserError("Multiple bar", "a|b|c", "a", null, null, Keyboard.CODE_UNSPECIFIED); - 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, Keyboard.CODE_UNSPECIFIED); - assertParserError("Multiple bar with icon and code", - ICON_SETTINGS + "|" + CODE_SETTINGS + "|c", null, null, mIconSettings, - mCodeSettings); - } -} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java index 5dff11471..4050a7123 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyStylesTests.java @@ -14,9 +14,9 @@ * the License. */ -package com.android.inputmethod.keyboard; +package com.android.inputmethod.keyboard.internal; -import com.android.inputmethod.keyboard.KeyStyles.EmptyKeyStyle; +import com.android.inputmethod.keyboard.internal.KeyStyles.EmptyKeyStyle; import android.test.AndroidTestCase; import android.text.TextUtils; diff --git a/tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java index 600342a7c..0d2802d53 100644 --- a/tests/src/com/android/inputmethod/keyboard/MiniKeyboardBuilderTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilderTests.java @@ -14,9 +14,9 @@ * the License. */ -package com.android.inputmethod.keyboard; +package com.android.inputmethod.keyboard.internal; -import com.android.inputmethod.keyboard.MiniKeyboardBuilder.MiniKeyboardLayoutParams; +import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder.MiniKeyboardLayoutParams; import android.test.AndroidTestCase; diff --git a/tests/src/com/android/inputmethod/keyboard/internal/PopupCharactersParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/PopupCharactersParserTests.java new file mode 100644 index 000000000..e4a1c68d8 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/internal/PopupCharactersParserTests.java @@ -0,0 +1,220 @@ +/* + * 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.internal; + +import android.content.res.Resources; +import android.test.AndroidTestCase; + +import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.R; + +public class PopupCharactersParserTests extends AndroidTestCase { + private Resources mRes; + + private static final int ICON_SETTINGS_KEY = 5; + 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 CODE_NON_EXISTING = "@integer/non_existing"; + private static final String ICON_NON_EXISTING = "@icon/non_existing"; + + private int mCodeSettings; + + @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); + mCodeSettings = res.getInteger(codeId); + } + + private void assertParser(String message, String popupSpec, String expectedLabel, + String expectedOutputText, int expectedIcon, int expectedCode) { + String actualLabel = PopupCharactersParser.getLabel(popupSpec); + assertEquals(message + ": label:", expectedLabel, actualLabel); + + String actualOutputText = PopupCharactersParser.getOutputText(popupSpec); + assertEquals(message + ": ouptputText:", expectedOutputText, actualOutputText); + + int actualIcon = PopupCharactersParser.getIconId(popupSpec); + assertEquals(message + ": icon:", expectedIcon, actualIcon); + + int actualCode = PopupCharactersParser.getCode(mRes, popupSpec); + assertEquals(message + ": codes value:", expectedCode, actualCode); + } + + private void assertParserError(String message, String popupSpec, String expectedLabel, + String expectedOutputText, int expectedIcon, int expectedCode) { + try { + assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, + expectedCode); + fail(message); + } catch (PopupCharactersParser.PopupCharactersParserError pcpe) { + // success. + } + } + + public void testSingleLetter() { + assertParser("Single letter", "a", + "a", null, ICON_UNDEFINED, 'a'); + 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 at", "@", + "@", null, ICON_UNDEFINED, '@'); + assertParser("Single escaped at", "\\@", + "@", null, ICON_UNDEFINED, '@'); + assertParser("Single letter with outputText", "a|abc", + "a", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single letter with escaped outputText", "a|a\\|c", + "a", "a|c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single letter with comma outputText", "a|a,b", + "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single letter with escaped comma outputText", "a|a\\,b", + "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single letter with outputText starts with at", "a|@bc", + "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single letter with outputText contains at", "a|a@c", + "a", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single letter with escaped at outputText", "a|\\@bc", + "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single escaped escape with outputText", "\\\\|\\\\", + "\\", "\\", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single escaped bar with outputText", "\\||\\|", + "|", "|", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Single letter with code", "a|" + CODE_SETTINGS, + "a", null, ICON_UNDEFINED, mCodeSettings); + } + + public void testLabel() { + assertParser("Simple label", "abc", + "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped bar", "a\\|c", + "a|c", "a|c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped escape", "a\\\\c", + "a\\c", "a\\c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with comma", "a,c", + "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped comma", "a\\,c", + "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label starts with at", "@bc", + "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label contains at", "a@c", + "a@c", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped at", "\\@bc", + "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped letter", "\\abc", + "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with outputText", "abc|def", + "abc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with comma and outputText", "a,c|def", + "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Escaped comma label with outputText", "a\\,c|def", + "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Escaped label with outputText", "a\\|c|def", + "a|c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped bar outputText", "abc|d\\|f", + "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Escaped escape label with outputText", "a\\\\|def", + "a\\", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label starts with at and outputText", "@bc|def", + "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label contains at label and outputText", "a@c|def", + "a@c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Escaped at label with outputText", "\\@bc|def", + "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with comma outputText", "abc|a,b", + "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped comma outputText", "abc|a\\,b", + "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with outputText starts with at", "abc|@bc", + "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with outputText contains at", "abc|a@c", + "abc", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped at outputText", "abc|\\@bc", + "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Label with escaped bar outputText", "abc|d\\|f", + "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", + "a|c", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + 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", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", + null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", + null, "a@c", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", + null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + 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, + null, null, ICON_SETTINGS_KEY, mCodeSettings); + } + + public void testFormatError() { + assertParserError("Empty spec", "", null, + null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); + assertParserError("Empty label with outputText", "|a", + null, "a", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + 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 + "|", + null, null, ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED); + assertParserError("Empty icon and code", "|", + null, null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED); + assertParserError("Icon without code", ICON_SETTINGS, + null, null, ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY); + assertParser("Non existing icon", ICON_NON_EXISTING + "|abc", + null, "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY); + 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", + null, null, ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED); + assertParserError("Multiple bar with icon and code", + ICON_SETTINGS + "|" + CODE_SETTINGS + "|c", + null, null, ICON_SETTINGS_KEY, mCodeSettings); + } +} diff --git a/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java b/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java deleted file mode 100644 index 869781f3d..000000000 --- a/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES 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 com.android.inputmethod.keyboard.SwipeTracker.EventRingBuffer; - -import android.test.AndroidTestCase; - -public class EventRingBufferTests extends AndroidTestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - private static float X_BASE = 1000f; - - private static float Y_BASE = 2000f; - - private static long TIME_BASE = 3000l; - - private static float x(int id) { - return X_BASE + id; - } - - private static float y(int id) { - return Y_BASE + id; - } - - private static long time(int id) { - return TIME_BASE + id; - } - - private static void addEvent(EventRingBuffer buf, int id) { - buf.add(x(id), y(id), time(id)); - } - - private static void assertEventSize(EventRingBuffer buf, int size) { - assertEquals(size, buf.size()); - } - - private static void assertEvent(EventRingBuffer buf, int pos, int id) { - assertEquals(x(id), buf.getX(pos), 0f); - assertEquals(y(id), buf.getY(pos), 0f); - assertEquals(time(id), buf.getTime(pos)); - } - - public void testClearBuffer() { - EventRingBuffer buf = new EventRingBuffer(4); - assertEventSize(buf, 0); - - addEvent(buf, 0); - addEvent(buf, 1); - addEvent(buf, 2); - addEvent(buf, 3); - addEvent(buf, 4); - assertEventSize(buf, 4); - - buf.clear(); - assertEventSize(buf, 0); - } - - public void testRingBuffer() { - EventRingBuffer buf = new EventRingBuffer(4); - assertEventSize(buf, 0); // [0] - - addEvent(buf, 0); - assertEventSize(buf, 1); // [1] 0 - assertEvent(buf, 0, 0); - - addEvent(buf, 1); - addEvent(buf, 2); - assertEventSize(buf, 3); // [3] 2 1 0 - assertEvent(buf, 0, 0); - assertEvent(buf, 1, 1); - assertEvent(buf, 2, 2); - - addEvent(buf, 3); - assertEventSize(buf, 4); // [4] 3 2 1 0 - assertEvent(buf, 0, 0); - assertEvent(buf, 1, 1); - assertEvent(buf, 2, 2); - assertEvent(buf, 3, 3); - - addEvent(buf, 4); - addEvent(buf, 5); - assertEventSize(buf, 4); // [4] 5 4|3 2(1 0) - assertEvent(buf, 0, 2); - assertEvent(buf, 1, 3); - assertEvent(buf, 2, 4); - assertEvent(buf, 3, 5); - - addEvent(buf, 6); - addEvent(buf, 7); - addEvent(buf, 8); - assertEventSize(buf, 4); // [4] 8 7 6 5|(4 3 2)1|0 - assertEvent(buf, 0, 5); - assertEvent(buf, 1, 6); - assertEvent(buf, 2, 7); - assertEvent(buf, 3, 8); - } - - public void testDropOldest() { - EventRingBuffer buf = new EventRingBuffer(4); - - addEvent(buf, 0); - assertEventSize(buf, 1); // [1] 0 - assertEvent(buf, 0, 0); - - buf.dropOldest(); - assertEventSize(buf, 0); // [0] (0) - - addEvent(buf, 1); - addEvent(buf, 2); - addEvent(buf, 3); - addEvent(buf, 4); - assertEventSize(buf, 4); // [4] 4|3 2 1(0) - assertEvent(buf, 0, 1); - - buf.dropOldest(); - assertEventSize(buf, 3); // [3] 4|3 2(1)0 - assertEvent(buf, 0, 2); - - buf.dropOldest(); - assertEventSize(buf, 2); // [2] 4|3(2)10 - assertEvent(buf, 0, 3); - - buf.dropOldest(); - assertEventSize(buf, 1); // [1] 4|(3)210 - assertEvent(buf, 0, 4); - - buf.dropOldest(); - assertEventSize(buf, 0); // [0] (4)|3210 - } -} diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java index d128cb3fa..d102aa4d1 100644 --- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java +++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.latin.Utils; + import android.content.Context; import android.content.res.Resources; import android.test.AndroidTestCase; @@ -75,7 +77,7 @@ public class SubtypeLocaleTests extends AndroidTestCase { int failedCount = 0; for (final InputMethodSubtype subtype : mKeyboardSubtypes) { final String localeCode = subtype.getLocale(); - final Locale locale = new Locale(localeCode); + final Locale locale = Utils.constructLocaleFromString(localeCode); // The locale name which will be displayed on spacebar. For example 'English (US)' or // 'Francais (Canada)'. (c=\u008d) final String displayName = SubtypeLocale.getFullDisplayName(locale); diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java index 5930ea36e..07d0e5d75 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java +++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java @@ -20,7 +20,6 @@ import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.LatinKeyboard; -import com.android.inputmethod.keyboard.ProximityKeyDetector; import android.content.Context; import android.text.TextUtils; @@ -34,17 +33,19 @@ public class SuggestHelper { private final KeyDetector mKeyDetector; public SuggestHelper(Context context, int dictionaryId, KeyboardId keyboardId) { - mSuggest = new Suggest(context, dictionaryId); - mKeyboard = new LatinKeyboard(context, keyboardId); - mKeyDetector = new ProximityKeyDetector(); + // Use null as the locale for Suggest so as to force it to use the internal dictionary + // (and not try to find a dictionary provider for a specified locale) + mSuggest = new Suggest(context, dictionaryId, null); + mKeyboard = new LatinKeyboard(context, keyboardId, keyboardId.mWidth); + mKeyDetector = new KeyDetector(0); init(); } protected SuggestHelper(Context context, File dictionaryPath, long startOffset, long length, KeyboardId keyboardId) { - mSuggest = new Suggest(dictionaryPath, startOffset, length); - mKeyboard = new LatinKeyboard(context, keyboardId); - mKeyDetector = new ProximityKeyDetector(); + mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null); + mKeyboard = new LatinKeyboard(context, keyboardId, keyboardId.mWidth); + mKeyDetector = new KeyDetector(0); init(); } @@ -53,7 +54,7 @@ public class SuggestHelper { mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL); mKeyDetector.setKeyboard(mKeyboard, 0, 0); mKeyDetector.setProximityCorrectionEnabled(true); - mKeyDetector.setProximityThreshold(KeyDetector.getMostCommonKeyWidth(mKeyboard)); + mKeyDetector.setProximityThreshold(mKeyboard.getMostCommonKeyWidth()); } public void setCorrectionMode(int correctionMode) { diff --git a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java index 48d169f6a..8aadee42e 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java @@ -16,15 +16,14 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.keyboard.KeyboardId; -import com.android.inputmethod.keyboard.KeyboardView; - import android.content.res.AssetFileDescriptor; import android.content.res.Configuration; import android.test.AndroidTestCase; import android.text.TextUtils; import android.view.inputmethod.EditorInfo; +import com.android.inputmethod.keyboard.KeyboardId; + import java.io.File; import java.io.InputStream; import java.util.Locale; @@ -38,10 +37,11 @@ public class SuggestTestsBase extends AndroidTestCase { mTestPackageFile = new File(getTestContext().getApplicationInfo().sourceDir); } - protected static KeyboardId createKeyboardId(Locale locale) { + protected KeyboardId createKeyboardId(Locale locale) { + final int displayWidth = getContext().getResources().getDisplayMetrics().widthPixels; return new KeyboardId(locale.toString() + " keyboard", - com.android.inputmethod.latin.R.xml.kbd_qwerty, KeyboardView.COLOR_SCHEME_WHITE, - locale, Configuration.ORIENTATION_LANDSCAPE, KeyboardId.MODE_TEXT, + com.android.inputmethod.latin.R.xml.kbd_qwerty, locale, + Configuration.ORIENTATION_LANDSCAPE, displayWidth, KeyboardId.MODE_TEXT, new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false, false); } diff --git a/tests/src/com/android/inputmethod/latin/UtilsTests.java b/tests/src/com/android/inputmethod/latin/UtilsTests.java new file mode 100644 index 000000000..5c0b03a0a --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/UtilsTests.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2010,2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.latin; + +import android.test.AndroidTestCase; + +import com.android.inputmethod.latin.tests.R; + +public class UtilsTests extends AndroidTestCase { + + // The following is meant to be a reasonable default for + // the "word_separators" resource. + private static final String sSeparators = ".,:;!?-"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + /************************** Tests ************************/ + + /** + * Test for getting previous word (for bigram suggestions) + */ + public void testGetPreviousWord() { + // If one of the following cases breaks, the bigram suggestions won't work. + assertEquals(EditingUtils.getPreviousWord("abc def", sSeparators), "abc"); + assertNull(EditingUtils.getPreviousWord("abc", sSeparators)); + assertNull(EditingUtils.getPreviousWord("abc. def", sSeparators)); + + // The following tests reflect the current behavior of the function + // EditingUtils#getPreviousWord. + // TODO: However at this time, the code does never go + // into such a path, so it should be safe to change the behavior of + // this function if needed - especially since it does not seem very + // logical. These tests are just there to catch any unintentional + // changes in the behavior of the EditingUtils#getPreviousWord method. + assertEquals(EditingUtils.getPreviousWord("abc def ", sSeparators), "abc"); + assertEquals(EditingUtils.getPreviousWord("abc def.", sSeparators), "abc"); + assertEquals(EditingUtils.getPreviousWord("abc def .", sSeparators), "def"); + assertNull(EditingUtils.getPreviousWord("abc ", sSeparators)); + } + + /** + * Test for getting the word before the cursor (for bigram) + */ + public void testGetThisWord() { + assertEquals(EditingUtils.getThisWord("abc def", sSeparators), "def"); + assertEquals(EditingUtils.getThisWord("abc def ", sSeparators), "def"); + assertNull(EditingUtils.getThisWord("abc def.", sSeparators)); + assertNull(EditingUtils.getThisWord("abc def .", sSeparators)); + } +} |