aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/inputmethod/latin')
-rw-r--r--tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java31
-rw-r--r--tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java56
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java8
-rw-r--r--tests/src/com/android/inputmethod/latin/InputTestsBase.java19
4 files changed, 89 insertions, 25 deletions
diff --git a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
index 81f744da9..a9947c1bd 100644
--- a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
+++ b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
@@ -18,6 +18,9 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.Keyboard;
+import android.text.style.SuggestionSpan;
+import android.text.style.UnderlineSpan;
+
public class BlueUnderlineTests extends InputTestsBase {
public void testBlueUnderline() {
@@ -27,7 +30,7 @@ public class BlueUnderlineTests extends InputTestsBase {
type(STRING_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
- final Span span = new Span(mTextView.getText());
+ final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
assertEquals("show blue underline, span start", EXPECTED_SPAN_START, span.mStart);
assertEquals("show blue underline, span end", EXPECTED_SPAN_END, span.mEnd);
assertEquals("show blue underline, span color", true, span.isAutoCorrectionIndicator());
@@ -44,7 +47,7 @@ public class BlueUnderlineTests extends InputTestsBase {
type(STRING_2_TO_TYPE);
// We haven't have time to look into the dictionary yet, so the line should still be
// blue to avoid any flicker.
- final Span spanBefore = new Span(mTextView.getText());
+ final SpanGetter spanBefore = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
assertEquals("extend blue underline, span start", EXPECTED_SPAN_START, spanBefore.mStart);
assertEquals("extend blue underline, span end", EXPECTED_SPAN_END, spanBefore.mEnd);
assertEquals("extend blue underline, span color", true,
@@ -52,14 +55,15 @@ public class BlueUnderlineTests extends InputTestsBase {
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
// Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span
- final Span spanAfter = new Span(mTextView.getText());
+ final SpanGetter spanAfter = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
assertNull("hide blue underline", spanAfter.mSpan);
}
public void testBlueUnderlineOnBackspace() {
final String STRING_TO_TYPE = "tgis";
- final int EXPECTED_SPAN_START = 0;
- final int EXPECTED_SPAN_END = 4;
+ final int EXPECTED_SUGGESTION_SPAN_START = -1;
+ final int EXPECTED_UNDERLINE_SPAN_START = 0;
+ final int EXPECTED_UNDERLINE_SPAN_END = 4;
type(STRING_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
@@ -72,13 +76,14 @@ public class BlueUnderlineTests extends InputTestsBase {
type(Keyboard.CODE_DELETE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
- final Span span = new Span(mTextView.getText());
- assertEquals("show blue underline after backspace, span start",
- EXPECTED_SPAN_START, span.mStart);
- assertEquals("show blue underline after backspace, span end",
- EXPECTED_SPAN_END, span.mEnd);
- assertEquals("show blue underline after backspace, span color", true,
- span.isAutoCorrectionIndicator());
+ final SpanGetter suggestionSpan = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
+ assertEquals("show no blue underline after backspace, span start should be -1",
+ EXPECTED_SUGGESTION_SPAN_START, suggestionSpan.mStart);
+ final SpanGetter underlineSpan = new SpanGetter(mTextView.getText(), UnderlineSpan.class);
+ assertEquals("should be composing, so should have an underline span",
+ EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart);
+ assertEquals("should be composing, so should have an underline span",
+ EXPECTED_UNDERLINE_SPAN_END, underlineSpan.mEnd);
}
public void testBlueUnderlineDisappearsWhenCursorMoved() {
@@ -96,7 +101,7 @@ public class BlueUnderlineTests extends InputTestsBase {
mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
- final Span span = new Span(mTextView.getText());
+ final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
assertNull("blue underline removed when cursor is moved", span.mSpan);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java b/tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java
new file mode 100644
index 000000000..a2e71c11a
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java
@@ -0,0 +1,56 @@
+/*
+ * 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.test.AndroidTestCase;
+
+public class ForgettingCurveTests extends AndroidTestCase {
+ public void testFcToFreq() {
+ for (int i = 0; i < Byte.MAX_VALUE; ++i) {
+ final byte fc = (byte)i;
+ final int e = UserHistoryForgettingCurveUtils.fcToElapsedTime(fc);
+ final int c = UserHistoryForgettingCurveUtils.fcToCount(fc);
+ final int l = UserHistoryForgettingCurveUtils.fcToLevel(fc);
+ final byte fc2 = UserHistoryForgettingCurveUtils.calcFc(e, c, l);
+ assertEquals(fc, fc2);
+ }
+ byte fc = 0;
+ int l;
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < (UserHistoryForgettingCurveUtils.COUNT_MAX + 1); ++j) {
+ fc = UserHistoryForgettingCurveUtils.pushCount(fc, true);
+ }
+ l = UserHistoryForgettingCurveUtils.fcToLevel(fc);
+ assertEquals(l, Math.max(1, Math.min(i + 1, 3)));
+ }
+ fc = 0;
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < (UserHistoryForgettingCurveUtils.COUNT_MAX + 1); ++j) {
+ fc = UserHistoryForgettingCurveUtils.pushCount(fc, false);
+ }
+ l = UserHistoryForgettingCurveUtils.fcToLevel(fc);
+ assertEquals(l, Math.min(i + 1, 3));
+ }
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < (UserHistoryForgettingCurveUtils.ELAPSED_TIME_MAX + 1); ++j) {
+ fc = UserHistoryForgettingCurveUtils.pushElapsedTime(fc);
+ }
+ l = UserHistoryForgettingCurveUtils.fcToLevel(fc);
+ assertEquals(l, Math.max(0, 2 - i));
+ }
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index 6c3cb16c7..f1ccfdd1d 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -28,7 +28,7 @@ public class InputLogicTests extends InputTestsBase {
public void testPickSuggestionThenBackspace() {
final String WORD_TO_TYPE = "this";
- final String EXPECTED_RESULT = "this";
+ final String EXPECTED_RESULT = "thi";
type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
@@ -40,7 +40,7 @@ public class InputLogicTests extends InputTestsBase {
public void testPickAutoCorrectionThenBackspace() {
final String WORD_TO_TYPE = "tgis";
final String WORD_TO_PICK = "this";
- final String EXPECTED_RESULT = "tgis";
+ final String EXPECTED_RESULT = "thi";
type(WORD_TO_TYPE);
// Choose the auto-correction, which is always in position 0. For "tgis", the
// auto-correction should be "this".
@@ -55,7 +55,7 @@ public class InputLogicTests extends InputTestsBase {
public void testPickTypedWordOverAutoCorrectionThenBackspace() {
final String WORD_TO_TYPE = "tgis";
- final String EXPECTED_RESULT = "tgis";
+ final String EXPECTED_RESULT = "tgi";
type(WORD_TO_TYPE);
// Choose the typed word, which should be in position 1 (because position 0 should
// be occupied by the "this" auto-correction, as checked by testAutoCorrect())
@@ -71,7 +71,7 @@ public class InputLogicTests extends InputTestsBase {
public void testPickDifferentSuggestionThenBackspace() {
final String WORD_TO_TYPE = "tgis";
final String WORD_TO_PICK = "thus";
- final String EXPECTED_RESULT = "tgis";
+ final String EXPECTED_RESULT = "thu";
type(WORD_TO_TYPE);
// Choose the second suggestion, which should be in position 2 and should be "thus"
// when "tgis is typed.
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index c73a931ea..eb47fd517 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -24,6 +24,7 @@ import android.preference.PreferenceManager;
import android.test.ServiceTestCase;
import android.text.InputType;
import android.text.SpannableStringBuilder;
+import android.text.style.CharacterStyle;
import android.text.style.SuggestionSpan;
import android.view.LayoutInflater;
import android.view.View;
@@ -57,18 +58,19 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
new HashMap<String, InputMethodSubtype>();
// A helper class to ease span tests
- public static class Span {
+ public static class SpanGetter {
final SpannableStringBuilder mInputText;
- final SuggestionSpan mSpan;
+ final CharacterStyle mSpan;
final int mStart;
final int mEnd;
// The supplied CharSequence should be an instance of SpannableStringBuilder,
- // and it should contain exactly zero or one SuggestionSpan. Otherwise, an exception
+ // and it should contain exactly zero or one span. Otherwise, an exception
// is thrown.
- public Span(final CharSequence inputText) {
+ public SpanGetter(final CharSequence inputText,
+ final Class<? extends CharacterStyle> spanType) {
mInputText = (SpannableStringBuilder)inputText;
- final SuggestionSpan[] spans =
- mInputText.getSpans(0, mInputText.length(), SuggestionSpan.class);
+ final CharacterStyle[] spans =
+ mInputText.getSpans(0, mInputText.length(), spanType);
if (0 == spans.length) {
mSpan = null;
mStart = -1;
@@ -78,11 +80,12 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
mStart = mInputText.getSpanStart(mSpan);
mEnd = mInputText.getSpanEnd(mSpan);
} else {
- throw new RuntimeException("Expected one SuggestionSpan, found " + spans.length);
+ throw new RuntimeException("Expected one span, found " + spans.length);
}
}
public boolean isAutoCorrectionIndicator() {
- return 0 != (SuggestionSpan.FLAG_AUTO_CORRECTION & mSpan.getFlags());
+ return (mSpan instanceof SuggestionSpan) &&
+ 0 != (SuggestionSpan.FLAG_AUTO_CORRECTION & ((SuggestionSpan)mSpan).getFlags());
}
}