Search in sources :

Example 6 with DirectoryResult

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

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 7 with DirectoryResult

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

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 8 with DirectoryResult

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

the class ModelTest method testSort_sizesWithBucketing.

// Tests that directories and files are properly bucketed when sorting by size
public void testSort_sizesWithBucketing() {
    MatrixCursor c = new MatrixCursor(COLUMNS);
    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_SIZE, i);
        // Interleave directories and text files.
        String mimeType = (i % 2 == 0) ? 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;
    model.update(r);
    boolean seenAllDirs = false;
    int previousSize = Integer.MAX_VALUE;
    BitSet seen = new BitSet(ITEM_COUNT);
    // bucketed at the front of the list, sorted by size, followed by documents, sorted by size.
    for (String id : model.getModelIds()) {
        Cursor cOut = model.getItem(id);
        seen.set(cOut.getPosition());
        String mimeType = DocumentInfo.getCursorString(cOut, Document.COLUMN_MIME_TYPE);
        if (seenAllDirs) {
            assertFalse(Document.MIME_TYPE_DIR.equals(mimeType));
        } else {
            if (!Document.MIME_TYPE_DIR.equals(mimeType)) {
                seenAllDirs = true;
                // Reset the previous size seen, because documents are bucketed separately by
                // the sort.
                previousSize = Integer.MAX_VALUE;
            }
        }
        // Check sort order - descending numerical
        int size = DocumentInfo.getCursorInt(c, Document.COLUMN_SIZE);
        assertTrue(previousSize >= size);
        previousSize = size;
    }
    // Check that all items were accounted for.
    assertEquals(ITEM_COUNT, seen.cardinality());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) BitSet(java.util.BitSet) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor)

Example 9 with DirectoryResult

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

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)

Example 10 with DirectoryResult

use of com.android.documentsui.DirectoryResult in project platform_frameworks_base by android.

the class ModelTest method setUp.

public void setUp() {
    setupTestContext();
    Random rand = new Random();
    MatrixCursor c = new MatrixCursor(COLUMNS);
    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_FLAGS, Document.FLAG_SUPPORTS_DELETE);
        // Generate random document names and sizes. This forces the model's internal sort code
        // to actually do something.
        row.add(Document.COLUMN_DISPLAY_NAME, NAMES[i]);
        row.add(Document.COLUMN_SIZE, rand.nextInt());
    }
    cursor = c;
    DirectoryResult r = new DirectoryResult();
    r.cursor = cursor;
    // Instantiate the model with a dummy view adapter and listener that (for now) do nothing.
    model = new Model();
    model.addUpdateListener(new DummyListener());
    model.update(r);
}
Also used : Random(java.util.Random) DirectoryResult(com.android.documentsui.DirectoryResult) MatrixCursor(android.database.MatrixCursor)

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