aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-01-07 17:43:44 +0900
committerTadashi G. Takaoka <takaoka@google.com>2014-01-08 14:14:42 +0900
commite7dc5302afdaedc379e3725f2a5822b630b43276 (patch)
treef2bfaf311e543836de0354c3ac194539a6a83a94 /java/src
parent385031557b7885d739d77e79f9cfc321659cbecf (diff)
downloadlatinime-e7dc5302afdaedc379e3725f2a5822b630b43276.tar.gz
latinime-e7dc5302afdaedc379e3725f2a5822b630b43276.tar.xz
latinime-e7dc5302afdaedc379e3725f2a5822b630b43276.zip
Fix InputPointersTests
InputPointers.getTime(int) has a validity check of time values. And the check is enabled when LatinImeLogger.sDBG is on. Such situation may occur while unit testing. This change ensure that time values are monotonic while unit testing. Change-Id: I9ff2cff2bcd253de0e8206dd3be964fe565170fa
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/InputPointers.java49
1 files changed, 27 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputPointers.java b/java/src/com/android/inputmethod/latin/InputPointers.java
index 2e638aaf3..6b489da30 100644
--- a/java/src/com/android/inputmethod/latin/InputPointers.java
+++ b/java/src/com/android/inputmethod/latin/InputPointers.java
@@ -16,14 +16,16 @@
package com.android.inputmethod.latin;
+import android.util.Log;
+
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.utils.ResizableIntArray;
-import android.util.Log;
-
// TODO: This class is not thread-safe.
public final class InputPointers {
private static final String TAG = InputPointers.class.getSimpleName();
+ private static final boolean DEBUG_TIME = false;
+
private final int mDefaultCapacity;
private final ResizableIntArray mXCoordinates;
private final ResizableIntArray mYCoordinates;
@@ -38,10 +40,29 @@ public final class InputPointers {
mTimes = new ResizableIntArray(defaultCapacity);
}
+ private void fillWithLastTimeUntil(final int index) {
+ final int fromIndex = mTimes.getLength();
+ // Fill the gap with the latest time.
+ // See {@link #getTime(int)} and {@link #isValidTimeStamps()}.
+ if (fromIndex <= 0) {
+ return;
+ }
+ final int fillLength = index - fromIndex + 1;
+ if (fillLength <= 0) {
+ return;
+ }
+ final int lastTime = mTimes.get(fromIndex - 1);
+ mTimes.fill(lastTime, fromIndex, fillLength);
+ }
+
+ // TODO: Rename this method to addPointerAt
public void addPointer(int index, int x, int y, int pointerId, int time) {
mXCoordinates.add(index, x);
mYCoordinates.add(index, y);
mPointerIds.add(index, pointerId);
+ if (LatinImeLogger.sDBG || DEBUG_TIME) {
+ fillWithLastTimeUntil(index);
+ }
mTimes.add(index, time);
}
@@ -68,23 +89,6 @@ public final class InputPointers {
}
/**
- * Append the pointers in the specified {@link InputPointers} to the end of this.
- * @param src the source {@link InputPointers} to read the data from.
- * @param startPos the starting index of the pointers in {@code src}.
- * @param length the number of pointers to be appended.
- */
- @UsedForTesting
- void append(InputPointers src, int startPos, int length) {
- if (length == 0) {
- return;
- }
- mXCoordinates.append(src.mXCoordinates, startPos, length);
- mYCoordinates.append(src.mYCoordinates, startPos, length);
- mPointerIds.append(src.mPointerIds, startPos, length);
- mTimes.append(src.mTimes, startPos, length);
- }
-
- /**
* Append the times, x-coordinates and y-coordinates in the specified {@link ResizableIntArray}
* to the end of this.
* @param pointerId the pointer id of the source.
@@ -141,7 +145,7 @@ public final class InputPointers {
}
public int[] getTimes() {
- if (LatinImeLogger.sDBG) {
+ if (LatinImeLogger.sDBG || DEBUG_TIME) {
if (!isValidTimeStamps()) {
throw new RuntimeException("Time stamps are invalid.");
}
@@ -157,10 +161,11 @@ public final class InputPointers {
private boolean isValidTimeStamps() {
final int[] times = mTimes.getPrimitiveArray();
- for (int i = 1; i < getPointerSize(); ++i) {
+ final int size = getPointerSize();
+ for (int i = 1; i < size; ++i) {
if (times[i] < times[i - 1]) {
// dump
- for (int j = 0; j < times.length; ++j) {
+ for (int j = 0; j < size; ++j) {
Log.d(TAG, "--- (" + j + ") " + times[j]);
}
return false;