diff options
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/EventRingBufferTests.java | 154 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/ImeLoggerTests.java | 59 |
2 files changed, 154 insertions, 59 deletions
diff --git a/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java b/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java new file mode 100644 index 000000000..620f036db --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/EventRingBufferTests.java @@ -0,0 +1,154 @@ +/* + * 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.latin.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/ImeLoggerTests.java b/tests/src/com/android/inputmethod/latin/ImeLoggerTests.java deleted file mode 100644 index 234559bb7..000000000 --- a/tests/src/com/android/inputmethod/latin/ImeLoggerTests.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.android.inputmethod.latin; - -import android.test.ServiceTestCase; - -public class ImeLoggerTests extends ServiceTestCase<LatinIME> { - - private static final String WORD_SEPARATORS - = ".\u0009\u0020,;:!?\n()[]*&@{}<>;_+=|\\u0022"; - - public ImeLoggerTests() { - super(LatinIME.class); - } - static LatinImeLogger sLogger; - @Override - protected void setUp() { - try { - super.setUp(); - } catch (Exception e) { - e.printStackTrace(); - } - setupService(); - // startService(null); // can't be started because VoiceInput can't be found. - final LatinIME context = getService(); - context.mWordSeparators = WORD_SEPARATORS; - LatinImeLogger.init(context); - sLogger = LatinImeLogger.sLatinImeLogger; - } - /*********************** Tests *********************/ - public void testRingBuffer() { - for (int i = 0; i < sLogger.mRingCharBuffer.BUFSIZE * 2; ++i) { - LatinImeLogger.logOnDelete(); - } - assertEquals("", sLogger.mRingCharBuffer.getLastString()); - LatinImeLogger.logOnInputChar('t'); - LatinImeLogger.logOnInputChar('g'); - LatinImeLogger.logOnInputChar('i'); - LatinImeLogger.logOnInputChar('s'); - LatinImeLogger.logOnInputChar(' '); - LatinImeLogger.logOnAutoSuggestion("tgis", "this"); - LatinImeLogger.logOnInputChar(' '); - LatinImeLogger.logOnDelete(); - assertEquals("", sLogger.mRingCharBuffer.getLastString()); - LatinImeLogger.logOnDelete(); - assertEquals("tgis", sLogger.mRingCharBuffer.getLastString()); - assertEquals("tgis", LatinImeLogger.sLastAutoSuggestBefore); - LatinImeLogger.logOnAutoSuggestionCanceled(); - assertEquals("", LatinImeLogger.sLastAutoSuggestBefore); - LatinImeLogger.logOnDelete(); - assertEquals("tgi", sLogger.mRingCharBuffer.getLastString()); - for (int i = 0; i < sLogger.mRingCharBuffer.BUFSIZE * 2; ++i) { - LatinImeLogger.logOnDelete(); - } - assertEquals("", sLogger.mRingCharBuffer.getLastString()); - for (int i = 0; i < sLogger.mRingCharBuffer.BUFSIZE * 2; ++i) { - LatinImeLogger.logOnInputChar('a'); - } - assertEquals(sLogger.mRingCharBuffer.BUFSIZE, sLogger.mRingCharBuffer.length); - } -} |