Search in sources :

Example 41 with DirectoryResult

use of com.android.documentsui.DirectoryResult 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)

Example 42 with DirectoryResult

use of com.android.documentsui.DirectoryResult in project android_frameworks_base by crdroidandroid.

the class ModelTest method testSort_time.

public void testSort_time() {
    final int DL_COUNT = 3;
    MatrixCursor c = new MatrixCursor(COLUMNS);
    Set<String> currentDownloads = new HashSet<>();
    // Add some files
    for (int i = 0; i < ITEM_COUNT; i++) {
        MatrixCursor.RowBuilder row = c.newRow();
        row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
        row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
        row.add(Document.COLUMN_LAST_MODIFIED, System.currentTimeMillis());
    }
    // Add some current downloads (no timestamp)
    for (int i = ITEM_COUNT; i < ITEM_COUNT + DL_COUNT; i++) {
        MatrixCursor.RowBuilder row = c.newRow();
        String id = Integer.toString(i);
        row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
        row.add(Document.COLUMN_DOCUMENT_ID, id);
        currentDownloads.add(id);
    }
    DirectoryResult r = new DirectoryResult();
    r.cursor = c;
    r.sortOrder = State.SORT_ORDER_LAST_MODIFIED;
    model.update(r);
    String[] ids = model.getModelIds();
    // Check that all items were accounted for
    assertEquals(ITEM_COUNT + DL_COUNT, ids.length);
    // Check that active downloads are sorted to the top.
    for (int i = 0; i < DL_COUNT; i++) {
        assertTrue(currentDownloads.contains(ids[i]));
    }
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) MatrixCursor(android.database.MatrixCursor) HashSet(java.util.HashSet)

Example 43 with DirectoryResult

use of com.android.documentsui.DirectoryResult in project android_frameworks_base by crdroidandroid.

the class SectionBreakDocumentsAdapterWrapperTest method testItemCount_allDirs.

// Tests that the item count is correct for a directory containing only subdirs.
public void testItemCount_allDirs() {
    MatrixCursor c = new MatrixCursor(TestModel.COLUMNS);
    for (int i = 0; i < 5; ++i) {
        MatrixCursor.RowBuilder row = c.newRow();
        row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
        row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
        row.add(Document.COLUMN_SIZE, i);
        row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
    }
    DirectoryResult r = new DirectoryResult();
    r.cursor = c;
    r.sortOrder = State.SORT_ORDER_SIZE;
    mModel.update(r);
    assertEquals(mModel.getItemCount(), mAdapter.getItemCount());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) MatrixCursor(android.database.MatrixCursor)

Example 44 with DirectoryResult

use of com.android.documentsui.DirectoryResult in project android_frameworks_base by crdroidandroid.

the class SectionBreakDocumentsAdapterWrapperTest method testItemCount_mixed.

// Tests that the item count is correct for a directory containing files and subdirs.
public void testItemCount_mixed() {
    MatrixCursor c = new MatrixCursor(TestModel.COLUMNS);
    for (int i = 0; i < 5; ++i) {
        MatrixCursor.RowBuilder row = c.newRow();
        row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
        row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
        row.add(Document.COLUMN_SIZE, i);
        String mimeType = (i < 2) ? Document.MIME_TYPE_DIR : "text/*";
        row.add(Document.COLUMN_MIME_TYPE, mimeType);
    }
    DirectoryResult r = new DirectoryResult();
    r.cursor = c;
    r.sortOrder = State.SORT_ORDER_SIZE;
    mModel.update(r);
    assertEquals(mModel.getItemCount() + 1, mAdapter.getItemCount());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) MatrixCursor(android.database.MatrixCursor)

Example 45 with DirectoryResult

use of com.android.documentsui.DirectoryResult in project android_frameworks_base by crdroidandroid.

the class ModelTest method testSort_names.

// Tests sorting by item name.
public void testSort_names() {
    BitSet seen = new BitSet(ITEM_COUNT);
    List<String> names = new ArrayList<>();
    DirectoryResult r = new DirectoryResult();
    r.cursor = cursor;
    r.sortOrder = State.SORT_ORDER_DISPLAY_NAME;
    model.update(r);
    for (String id : model.getModelIds()) {
        Cursor c = model.getItem(id);
        seen.set(c.getPosition());
        names.add(DocumentInfo.getCursorString(c, Document.COLUMN_DISPLAY_NAME));
    }
    assertEquals(ITEM_COUNT, seen.cardinality());
    for (int i = 0; i < names.size() - 1; ++i) {
        assertTrue(Shared.compareToIgnoreCaseNullable(names.get(i), names.get(i + 1)) <= 0);
    }
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor)

Aggregations

MatrixCursor (android.database.MatrixCursor)45 DirectoryResult (com.android.documentsui.DirectoryResult)45 Cursor (android.database.Cursor)20 MergeCursor (android.database.MergeCursor)20 BitSet (java.util.BitSet)20 Random (java.util.Random)10 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5