SearchRecentSuggestionsProviderTest.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.content;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.app.SearchManager;
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.database.Cursor;
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.net.Uri;
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.provider.SearchRecentSuggestions;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.test.ProviderTestCase2;
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.test.suitebuilder.annotation.Suppress;
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Very simple provider that I can instantiate right here.
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectclass TestProvider extends SearchRecentSuggestionsProvider {
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    final static String AUTHORITY = "android.content.TestProvider";
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    final static int MODE = DATABASE_MODE_QUERIES + DATABASE_MODE_2LINES;
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public TestProvider() {
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        super();
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        setupSuggestions(AUTHORITY, MODE);
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * ProviderTestCase that performs unit tests of SearchRecentSuggestionsProvider.
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You can run this test in isolation via the commands:
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * $ (cd tests/FrameworkTests/ && mm) && adb sync
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * $ adb shell am instrument -w \
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *     -e class android.content.SearchRecentSuggestionsProviderTest
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *     com.android.frameworktest.tests/android.test.InstrumentationTestRunner
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// Suppress these until bug http://b/issue?id=1416586 is fixed.
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project@Suppress
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class SearchRecentSuggestionsProviderTest extends ProviderTestCase2<TestProvider> {
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // Elements prepared by setUp()
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    SearchRecentSuggestions mSearchHelper;
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public SearchRecentSuggestionsProviderTest() {
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        super(TestProvider.class, TestProvider.AUTHORITY);
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * During setup, grab a helper for DB access
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @Override
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setUp() throws Exception {
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        super.setUp();
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // Use the recent suggestions helper.  As long as we pass in our isolated context,
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // it should correctly access the provider under test.
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mSearchHelper = new SearchRecentSuggestions(getMockContext(),
709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                TestProvider.AUTHORITY, TestProvider.MODE);
719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // test for empty database at setup time
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(0);
749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Simple test to see if we can instantiate the whole mess.
789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void testSetup() {
809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue(true);
819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Simple test to see if we can write and read back a single query
859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void testOneQuery() {
879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String TEST_LINE1 = "test line 1";
889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String TEST_LINE2 = "test line 2";
899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mSearchHelper.saveRecentQuery(TEST_LINE1, TEST_LINE2);
909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // make sure that there are is exactly one entry returned by a non-filtering cursor
929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(1);
939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // test non-filtering cursor for correct entry
959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(null, 1, 1, TEST_LINE1, TEST_LINE2);
969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // test filtering cursor for correct entry
989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(TEST_LINE1, 1, 1, TEST_LINE1, TEST_LINE2);
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(TEST_LINE2, 1, 1, TEST_LINE1, TEST_LINE2);
1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // test that a different filter returns zero results
1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts("bad filter", 0, 0, null, null);
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Simple test to see if we can write and read back a diverse set of queries
1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void testMixedQueries() {
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // we'll make 10 queries named "query x" and 10 queries named "test x"
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String TEST_GROUP_1 = "query ";
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String TEST_GROUP_2 = "test ";
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String TEST_LINE2 = "line2 ";
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_COUNT = 10;
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_COUNT, TEST_GROUP_1, TEST_LINE2);
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_COUNT, TEST_GROUP_2, TEST_LINE2);
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check counts
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(2 * GROUP_COUNT);
1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check that each query returns the right result counts
1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(TEST_GROUP_1, GROUP_COUNT, GROUP_COUNT, null, null);
1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(TEST_GROUP_2, GROUP_COUNT, GROUP_COUNT, null, null);
1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(TEST_LINE2, 2 * GROUP_COUNT, 2 * GROUP_COUNT, null, null);
1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Test that the reordering code works properly.  The most recently injected queries
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * should replace existing queries and be sorted to the top of the list.
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void testReordering() {
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // first we'll make 10 queries named "group1 x"
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_1_COUNT = 10;
1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_1_QUERY = "group1 ";
1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_1_LINE2 = "line2 ";
1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_1_COUNT, GROUP_1_QUERY, GROUP_1_LINE2);
1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check totals
1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(GROUP_1_COUNT);
1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // guarantee that group 1 has older timestamps
1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeDelay();
1439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // next we'll add 10 entries named "group2 x"
1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_2_COUNT = 10;
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_2_QUERY = "group2 ";
1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_2_LINE2 = "line2 ";
1489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_2_COUNT, GROUP_2_QUERY, GROUP_2_LINE2);
1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check totals
1519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(GROUP_1_COUNT + GROUP_2_COUNT);
1529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // guarantee that group 2 has older timestamps
1549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeDelay();
1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // now refresh 5 of the 10 from group 1
1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // change line2 so they can be more easily tracked
1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_3_COUNT = 5;
1599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_3_QUERY = GROUP_1_QUERY;
1609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_3_LINE2 = "refreshed ";
1619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_3_COUNT, GROUP_3_QUERY, GROUP_3_LINE2);
1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // confirm that the total didn't change (those were replacements, not adds)
1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(GROUP_1_COUNT + GROUP_2_COUNT);
1659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // confirm that the are now 5 in group 1, 10 in group 2, and 5 in group 3
1679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int newGroup1Count = GROUP_1_COUNT - GROUP_3_COUNT;
1689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(GROUP_1_QUERY, newGroup1Count, newGroup1Count, null, GROUP_1_LINE2);
1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(GROUP_2_QUERY, GROUP_2_COUNT, GROUP_2_COUNT, null, null);
1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(GROUP_3_QUERY, GROUP_3_COUNT, GROUP_3_COUNT, null, GROUP_3_LINE2);
1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // finally, spot check that the right groups are in the right places
1739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // the ordering should be group 3 (newest), group 2, group 1 (oldest)
1749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Cursor c = getQueryCursor(null);
1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int colQuery = c.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_QUERY);
1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int colDisplay1 = c.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1);
1779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int colDisplay2 = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2);
1789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // Spot check the first and last expected entries of group 3
1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.moveToPosition(0);
1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue("group 3 did not properly reorder to head of list",
1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                checkRow(c, colQuery, colDisplay1, colDisplay2, GROUP_3_QUERY, GROUP_3_LINE2));
1839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.move(GROUP_3_COUNT - 1);
1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue("group 3 did not properly reorder to head of list",
1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                checkRow(c, colQuery, colDisplay1, colDisplay2, GROUP_3_QUERY, GROUP_3_LINE2));
1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // Spot check the first and last expected entries of group 2
1889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.move(1);
1899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue("group 2 not in expected position after reordering",
1909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                checkRow(c, colQuery, colDisplay1, colDisplay2, GROUP_2_QUERY, GROUP_2_LINE2));
1919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.move(GROUP_2_COUNT - 1);
1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue("group 2 not in expected position after reordering",
1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                checkRow(c, colQuery, colDisplay1, colDisplay2, GROUP_2_QUERY, GROUP_2_LINE2));
1949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // Spot check the first and last expected entries of group 1
1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.move(1);
1979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue("group 1 not in expected position after reordering",
1989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                checkRow(c, colQuery, colDisplay1, colDisplay2, GROUP_1_QUERY, GROUP_1_LINE2));
1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.move(newGroup1Count - 1);
2009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue("group 1 not in expected position after reordering",
2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                checkRow(c, colQuery, colDisplay1, colDisplay2, GROUP_1_QUERY, GROUP_1_LINE2));
2029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.close();
2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Test that the pruning code works properly,  The database should not go beyond 250 entries,
2089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * and the oldest entries should always be discarded first.
2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * TODO:  This is a slow test, do we have annotation for that?
2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void testPruning() {
2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // first we'll make 50 queries named "group1 x"
2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_1_COUNT = 50;
2159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_1_QUERY = "group1 ";
2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_1_LINE2 = "line2 ";
2179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_1_COUNT, GROUP_1_QUERY, GROUP_1_LINE2);
2189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check totals
2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(GROUP_1_COUNT);
2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // guarantee that group 1 has older timestamps (and will be pruned first)
2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeDelay();
2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // next we'll add 200 entries named "group2 x"
2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_2_COUNT = 200;
2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_2_QUERY = "group2 ";
2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_2_LINE2 = "line2 ";
2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_2_COUNT, GROUP_2_QUERY, GROUP_2_LINE2);
2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check totals
2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(GROUP_1_COUNT + GROUP_2_COUNT);
2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // Finally we'll add 10 more entries named "group3 x"
2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // These should push out 10 entries from group 1
2369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_3_COUNT = 10;
2379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_3_QUERY = "group3 ";
2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_3_LINE2 = "line2 ";
2399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_3_COUNT, GROUP_3_QUERY, GROUP_3_LINE2);
2409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // total should still be 250
2429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(GROUP_1_COUNT + GROUP_2_COUNT);
2439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // there should be 40 group 1, 200 group 2, and 10 group 3
2459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int group1NewCount = GROUP_1_COUNT-GROUP_3_COUNT;
2469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(GROUP_1_QUERY, group1NewCount, group1NewCount, null, null);
2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(GROUP_2_QUERY, GROUP_2_COUNT, GROUP_2_COUNT, null, null);
2489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkResultCounts(GROUP_3_QUERY, GROUP_3_COUNT, GROUP_3_COUNT, null, null);
2499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Test that the clear history code works properly.
2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void testClear() {
2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // first we'll make 10 queries named "group1 x"
2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_1_COUNT = 10;
2579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_1_QUERY = "group1 ";
2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_1_LINE2 = "line2 ";
2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_1_COUNT, GROUP_1_QUERY, GROUP_1_LINE2);
2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // next we'll add 10 entries named "group2 x"
2629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final int GROUP_2_COUNT = 10;
2639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_2_QUERY = "group2 ";
2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        final String GROUP_2_LINE2 = "line2 ";
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        writeEntries(GROUP_2_COUNT, GROUP_2_QUERY, GROUP_2_LINE2);
2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check totals
2689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(GROUP_1_COUNT + GROUP_2_COUNT);
2699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // delete all
2719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mSearchHelper.clearHistory();
2729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // check totals
2749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        checkOpenCursorCount(0);
2759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Write a sequence of queries into the database, with incrementing counters in the strings.
2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private void writeEntries(int groupCount, String line1Base, String line2Base) {
2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        for (int i = 0; i < groupCount; i++) {
2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            final String line1 = line1Base + i;
2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            final String line2 = line2Base + i;
2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mSearchHelper.saveRecentQuery(line1, line2);
2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
2869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * A very slight delay to ensure that successive groups of queries in the DB cannot
2909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * have the same timestamp.
2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private void writeDelay() {
2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
2949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Thread.sleep(10);
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (InterruptedException e) {
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            fail("Interrupted sleep.");
2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Access an "open" (no selection) suggestions cursor and confirm that it has the specified
3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * number of entries.
3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
3049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param expectCount The expected number of entries returned by the cursor.
3059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private void checkOpenCursorCount(int expectCount) {
3079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Cursor c = getQueryCursor(null);
3089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertEquals(expectCount, c.getCount());
3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.close();
3109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Set up a filter cursor and then scan it for specific results.
3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param queryString The query string to apply.
3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param minRows The minimum number of matching rows that must be found.
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param maxRows The maximum number of matching rows that must be found.
3189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param matchDisplay1 If non-null, must match DISPLAY1 column if row counts as match
3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param matchDisplay2 If non-null, must match DISPLAY2 column if row counts as match
3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private void checkResultCounts(String queryString, int minRows, int maxRows,
3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String matchDisplay1, String matchDisplay2) {
3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // get the cursor and apply sanity checks to result
3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Cursor c = getQueryCursor(queryString);
3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertNotNull(c);
3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue("Insufficient rows in filtered cursor", c.getCount() >= minRows);
3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // look for minimum set of columns (note, display2 is optional)
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int colQuery = c.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_QUERY);
3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int colDisplay1 = c.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1);
3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int colDisplay2 = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2);
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // now loop through rows and look for desired rows
3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        int foundRows = 0;
3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.moveToFirst();
3379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        while (!c.isAfterLast()) {
3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (checkRow(c, colQuery, colDisplay1, colDisplay2, matchDisplay1, matchDisplay2)) {
3399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                foundRows++;
3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
3419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            c.moveToNext();
3429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
3439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // now check the results
3459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue(minRows <= foundRows);
3469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertTrue(foundRows <= maxRows);
3479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        c.close();
3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Check a single row for equality with target strings.
3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param c The cursor, already moved to the row
3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param colQuery The column # containing the query.  The query must match display1.
3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param colDisp1 The column # containing display line 1.
3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param colDisp2 The column # containing display line 2, or -1 if no column
3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param matchDisplay1 If non-null, this must be the prefix of display1
3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param matchDisplay2 If non-null, this must be the prefix of display2
3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return Returns true if the row is a "match"
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean checkRow(Cursor c, int colQuery, int colDisp1, int colDisp2,
3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String matchDisplay1, String matchDisplay2) {
3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        // Get the data from the row
3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String query = c.getString(colQuery);
3669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String display1 = c.getString(colDisp1);
3679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String display2 = (colDisp2 >= 0) ? c.getString(colDisp2) : null;
3689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertEquals(query, display1);
3709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        boolean result = true;
3719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (matchDisplay1 != null) {
3729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            result = result && (display1 != null) && display1.startsWith(matchDisplay1);
3739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
3749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (matchDisplay2 != null) {
3759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            result = result && (display2 != null) && display2.startsWith(matchDisplay2);
3769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return result;
3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Generate a query cursor in a manner like the search dialog would.
3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param queryString The search string, or, null for "all"
3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return Returns a cursor, or null if there was some problem.  Be sure to close the cursor
3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * when done with it.
3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private Cursor getQueryCursor(String queryString) {
3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        ContentResolver cr = getMockContext().getContentResolver();
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String uriStr = "content://" + TestProvider.AUTHORITY +
3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        '/' + SearchManager.SUGGEST_URI_PATH_QUERY;
3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Uri contentUri = Uri.parse(uriStr);
3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String[] selArgs = new String[] {queryString};
3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Cursor c = cr.query(contentUri, null, null, selArgs, null);
3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        assertNotNull(c);
4009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return c;
4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
403