aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs/ddmuilib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ddms/libs/ddmuilib/tests')
-rw-r--r--ddms/libs/ddmuilib/tests/.classpath11
-rw-r--r--ddms/libs/ddmuilib/tests/.project17
-rw-r--r--ddms/libs/ddmuilib/tests/Android.mk37
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/BugReportParserTest.java188
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/heap/NativeHeapDataImporterTest.java74
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java75
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatStackTraceParserTest.java54
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/RollingBufferFindTest.java108
8 files changed, 0 insertions, 564 deletions
diff --git a/ddms/libs/ddmuilib/tests/.classpath b/ddms/libs/ddmuilib/tests/.classpath
deleted file mode 100644
index 83429f8..0000000
--- a/ddms/libs/ddmuilib/tests/.classpath
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry combineaccessrules="false" kind="src" path="/ddmlib"/>
- <classpathentry combineaccessrules="false" kind="src" path="/ddmuilib"/>
- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
- <classpathentry kind="var" path="ANDROID_OUT_FRAMEWORK/swt.jar"/>
- <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/eclipse/org.eclipse.equinox.common_3.6.0.v20100503.jar"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/ddms/libs/ddmuilib/tests/.project b/ddms/libs/ddmuilib/tests/.project
deleted file mode 100644
index ca60a57..0000000
--- a/ddms/libs/ddmuilib/tests/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>ddmuilib-tests</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/ddms/libs/ddmuilib/tests/Android.mk b/ddms/libs/ddmuilib/tests/Android.mk
deleted file mode 100644
index 6bbff34..0000000
--- a/ddms/libs/ddmuilib/tests/Android.mk
+++ /dev/null
@@ -1,37 +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.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-# Only compile source java files in this lib.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_MODULE := ddmuilib-tests
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_JAVA_LIBRARIES := \
- ddmlib \
- ddmuilib \
- swt \
- org.eclipse.jface_3.6.2.M20110210-1200 \
- org.eclipse.equinox.common_3.6.0.v20100503 \
- org.eclipse.core.commands_3.6.0.I20100512-1500 \
- junit
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-# Build all sub-directories
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/BugReportParserTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/BugReportParserTest.java
deleted file mode 100644
index 7894965..0000000
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/BugReportParserTest.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * 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.ddmuilib;
-
-import com.android.ddmuilib.SysinfoPanel.BugReportParser;
-import com.android.ddmuilib.SysinfoPanel.BugReportParser.DataValue;
-import com.android.ddmuilib.SysinfoPanel.BugReportParser.GfxProfileData;
-
-import junit.framework.TestCase;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.List;
-
-public class BugReportParserTest extends TestCase {
- public void testParseEclairCpuDataSet() throws IOException {
- String cpuInfo =
- "Currently running services:\n" +
- " cpuinfo\n" +
- " ----------------------------------------------------------------------------\n" +
- " DUMP OF SERVICE cpuinfo:\n" +
- " Load: 0.53 / 0.11 / 0.04\n" +
- " CPU usage from 33406ms to 28224ms ago:\n" +
- " system_server: 56% = 42% user + 13% kernel / faults: 6724 minor 9 major\n" +
- " bootanimation: 1% = 0% user + 0% kernel\n" +
- " zygote: 0% = 0% user + 0% kernel / faults: 146 minor\n" +
- " TOTAL: 98% = 67% user + 30% kernel;\n";
- BufferedReader br = new BufferedReader(new StringReader(cpuInfo));
- List<DataValue> data = BugReportParser.readCpuDataset(br);
-
- assertEquals(4, data.size());
- assertEquals("system_server (user)", data.get(0).name);
- assertEquals("Idle", data.get(3).name);
- }
-
- public void testParseJbCpuDataSet() throws IOException {
- String cpuInfo =
- "Load: 1.0 / 1.02 / 0.97\n" +
- "CPU usage from 96307ms to 36303ms ago:\n" +
- " 0.4% 675/system_server: 0.3% user + 0.1% kernel / faults: 198 minor\n" +
- " 0.1% 173/mpdecision: 0% user + 0.1% kernel\n" +
- " 0% 2856/kworker/0:2: 0% user + 0% kernel\n" +
- " 0% 3128/kworker/0:0: 0% user + 0% kernel\n" +
- "0.3% TOTAL: 0.1% user + 0% kernel + 0% iowait\n";
- BufferedReader br = new BufferedReader(new StringReader(cpuInfo));
- List<DataValue> data = BugReportParser.readCpuDataset(br);
-
- assertEquals(4, data.size());
- assertEquals("675/system_server (user)", data.get(0).name);
- assertEquals("Idle", data.get(3).name);
- }
-
- public void testParseProcRankEclair() throws IOException {
- String memInfo =
- " 51 39408K 37908K 18731K 14936K system_server\n" +
- " 96 27432K 27432K 9501K 6816K android.process.acore\n" +
- " 27 248K 248K 83K 76K /system/bin/debuggerd\n";
- BufferedReader br = new BufferedReader(new StringReader(memInfo));
- List<DataValue> data = BugReportParser.readProcRankDataset(br,
- " PID Vss Rss Pss Uss cmdline\n");
-
- assertEquals(3, data.size());
- assertEquals("debuggerd", data.get(2).name);
- if (data.get(0).value - 18731 > 0.0002) {
- fail("Unexpected PSS Value " + data.get(0).value);
- }
- }
-
- public void testParseProcRankJb() throws IOException {
- String memInfo =
- " 675 101120K 100928K 63452K 52624K system_server\n" +
- "10170 82100K 82012K 58246K 53580K com.android.chrome:sandboxed_process0\n" +
- " 8742 27296K 27224K 6849K 5620K com.google.android.apps.walletnfcrel\n" +
- " ------ ------ ------\n" +
- " 480598K 394172K TOTAL\n" +
- "\n" +
- "RAM: 1916984K total, 886404K free, 72036K buffers, 482544K cached, 456K shmem, 34864K slab\n";
- BufferedReader br = new BufferedReader(new StringReader(memInfo));
- List<DataValue> data = BugReportParser.readProcRankDataset(br,
- " PID Vss Rss Pss Uss cmdline\n");
-
- assertEquals(3, data.size());
- }
-
- public void testParseMeminfoEclair() throws IOException {
- String memInfo =
- "------ MEMORY INFO ------\n" +
- "MemTotal: 516528 kB\n" +
- "MemFree: 401036 kB\n" +
- "Buffers: 0 kB\n" +
- " PID Vss Rss Pss Uss cmdline\n" +
- " 51 39408K 37908K 18731K 14936K system_server\n" +
- " 96 27432K 27432K 9501K 6816K android.process.acore\n" +
- " 297 23348K 23348K 5245K 2276K com.android.gallery\n";
- BufferedReader br = new BufferedReader(new StringReader(memInfo));
- List<DataValue> data = BugReportParser.readMeminfoDataset(br);
- assertEquals(5, data.size());
-
- assertEquals("Free", data.get(0).name);
- }
-
- public void testParseMeminfoJb() throws IOException {
-
- String memInfo = // note: This dataset does not have all entries, so the totals will be off
- "------ MEMORY INFO ------\n" +
- "MemTotal: 1916984 kB\n" +
- "MemFree: 888048 kB\n" +
- "Buffers: 72036 kB\n" +
- " PID Vss Rss Pss Uss cmdline\n" +
- " 675 101120K 100928K 63452K 52624K system_server\n" +
- "10170 82100K 82012K 58246K 53580K com.android.chrome:sandboxed_process0\n" +
- " 8742 27296K 27224K 6849K 5620K com.google.android.apps.walletnfcrel\n" +
- " ------ ------ ------\n" +
- " 480598K 394172K TOTAL\n" +
- "\n" +
- "RAM: 1916984K total, 886404K free, 72036K buffers, 482544K cached, 456K shmem, 34864K slab\n";
-
- BufferedReader br = new BufferedReader(new StringReader(memInfo));
- List<DataValue> data = BugReportParser.readMeminfoDataset(br);
-
- assertEquals(6, data.size());
- }
-
- public void testParseGfxInfo() throws IOException {
- String gfxinfo =
- "Applications Graphics Acceleration Info:\n" +
- "Uptime: 78455570 Realtime: 78455565\n" +
- "\n" +
- "** Graphics info for pid 20517 [com.android.launcher] **\n" +
- "\n" +
- "Recent DisplayList operations\n" +
- " DrawDisplayList\n" +
- " <snip>\n" +
- " RestoreToCount\n" +
- "\n" +
- "Caches:\n" +
- "Current memory usage / total memory usage (bytes):\n" +
- " TextureCache 4663920 / 25165824\n" +
- " <snip>\n" +
- " FontRenderer 0 262144 / 262144\n" +
- "Other:\n" +
- " FboCache 2 / 16\n" +
- " PatchCache 9 / 512\n" +
- "Total memory usage:\n" +
- " 13274756 bytes, 12.66 MB\n" +
- "\n" +
- "Profile data in ms:\n" +
- "\n" +
- " com.android.launcher/com.android.launcher2.Launcher/android.view.ViewRootImpl@4265d918\n" +
- " Draw Process Execute\n" +
- " 0.85 1.10 0.61\n" +
- " 54.45 0.85 0.52\n" +
- " 1.04 2.17 0.73\n" +
- " 0.15 0.46 1.01\n" +
- "\n" +
- "View hierarchy:\n" +
- "\n" +
- " com.android.launcher/com.android.launcher2.Launcher/android.view.ViewRootImpl@4265d918\n" +
- " 276 views, 27.16 kB of display lists, 228 frames rendered\n" +
- "\n" +
- "\n" +
- "Total ViewRootImpl: 1\n" +
- "Total Views: 276\n" +
- "Total DisplayList: 27.16 kB\n";
-
- BufferedReader br = new BufferedReader(new StringReader(gfxinfo));
- List<GfxProfileData> gfxProfile = BugReportParser.parseGfxInfo(br);
-
- assertEquals(4, gfxProfile.size());
- assertEquals(0.85, gfxProfile.get(0).draw);
- assertEquals(1.01, gfxProfile.get(3).execute);
- }
-}
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/heap/NativeHeapDataImporterTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/heap/NativeHeapDataImporterTest.java
deleted file mode 100644
index 4487454..0000000
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/heap/NativeHeapDataImporterTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.ddmuilib.heap;
-
-import com.android.ddmlib.NativeAllocationInfo;
-import com.android.ddmlib.NativeStackCallInfo;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-
-import java.io.StringReader;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-
-public class NativeHeapDataImporterTest extends TestCase {
- private static final String BASIC_TEXT =
- "Allocations: 1\n" +
- "Size: 524292\n" +
- "TotalSize: 524292\n" +
- "BeginStacktrace:\n" +
- " 40170bd8 /libc_malloc_leak.so --- getbacktrace --- /b/malloc_leak.c:258\n" +
- " 400910d6 /lib/libc.so --- ca110c --- /bionic/malloc_debug_common.c:227\n" +
- " 5dd6abfe /lib/libcgdrv.so --- 5dd6abfe ---\n" +
- " 5dd98a8e /lib/libcgdrv.so --- 5dd98a8e ---\n" +
- "EndStacktrace\n";
-
- private NativeHeapDataImporter mImporter;
-
- public void testImportValidAllocation() {
- mImporter = createImporter(BASIC_TEXT);
- try {
- mImporter.run(new NullProgressMonitor());
- } catch (InvocationTargetException e) {
- fail("Unexpected exception while parsing text: " + e.getTargetException().getMessage());
- } catch (InterruptedException e) {
- fail("Tests are not interrupted!");
- }
-
- NativeHeapSnapshot snapshot = mImporter.getImportedSnapshot();
- assertNotNull(snapshot);
-
- // check whether all details have been parsed correctly
- assertEquals(1, snapshot.getAllocations().size());
-
- NativeAllocationInfo info = snapshot.getAllocations().get(0);
-
- assertEquals(1, info.getAllocationCount());
- assertEquals(524292, info.getSize());
- assertEquals(true, info.isStackCallResolved());
-
- List<NativeStackCallInfo> stack = info.getResolvedStackCall();
- assertEquals(4, stack.size());
- }
-
- private NativeHeapDataImporter createImporter(String contentsToParse) {
- StringReader r = new StringReader(contentsToParse);
- return new NativeHeapDataImporter(r);
- }
-}
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java
deleted file mode 100644
index e6c0e76..0000000
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.ddmuilib.logcat;
-
-import com.android.ddmlib.Log.LogLevel;
-import com.android.ddmlib.logcat.LogCatFilter;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class LogCatFilterSettingsSerializerTest extends TestCase {
- /* test that decode(encode(f)) = f */
- public void testSerializer() {
- LogCatFilter fs = new LogCatFilter(
- "TestFilter", //$NON-NLS-1$
- "Tag'.*Regex", //$NON-NLS-1$
- "regexForTextField..''", //$NON-NLS-1$
- "123", //$NON-NLS-1$
- "TestAppName.*", //$NON-NLS-1$
- LogLevel.ERROR);
-
- LogCatFilterSettingsSerializer serializer = new LogCatFilterSettingsSerializer();
- String s = serializer.encodeToPreferenceString(Arrays.asList(fs),
- new HashMap<LogCatFilter, LogCatFilterData>());
- List<LogCatFilter> decodedFiltersList = serializer.decodeFromPreferenceString(s);
-
- assertEquals(1, decodedFiltersList.size());
-
- LogCatFilter dfs = decodedFiltersList.get(0);
- assertEquals(fs.getName(), dfs.getName());
- assertEquals(fs.getTag(), dfs.getTag());
- assertEquals(fs.getText(), dfs.getText());
- assertEquals(fs.getPid(), dfs.getPid());
- assertEquals(fs.getAppName(), dfs.getAppName());
- assertEquals(fs.getLogLevel(), dfs.getLogLevel());
- }
-
- /* test that transient filters are not persisted */
- public void testTransientFilters() {
- LogCatFilter fs = new LogCatFilter(
- "TestFilter", //$NON-NLS-1$
- "Tag'.*Regex", //$NON-NLS-1$
- "regexForTextField..''", //$NON-NLS-1$
- "123", //$NON-NLS-1$
- "TestAppName.*", //$NON-NLS-1$
- LogLevel.ERROR);
- LogCatFilterData fd = new LogCatFilterData(fs);
- fd.setTransient();
- HashMap<LogCatFilter, LogCatFilterData> fdMap =
- new HashMap<LogCatFilter, LogCatFilterData>();
- fdMap.put(fs, fd);
-
- LogCatFilterSettingsSerializer serializer = new LogCatFilterSettingsSerializer();
- String s = serializer.encodeToPreferenceString(Arrays.asList(fs), fdMap);
- List<LogCatFilter> decodedFiltersList = serializer.decodeFromPreferenceString(s);
-
- assertEquals(0, decodedFiltersList.size());
- }
-}
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatStackTraceParserTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatStackTraceParserTest.java
deleted file mode 100644
index 7d9869a..0000000
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatStackTraceParserTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.ddmuilib.logcat;
-
-import junit.framework.TestCase;
-
-public class LogCatStackTraceParserTest extends TestCase {
- private LogCatStackTraceParser mTranslator;
-
- private static final String SAMPLE_METHOD = "com.foo.Class.method"; //$NON-NLS-1$
- private static final String SAMPLE_FNAME = "FileName"; //$NON-NLS-1$
- private static final int SAMPLE_LINENUM = 20;
- private static final String SAMPLE_TRACE =
- String.format(" at %s(%s.groovy:%d)", //$NON-NLS-1$
- SAMPLE_METHOD, SAMPLE_FNAME, SAMPLE_LINENUM);
-
- @Override
- protected void setUp() throws Exception {
- mTranslator = new LogCatStackTraceParser();
- }
-
- public void testIsValidExceptionTrace() {
- assertTrue(mTranslator.isValidExceptionTrace(SAMPLE_TRACE));
- assertFalse(mTranslator.isValidExceptionTrace(
- "java.lang.RuntimeException: message")); //$NON-NLS-1$
- assertFalse(mTranslator.isValidExceptionTrace(
- "at com.foo.test(Ins.java:unknown)")); //$NON-NLS-1$
- }
-
- public void testGetMethodName() {
- assertEquals(SAMPLE_METHOD, mTranslator.getMethodName(SAMPLE_TRACE));
- }
-
- public void testGetFileName() {
- assertEquals(SAMPLE_FNAME, mTranslator.getFileName(SAMPLE_TRACE));
- }
-
- public void testGetLineNumber() {
- assertEquals(SAMPLE_LINENUM, mTranslator.getLineNumber(SAMPLE_TRACE));
- }
-}
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/RollingBufferFindTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/RollingBufferFindTest.java
deleted file mode 100644
index 32a36c4..0000000
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/RollingBufferFindTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.ddmuilib.logcat;
-
-import com.android.ddmuilib.AbstractBufferFindTarget;
-
-import junit.framework.TestCase;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class RollingBufferFindTest extends TestCase {
- public class FindTarget extends AbstractBufferFindTarget {
- private int mSelectedItem = -1;
- private int mItemReadCount = 0;
- private List<String> mItems = Arrays.asList(
- "abc",
- "def",
- "abc",
- null,
- "xyz"
- );
-
- @Override
- public int getItemCount() {
- return mItems.size();
- }
-
- @Override
- public String getItem(int index) {
- mItemReadCount++;
- return mItems.get(index);
- }
-
- @Override
- public void selectAndReveal(int index) {
- mSelectedItem = index;
- }
-
- @Override
- public int getStartingIndex() {
- return mItems.size() - 1;
- }
- }
- FindTarget mFindTarget = new FindTarget();
-
- public void testMultipleMatch() {
- mFindTarget.mSelectedItem = -1;
-
- String text = "abc";
- int lastIndex = mFindTarget.mItems.lastIndexOf(text);
- int firstIndex = mFindTarget.mItems.indexOf(text);
-
- // the first time we search through the buffer we should hit the item at lastIndex
- assertTrue(mFindTarget.findAndSelect(text, true, false));
- assertEquals(lastIndex, mFindTarget.mSelectedItem);
-
- // subsequent search should hit the item at first index
- assertTrue(mFindTarget.findAndSelect(text, false, false));
- assertEquals(firstIndex, mFindTarget.mSelectedItem);
-
- // search again should roll over and hit the last index
- assertTrue(mFindTarget.findAndSelect(text, false, false));
- assertEquals(lastIndex, mFindTarget.mSelectedItem);
- }
-
- public void testMissingItem() {
- mFindTarget.mSelectedItem = -1;
- mFindTarget.mItemReadCount = 0;
-
- // should not match
- assertFalse(mFindTarget.findAndSelect("nonexistent", true, false));
-
- // no item should be selected
- assertEquals(-1, mFindTarget.mSelectedItem);
-
- // but all items should have been read in once
- assertEquals(mFindTarget.getItemCount(), mFindTarget.mItemReadCount);
- }
-
- public void testSearchDirection() {
- String text = "abc";
- int lastIndex = mFindTarget.mItems.lastIndexOf(text);
- int firstIndex = mFindTarget.mItems.indexOf(text);
-
- // the first time we search through the buffer we should hit the "abc" from the last
- assertTrue(mFindTarget.findAndSelect(text, true, false));
- assertEquals(lastIndex, mFindTarget.mSelectedItem);
-
- // searching forward from there should also hit the first index
- assertTrue(mFindTarget.findAndSelect(text, false, true));
- assertEquals(firstIndex, mFindTarget.mSelectedItem);
- }
-}