am f46eafe2: am c9398a3b: Merge "Fix PointerTrackerQueue.releaseAllPointerOlderThan"

* commit 'f46eafe2555a8d405ce7171bc4a2977a9aecf2b9':
  Fix PointerTrackerQueue.releaseAllPointerOlderThan
main
Tadashi G. Takaoka 2013-05-15 12:59:06 -07:00 committed by Android Git Automerger
commit 03f2ca6d50
2 changed files with 171 additions and 160 deletions

View File

@ -48,6 +48,9 @@ public final class PointerTrackerQueue {
public void add(final Element pointer) { public void add(final Element pointer) {
synchronized (mExpandableArrayOfActivePointers) { synchronized (mExpandableArrayOfActivePointers) {
if (DEBUG) {
Log.d(TAG, "add: " + pointer + " " + this);
}
final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers; final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers;
final int arraySize = mArraySize; final int arraySize = mArraySize;
if (arraySize < expandableArray.size()) { if (arraySize < expandableArray.size()) {
@ -61,24 +64,27 @@ public final class PointerTrackerQueue {
public void remove(final Element pointer) { public void remove(final Element pointer) {
synchronized (mExpandableArrayOfActivePointers) { synchronized (mExpandableArrayOfActivePointers) {
if (DEBUG) {
Log.d(TAG, "remove: " + pointer + " " + this);
}
final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers; final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers;
final int arraySize = mArraySize; final int arraySize = mArraySize;
int newSize = 0; int newIndex = 0;
for (int index = 0; index < arraySize; index++) { for (int index = 0; index < arraySize; index++) {
final Element element = expandableArray.get(index); final Element element = expandableArray.get(index);
if (element == pointer) { if (element == pointer) {
if (newSize != index) { if (newIndex != index) {
Log.w(TAG, "Found duplicated element in remove: " + pointer); Log.w(TAG, "Found duplicated element in remove: " + pointer);
} }
continue; // Remove this element from the expandableArray. continue; // Remove this element from the expandableArray.
} }
if (newSize != index) { if (newIndex != index) {
// Shift this element toward the beginning of the expandableArray. // Shift this element toward the beginning of the expandableArray.
expandableArray.set(newSize, element); expandableArray.set(newIndex, element);
} }
newSize++; newIndex++;
} }
mArraySize = newSize; mArraySize = newIndex;
} }
} }
@ -95,8 +101,8 @@ public final class PointerTrackerQueue {
} }
final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers; final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers;
final int arraySize = mArraySize; final int arraySize = mArraySize;
int newSize, index; int newIndex, index;
for (newSize = index = 0; index < arraySize; index++) { for (newIndex = index = 0; index < arraySize; index++) {
final Element element = expandableArray.get(index); final Element element = expandableArray.get(index);
if (element == pointer) { if (element == pointer) {
break; // Stop releasing elements. break; // Stop releasing elements.
@ -105,29 +111,30 @@ public final class PointerTrackerQueue {
element.onPhantomUpEvent(eventTime); element.onPhantomUpEvent(eventTime);
continue; // Remove this element from the expandableArray. continue; // Remove this element from the expandableArray.
} }
if (newSize != index) { if (newIndex != index) {
// Shift this element toward the beginning of the expandableArray. // Shift this element toward the beginning of the expandableArray.
expandableArray.set(newSize, element); expandableArray.set(newIndex, element);
} }
newSize++; newIndex++;
} }
// Shift rest of the expandableArray. // Shift rest of the expandableArray.
int count = 0; int count = 0;
for (; index < arraySize; index++) { for (; index < arraySize; index++) {
final Element element = expandableArray.get(index); final Element element = expandableArray.get(index);
if (element == pointer) { if (element == pointer) {
if (count > 0) { count++;
if (count > 1) {
Log.w(TAG, "Found duplicated element in releaseAllPointersOlderThan: " Log.w(TAG, "Found duplicated element in releaseAllPointersOlderThan: "
+ pointer); + pointer);
} }
count++;
} }
if (newSize != index) { if (newIndex != index) {
expandableArray.set(newSize, expandableArray.get(index)); // Shift this element toward the beginning of the expandableArray.
newSize++; expandableArray.set(newIndex, expandableArray.get(index));
} }
newIndex++;
} }
mArraySize = newSize; mArraySize = newIndex;
} }
} }
@ -146,26 +153,26 @@ public final class PointerTrackerQueue {
} }
final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers; final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers;
final int arraySize = mArraySize; final int arraySize = mArraySize;
int newSize = 0, count = 0; int newIndex = 0, count = 0;
for (int index = 0; index < arraySize; index++) { for (int index = 0; index < arraySize; index++) {
final Element element = expandableArray.get(index); final Element element = expandableArray.get(index);
if (element == pointer) { if (element == pointer) {
if (count > 0) { count++;
if (count > 1) {
Log.w(TAG, "Found duplicated element in releaseAllPointersExcept: " Log.w(TAG, "Found duplicated element in releaseAllPointersExcept: "
+ pointer); + pointer);
} }
count++;
} else { } else {
element.onPhantomUpEvent(eventTime); element.onPhantomUpEvent(eventTime);
continue; // Remove this element from the expandableArray. continue; // Remove this element from the expandableArray.
} }
if (newSize != index) { if (newIndex != index) {
// Shift this element toward the beginning of the expandableArray. // Shift this element toward the beginning of the expandableArray.
expandableArray.set(newSize, element); expandableArray.set(newIndex, element);
} }
newSize++; newIndex++;
} }
mArraySize = newSize; mArraySize = newIndex;
} }
} }
@ -202,6 +209,9 @@ public final class PointerTrackerQueue {
public void cancelAllPointerTracker() { public void cancelAllPointerTracker() {
synchronized (mExpandableArrayOfActivePointers) { synchronized (mExpandableArrayOfActivePointers) {
if (DEBUG) {
Log.d(TAG, "cancelAllPointerTracker: " + this);
}
final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers; final ArrayList<Element> expandableArray = mExpandableArrayOfActivePointers;
final int arraySize = mArraySize; final int arraySize = mArraySize;
for (int index = 0; index < arraySize; index++) { for (int index = 0; index < arraySize; index++) {

View File

@ -66,23 +66,23 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
private final PointerTrackerQueue mQueue = new PointerTrackerQueue(); private final PointerTrackerQueue mQueue = new PointerTrackerQueue();
public void testEmpty() { public void testEmpty() {
assertEquals("empty queue", 0, mQueue.size()); assertEquals(0, mQueue.size());
assertEquals("empty queue", "[]", mQueue.toString()); assertEquals("[]", mQueue.toString());
} }
public void testAdd() { public void testAdd() {
mQueue.add(mElement1); mQueue.add(mElement1);
assertEquals("add element1", 1, mQueue.size()); assertEquals(1, mQueue.size());
assertEquals("after adding element1", "[1]", mQueue.toString()); assertEquals("[1]", mQueue.toString());
mQueue.add(mElement2); mQueue.add(mElement2);
assertEquals("add element2", 2, mQueue.size()); assertEquals(2, mQueue.size());
assertEquals("after adding element2", "[1 2]", mQueue.toString()); assertEquals("[1 2]", mQueue.toString());
mQueue.add(mElement3); mQueue.add(mElement3);
assertEquals("add element3", 3, mQueue.size()); assertEquals(3, mQueue.size());
assertEquals("after adding element3", "[1 2 3]", mQueue.toString()); assertEquals("[1 2 3]", mQueue.toString());
mQueue.add(mElement4); mQueue.add(mElement4);
assertEquals("add element4", 4, mQueue.size()); assertEquals(4, mQueue.size());
assertEquals("after adding element4", "[1 2 3 4]", mQueue.toString()); assertEquals("[1 2 3 4]", mQueue.toString());
} }
public void testRemove() { public void testRemove() {
@ -94,33 +94,29 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
mQueue.add(mElement4); mQueue.add(mElement4);
mQueue.remove(mElement2); mQueue.remove(mElement2);
assertEquals("remove element2", 3, mQueue.size()); assertEquals(3, mQueue.size());
assertEquals("after removing element2", "[1 3 4]", mQueue.toString()); assertEquals("[1 3 4]", mQueue.toString());
mQueue.remove(mElement4); mQueue.remove(mElement4);
assertEquals("remove element4", 2, mQueue.size()); assertEquals(2, mQueue.size());
assertEquals("after removing element4", "[1 3]", mQueue.toString()); assertEquals("[1 3]", mQueue.toString());
mQueue.remove(mElement4); mQueue.remove(mElement4);
assertEquals("remove element4 again", 2, mQueue.size()); assertEquals(2, mQueue.size());
assertEquals("after removing element4 again", "[1 3]", mQueue.toString()); assertEquals("[1 3]", mQueue.toString());
mQueue.remove(mElement1); mQueue.remove(mElement1);
assertEquals("remove element1", 1, mQueue.size()); assertEquals(1, mQueue.size());
assertEquals("after removing element4", "[3]", mQueue.toString()); assertEquals("[3]", mQueue.toString());
mQueue.remove(mElement3); mQueue.remove(mElement3);
assertEquals("remove element3", 0, mQueue.size()); assertEquals(0, mQueue.size());
assertEquals("after removing element3", "[]", mQueue.toString()); assertEquals("[]", mQueue.toString());
mQueue.remove(mElement1); mQueue.remove(mElement1);
assertEquals("remove element1 again", 0, mQueue.size()); assertEquals(0, mQueue.size());
assertEquals("after removing element1 again", "[]", mQueue.toString()); assertEquals("[]", mQueue.toString());
assertEquals("after remove elements", 0, Element.sPhantomUpCount); assertEquals(0, Element.sPhantomUpCount);
assertEquals("after remove element1", assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime);
assertEquals("after remove element2", assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
assertEquals("after remove element3",
Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
assertEquals("after remove element4",
Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
} }
public void testAddAndRemove() { public void testAddAndRemove() {
@ -132,38 +128,34 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
mQueue.add(mElement4); mQueue.add(mElement4);
mQueue.remove(mElement2); mQueue.remove(mElement2);
assertEquals("remove element2", 3, mQueue.size()); assertEquals(3, mQueue.size());
assertEquals("after removing element2", "[1 3 4]", mQueue.toString()); assertEquals("[1 3 4]", mQueue.toString());
mQueue.remove(mElement4); mQueue.remove(mElement4);
assertEquals("remove element4", 2, mQueue.size()); assertEquals(2, mQueue.size());
assertEquals("after removing element4", "[1 3]", mQueue.toString()); assertEquals("[1 3]", mQueue.toString());
mQueue.add(mElement2); mQueue.add(mElement2);
assertEquals("add element2", 3, mQueue.size()); assertEquals(3, mQueue.size());
assertEquals("after adding element2", "[1 3 2]", mQueue.toString()); assertEquals("[1 3 2]", mQueue.toString());
mQueue.remove(mElement4); mQueue.remove(mElement4);
assertEquals("remove element4 again", 3, mQueue.size()); assertEquals(3, mQueue.size());
assertEquals("after removing element4 again", "[1 3 2]", mQueue.toString()); assertEquals("[1 3 2]", mQueue.toString());
mQueue.remove(mElement1); mQueue.remove(mElement1);
assertEquals("remove element1", 2, mQueue.size()); assertEquals(2, mQueue.size());
assertEquals("after removing element4", "[3 2]", mQueue.toString()); assertEquals("[3 2]", mQueue.toString());
mQueue.add(mElement1); mQueue.add(mElement1);
assertEquals("add element1", 3, mQueue.size()); assertEquals(3, mQueue.size());
assertEquals("after adding element1", "[3 2 1]", mQueue.toString()); assertEquals("[3 2 1]", mQueue.toString());
mQueue.remove(mElement3); mQueue.remove(mElement3);
assertEquals("remove element3", 2, mQueue.size()); assertEquals(2, mQueue.size());
assertEquals("after removing element3", "[2 1]", mQueue.toString()); assertEquals("[2 1]", mQueue.toString());
mQueue.remove(mElement1); mQueue.remove(mElement1);
assertEquals("remove element1 again", 1, mQueue.size()); assertEquals(1, mQueue.size());
assertEquals("after removing element1 again", "[2]", mQueue.toString()); assertEquals("[2]", mQueue.toString());
assertEquals("after remove element1", assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime);
assertEquals("after remove element2", assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
assertEquals("after remove element3",
Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
assertEquals("after remove element4",
Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
} }
public void testReleaseAllPointers() { public void testReleaseAllPointers() {
@ -176,20 +168,33 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
final long eventTime = 123; final long eventTime = 123;
Element.sPhantomUpCount = 0; Element.sPhantomUpCount = 0;
mQueue.releaseAllPointers(eventTime); mQueue.releaseAllPointers(eventTime);
assertEquals("after releaseAllPointers", 4, Element.sPhantomUpCount); assertEquals(4, Element.sPhantomUpCount);
assertEquals("after releaseAllPointers", 0, mQueue.size()); assertEquals(0, mQueue.size());
assertEquals("after releaseAllPointers", "[]", mQueue.toString()); assertEquals("[]", mQueue.toString());
assertEquals("after releaseAllPointers element1", assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime);
eventTime + 1, mElement1.mPhantomUpEventTime); assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime);
assertEquals("after releaseAllPointers element2", assertEquals(eventTime + 3, mElement3.mPhantomUpEventTime);
eventTime + 2, mElement2.mPhantomUpEventTime); assertEquals(eventTime + 4, mElement4.mPhantomUpEventTime);
assertEquals("after releaseAllPointers element3",
eventTime + 3, mElement3.mPhantomUpEventTime);
assertEquals("after releaseAllPointers element4",
eventTime + 4, mElement4.mPhantomUpEventTime);
} }
public void testReleaseAllPointersOlderThan() { public void testReleaseAllPointersOlderThanFirst() {
mElement2.mIsModifier = true;
mQueue.add(mElement1);
mQueue.add(mElement2);
mQueue.add(mElement3);
final long eventTime = 123;
Element.sPhantomUpCount = 0;
mQueue.releaseAllPointersOlderThan(mElement1, eventTime);
assertEquals(0, Element.sPhantomUpCount);
assertEquals(3, mQueue.size());
assertEquals("[1 2 3]", mQueue.toString());
assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime);
assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime);
assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
}
public void testReleaseAllPointersOlderThanLast() {
mElement2.mIsModifier = true; mElement2.mIsModifier = true;
mQueue.add(mElement1); mQueue.add(mElement1);
mQueue.add(mElement2); mQueue.add(mElement2);
@ -199,20 +204,34 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
final long eventTime = 123; final long eventTime = 123;
Element.sPhantomUpCount = 0; Element.sPhantomUpCount = 0;
mQueue.releaseAllPointersOlderThan(mElement4, eventTime); mQueue.releaseAllPointersOlderThan(mElement4, eventTime);
assertEquals("after releaseAllPointersOlderThan", 2, Element.sPhantomUpCount); assertEquals(2, Element.sPhantomUpCount);
assertEquals("after releaseAllPointersOlderThan", 2, mQueue.size()); assertEquals(2, mQueue.size());
assertEquals("after releaseAllPointersOlderThan", "[2 4]", mQueue.toString()); assertEquals("[2 4]", mQueue.toString());
assertEquals("after releaseAllPointersOlderThan element1", assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime);
eventTime + 1, mElement1.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime);
assertEquals("after releaseAllPointersOlderThan element2", assertEquals(eventTime + 2, mElement3.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
assertEquals("after releaseAllPointersOlderThan element3",
eventTime + 2, mElement3.mPhantomUpEventTime);
assertEquals("after releaseAllPointersOlderThan element4",
Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
} }
public void testReleaseAllPointersOlderThanWithoutModifier() { public void testReleaseAllPointersOlderThanWithoutModifierMiddle() {
mQueue.add(mElement1);
mQueue.add(mElement2);
mQueue.add(mElement3);
mQueue.add(mElement4);
final long eventTime = 123;
Element.sPhantomUpCount = 0;
mQueue.releaseAllPointersOlderThan(mElement3, eventTime);
assertEquals(2, Element.sPhantomUpCount);
assertEquals(2, mQueue.size());
assertEquals("[3 4]", mQueue.toString());
assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime);
assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime);
assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
}
public void testReleaseAllPointersOlderThanWithoutModifierLast() {
mQueue.add(mElement1); mQueue.add(mElement1);
mQueue.add(mElement2); mQueue.add(mElement2);
mQueue.add(mElement3); mQueue.add(mElement3);
@ -221,19 +240,13 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
final long eventTime = 123; final long eventTime = 123;
Element.sPhantomUpCount = 0; Element.sPhantomUpCount = 0;
mQueue.releaseAllPointersOlderThan(mElement4, eventTime); mQueue.releaseAllPointersOlderThan(mElement4, eventTime);
assertEquals("after releaseAllPointersOlderThan without modifier", assertEquals(3, Element.sPhantomUpCount);
3, Element.sPhantomUpCount); assertEquals(1, mQueue.size());
assertEquals("after releaseAllPointersOlderThan without modifier", 1, mQueue.size()); assertEquals("[4]", mQueue.toString());
assertEquals("after releaseAllPointersOlderThan without modifier", assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime);
"[4]", mQueue.toString()); assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime);
assertEquals("after releaseAllPointersOlderThan without modifier element1", assertEquals(eventTime + 3, mElement3.mPhantomUpEventTime);
eventTime + 1, mElement1.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
assertEquals("after releaseAllPointersOlderThan without modifier element2",
eventTime + 2, mElement2.mPhantomUpEventTime);
assertEquals("after releaseAllPointersOlderThan without modifier element3",
eventTime + 3, mElement3.mPhantomUpEventTime);
assertEquals("after releaseAllPointersOlderThan without modifier element4",
Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
} }
public void testReleaseAllPointersExcept() { public void testReleaseAllPointersExcept() {
@ -246,17 +259,13 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
final long eventTime = 123; final long eventTime = 123;
Element.sPhantomUpCount = 0; Element.sPhantomUpCount = 0;
mQueue.releaseAllPointersExcept(mElement3, eventTime); mQueue.releaseAllPointersExcept(mElement3, eventTime);
assertEquals("after releaseAllPointersExcept", 3, Element.sPhantomUpCount); assertEquals(3, Element.sPhantomUpCount);
assertEquals("after releaseAllPointersExcept", 1, mQueue.size()); assertEquals(1, mQueue.size());
assertEquals("after releaseAllPointersExcept", "[3]", mQueue.toString()); assertEquals("[3]", mQueue.toString());
assertEquals("after releaseAllPointersExcept element1", assertEquals(eventTime + 1, mElement1.mPhantomUpEventTime);
eventTime + 1, mElement1.mPhantomUpEventTime); assertEquals(eventTime + 2, mElement2.mPhantomUpEventTime);
assertEquals("after releaseAllPointersExcept element2", assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
eventTime + 2, mElement2.mPhantomUpEventTime); assertEquals(eventTime + 3, mElement4.mPhantomUpEventTime);
assertEquals("after releaseAllPointersExcept element3",
Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
assertEquals("after releaseAllPointersExcept element4",
eventTime + 3, mElement4.mPhantomUpEventTime);
} }
public void testHasModifierKeyOlderThan() { public void testHasModifierKeyOlderThan() {
@ -268,54 +277,46 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
mQueue.add(mElement3); mQueue.add(mElement3);
mQueue.add(mElement4); mQueue.add(mElement4);
assertFalse("hasModifierKeyOlderThan element1", mQueue.hasModifierKeyOlderThan(mElement1)); assertFalse(mQueue.hasModifierKeyOlderThan(mElement1));
assertFalse("hasModifierKeyOlderThan element2", mQueue.hasModifierKeyOlderThan(mElement2)); assertFalse(mQueue.hasModifierKeyOlderThan(mElement2));
assertFalse("hasModifierKeyOlderThan element3", mQueue.hasModifierKeyOlderThan(mElement3)); assertFalse(mQueue.hasModifierKeyOlderThan(mElement3));
assertFalse("hasModifierKeyOlderThan element4", mQueue.hasModifierKeyOlderThan(mElement4)); assertFalse(mQueue.hasModifierKeyOlderThan(mElement4));
mElement2.mIsModifier = true; mElement2.mIsModifier = true;
assertFalse("hasModifierKeyOlderThan element1", mQueue.hasModifierKeyOlderThan(mElement1)); assertFalse(mQueue.hasModifierKeyOlderThan(mElement1));
assertFalse("hasModifierKeyOlderThan element2", mQueue.hasModifierKeyOlderThan(mElement2)); assertFalse(mQueue.hasModifierKeyOlderThan(mElement2));
assertTrue("hasModifierKeyOlderThan element3", mQueue.hasModifierKeyOlderThan(mElement3)); assertTrue(mQueue.hasModifierKeyOlderThan(mElement3));
assertTrue("hasModifierKeyOlderThan element4", mQueue.hasModifierKeyOlderThan(mElement4)); assertTrue(mQueue.hasModifierKeyOlderThan(mElement4));
assertEquals("after hasModifierKeyOlderThan", 0, Element.sPhantomUpCount); assertEquals(0, Element.sPhantomUpCount);
assertEquals("after hasModifierKeyOlderThan", 4, mQueue.size()); assertEquals(4, mQueue.size());
assertEquals("after hasModifierKeyOlderThan", "[1 2 3 4]", mQueue.toString()); assertEquals("[1 2 3 4]", mQueue.toString());
assertEquals("after hasModifierKeyOlderThan element1", assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime);
assertEquals("after hasModifierKeyOlderThan element2", assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
assertEquals("after hasModifierKeyOlderThan element3",
Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
assertEquals("after hasModifierKeyOlderThan element4",
Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
} }
public void testIsAnyInSlidingKeyInput() { public void testIsAnyInSlidingKeyInput() {
Element.sPhantomUpCount = 0; Element.sPhantomUpCount = 0;
assertFalse("isAnyInSlidingKeyInput empty", mQueue.isAnyInSlidingKeyInput()); assertFalse(mQueue.isAnyInSlidingKeyInput());
mQueue.add(mElement1); mQueue.add(mElement1);
mQueue.add(mElement2); mQueue.add(mElement2);
mQueue.add(mElement3); mQueue.add(mElement3);
mQueue.add(mElement4); mQueue.add(mElement4);
assertFalse("isAnyInSlidingKeyInput element1", mQueue.isAnyInSlidingKeyInput()); assertFalse(mQueue.isAnyInSlidingKeyInput());
mElement3.mIsInSlidingKeyInput = true; mElement3.mIsInSlidingKeyInput = true;
assertTrue("isAnyInSlidingKeyInput element1", mQueue.isAnyInSlidingKeyInput()); assertTrue(mQueue.isAnyInSlidingKeyInput());
assertEquals("after isAnyInSlidingKeyInput", 0, Element.sPhantomUpCount); assertEquals(0, Element.sPhantomUpCount);
assertEquals("after isAnyInSlidingKeyInput", 4, mQueue.size()); assertEquals(4, mQueue.size());
assertEquals("after isAnyInSlidingKeyInput", "[1 2 3 4]", mQueue.toString()); assertEquals("[1 2 3 4]", mQueue.toString());
assertEquals("after isAnyInSlidingKeyInput element1", assertEquals(Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement1.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime);
assertEquals("after isAnyInSlidingKeyInput element2", assertEquals(Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
Element.NOT_HAPPENED, mElement2.mPhantomUpEventTime); assertEquals(Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
assertEquals("after isAnyInSlidingKeyInput element3",
Element.NOT_HAPPENED, mElement3.mPhantomUpEventTime);
assertEquals("after isAnyInSlidingKeyInput element4",
Element.NOT_HAPPENED, mElement4.mPhantomUpEventTime);
} }
} }