use of com.android.documentsui.DirectoryResult in project android_frameworks_base by DirtyUnicorns.
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);
}
}
use of com.android.documentsui.DirectoryResult in project android_frameworks_base by DirtyUnicorns.
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());
}
use of com.android.documentsui.DirectoryResult in project android_frameworks_base by AOSPA.
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 AOSPA.
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());
}
use of com.android.documentsui.DirectoryResult in project android_frameworks_base by ResurrectionRemix.
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);
}
}
Aggregations