Search in sources :

Example 31 with MergeCursor

use of android.database.MergeCursor in project android_frameworks_base by crdroidandroid.

the class ModelTest method testModelIdIsUnique.

// Tests multiple authorities with clashing document IDs.
public void testModelIdIsUnique() {
    MatrixCursor cIn1 = new MatrixCursor(COLUMNS);
    MatrixCursor cIn2 = new MatrixCursor(COLUMNS);
    // Make two sets of items with the same IDs, under different authorities.
    final String AUTHORITY0 = "auth0";
    final String AUTHORITY1 = "auth1";
    for (int i = 0; i < ITEM_COUNT; ++i) {
        MatrixCursor.RowBuilder row0 = cIn1.newRow();
        row0.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY0);
        row0.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
        MatrixCursor.RowBuilder row1 = cIn2.newRow();
        row1.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY1);
        row1.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
    }
    Cursor cIn = new MergeCursor(new Cursor[] { cIn1, cIn2 });
    // Update the model, then make sure it contains all the expected items.
    DirectoryResult r = new DirectoryResult();
    r.cursor = cIn;
    model.update(r);
    assertEquals(ITEM_COUNT * 2, model.getItemCount());
    BitSet b0 = new BitSet(ITEM_COUNT);
    BitSet b1 = new BitSet(ITEM_COUNT);
    for (String id : model.getModelIds()) {
        Cursor cOut = model.getItem(id);
        String authority = DocumentInfo.getCursorString(cOut, RootCursorWrapper.COLUMN_AUTHORITY);
        String docId = DocumentInfo.getCursorString(cOut, Document.COLUMN_DOCUMENT_ID);
        switch(authority) {
            case AUTHORITY0:
                b0.set(Integer.parseInt(docId));
                break;
            case AUTHORITY1:
                b1.set(Integer.parseInt(docId));
                break;
            default:
                fail("Unrecognized authority string");
        }
    }
    assertEquals(ITEM_COUNT, b0.cardinality());
    assertEquals(ITEM_COUNT, b1.cardinality());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) MergeCursor(android.database.MergeCursor) BitSet(java.util.BitSet) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor)

Aggregations

MergeCursor (android.database.MergeCursor)31 Cursor (android.database.Cursor)25 MatrixCursor (android.database.MatrixCursor)13 SQLiteCursor (android.database.sqlite.SQLiteCursor)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Bundle (android.os.Bundle)5 DirectoryResult (com.android.documentsui.DirectoryResult)5 DocumentInfo.getCursorString (com.android.documentsui.model.DocumentInfo.getCursorString)5 RootInfo (com.android.documentsui.model.RootInfo)5 IOException (java.io.IOException)5 BitSet (java.util.BitSet)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ExecutionException (java.util.concurrent.ExecutionException)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 LinkedList (java.util.LinkedList)2 Intent (android.content.Intent)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1 Uri (android.net.Uri)1 List (java.util.List)1