use of com.android.documentsui.DirectoryResult in project android_frameworks_base by ResurrectionRemix.
the class ModelTest method testSort_sizes.
// Tests sorting by item size.
public void testSort_sizes() {
DirectoryResult r = new DirectoryResult();
r.cursor = cursor;
r.sortOrder = State.SORT_ORDER_SIZE;
model.update(r);
BitSet seen = new BitSet(ITEM_COUNT);
int previousSize = Integer.MAX_VALUE;
for (String id : model.getModelIds()) {
Cursor c = model.getItem(id);
seen.set(c.getPosition());
// 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());
}
use of com.android.documentsui.DirectoryResult in project android_frameworks_base by ResurrectionRemix.
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());
}
use of com.android.documentsui.DirectoryResult in project android_frameworks_base by ResurrectionRemix.
the class TestModel method update.
void update(String... names) {
Random rand = new Random();
MatrixCursor c = new MatrixCursor(COLUMNS);
for (int i = 0; i < names.length; i++) {
MatrixCursor.RowBuilder row = c.newRow();
row.add(RootCursorWrapper.COLUMN_AUTHORITY, mAuthority);
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());
}
DirectoryResult r = new DirectoryResult();
r.cursor = c;
update(r);
}
use of com.android.documentsui.DirectoryResult in project android_frameworks_base by ResurrectionRemix.
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]));
}
}
use of com.android.documentsui.DirectoryResult in project android_frameworks_base by ResurrectionRemix.
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());
}
Aggregations