GroupingListAdapterTestspublic class GroupingListAdapterTests extends android.test.AndroidTestCase Tests for {@link GroupingListAdapter}.
Running all tests:
adb shell am instrument -e class com.android.common.widget.GroupingListAdapterTests \
-w com.android.common.tests/android.test.InstrumentationTestRunner |
Fields Summary |
---|
private static final String[] | PROJECTION | private static final int | GROUPING_COLUMN_INDEX | private android.database.MatrixCursor | mCursor | private long | mNextId | private GroupingListAdapter | mAdapter |
Methods Summary |
---|
private void | assertPositionMetadata(int position, int itemType, boolean isExpanded, int cursorPosition)
GroupingListAdapter.PositionMetadata metadata = new GroupingListAdapter.PositionMetadata();
mAdapter.obtainPositionMetadata(metadata, position);
assertEquals(itemType, metadata.itemType);
if (metadata.itemType == ITEM_TYPE_GROUP_HEADER) {
assertEquals(isExpanded, metadata.isExpanded);
}
assertEquals(cursorPosition, metadata.cursorPosition);
| private void | buildCursor(java.lang.String numbers)
mCursor = new MatrixCursor(PROJECTION);
mNextId = 1;
for (String number : numbers) {
mCursor.addRow(new Object[]{mNextId, number});
mNextId++;
}
| public void | testGroupDescriptorArrayGrowth()
String[] numbers = new String[500];
for (int i = 0; i < numbers.length; i++) {
// Make groups of 2
numbers[i] = String.valueOf((i / 2) * 2);
}
buildCursor(numbers);
mAdapter.changeCursor(mCursor);
assertEquals(250, mAdapter.getCount());
| public void | testGroupingWithCollapsedGroupAtTheBeginning()
buildCursor("1", "1", "2");
mAdapter.changeCursor(mCursor);
assertEquals(2, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_GROUP_HEADER, false, 0);
assertPositionMetadata(1, ITEM_TYPE_STANDALONE, false, 2);
| public void | testGroupingWithCollapsedGroupAtTheEnd()
buildCursor("1", "2", "3", "3", "3");
mAdapter.changeCursor(mCursor);
assertEquals(3, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_STANDALONE, false, 1);
assertPositionMetadata(2, ITEM_TYPE_GROUP_HEADER, false, 2);
| public void | testGroupingWithCollapsedGroupInTheMiddle()
buildCursor("1", "2", "2", "2", "3");
mAdapter.changeCursor(mCursor);
assertEquals(3, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, false, 1);
assertPositionMetadata(2, ITEM_TYPE_STANDALONE, false, 4);
| public void | testGroupingWithExpandCollapseCycleAtTheBeginning()
buildCursor("1", "1", "2");
mAdapter.changeCursor(mCursor);
mAdapter.toggleGroup(0);
mAdapter.toggleGroup(0);
assertEquals(2, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_GROUP_HEADER, false, 0);
assertPositionMetadata(1, ITEM_TYPE_STANDALONE, false, 2);
| public void | testGroupingWithExpandedGroupAtTheBeginning()
buildCursor("1", "1", "2");
mAdapter.changeCursor(mCursor);
mAdapter.toggleGroup(0);
assertEquals(4, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_GROUP_HEADER, true, 0);
assertPositionMetadata(1, ITEM_TYPE_IN_GROUP, false, 0);
assertPositionMetadata(2, ITEM_TYPE_IN_GROUP, false, 1);
assertPositionMetadata(3, ITEM_TYPE_STANDALONE, false, 2);
| public void | testGroupingWithExpandedGroupAtTheEnd()
buildCursor("1", "2", "3", "3", "3");
mAdapter.changeCursor(mCursor);
mAdapter.toggleGroup(2);
assertEquals(6, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_STANDALONE, false, 1);
assertPositionMetadata(2, ITEM_TYPE_GROUP_HEADER, true, 2);
assertPositionMetadata(3, ITEM_TYPE_IN_GROUP, false, 2);
assertPositionMetadata(4, ITEM_TYPE_IN_GROUP, false, 3);
assertPositionMetadata(5, ITEM_TYPE_IN_GROUP, false, 4);
| public void | testGroupingWithExpandedGroupInTheMiddle()
buildCursor("1", "2", "2", "2", "3");
mAdapter.changeCursor(mCursor);
mAdapter.toggleGroup(1);
assertEquals(6, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, true, 1);
assertPositionMetadata(2, ITEM_TYPE_IN_GROUP, false, 1);
assertPositionMetadata(3, ITEM_TYPE_IN_GROUP, false, 2);
assertPositionMetadata(4, ITEM_TYPE_IN_GROUP, false, 3);
assertPositionMetadata(5, ITEM_TYPE_STANDALONE, false, 4);
| public void | testGroupingWithMultipleCollapsedGroups()
buildCursor("1", "2", "2", "3", "4", "4", "5", "5", "6");
mAdapter.changeCursor(mCursor);
assertEquals(6, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, false, 1);
assertPositionMetadata(2, ITEM_TYPE_STANDALONE, false, 3);
assertPositionMetadata(3, ITEM_TYPE_GROUP_HEADER, false, 4);
assertPositionMetadata(4, ITEM_TYPE_GROUP_HEADER, false, 6);
assertPositionMetadata(5, ITEM_TYPE_STANDALONE, false, 8);
| public void | testGroupingWithMultipleExpandedGroups()
buildCursor("1", "2", "2", "3", "4", "4", "5", "5", "6");
mAdapter.changeCursor(mCursor);
mAdapter.toggleGroup(1);
// Note that expanding the group of 2's shifted the group of 5's down from the
// 4th to the 6th position
mAdapter.toggleGroup(6);
assertEquals(10, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, true, 1);
assertPositionMetadata(2, ITEM_TYPE_IN_GROUP, false, 1);
assertPositionMetadata(3, ITEM_TYPE_IN_GROUP, false, 2);
assertPositionMetadata(4, ITEM_TYPE_STANDALONE, false, 3);
assertPositionMetadata(5, ITEM_TYPE_GROUP_HEADER, false, 4);
assertPositionMetadata(6, ITEM_TYPE_GROUP_HEADER, true, 6);
assertPositionMetadata(7, ITEM_TYPE_IN_GROUP, false, 6);
assertPositionMetadata(8, ITEM_TYPE_IN_GROUP, false, 7);
assertPositionMetadata(9, ITEM_TYPE_STANDALONE, false, 8);
| public void | testGroupingWithoutGroups()
buildCursor("1", "2", "3");
mAdapter.changeCursor(mCursor);
assertEquals(3, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_STANDALONE, false, 1);
assertPositionMetadata(2, ITEM_TYPE_STANDALONE, false, 2);
| public void | testPositionCache()
buildCursor("1", "2", "2", "3", "4", "4", "5", "5", "6");
mAdapter.changeCursor(mCursor);
// First pass - building up cache
assertEquals(6, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, false, 1);
assertPositionMetadata(2, ITEM_TYPE_STANDALONE, false, 3);
assertPositionMetadata(3, ITEM_TYPE_GROUP_HEADER, false, 4);
assertPositionMetadata(4, ITEM_TYPE_GROUP_HEADER, false, 6);
assertPositionMetadata(5, ITEM_TYPE_STANDALONE, false, 8);
// Second pass - using cache
assertEquals(6, mAdapter.getCount());
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, false, 1);
assertPositionMetadata(2, ITEM_TYPE_STANDALONE, false, 3);
assertPositionMetadata(3, ITEM_TYPE_GROUP_HEADER, false, 4);
assertPositionMetadata(4, ITEM_TYPE_GROUP_HEADER, false, 6);
assertPositionMetadata(5, ITEM_TYPE_STANDALONE, false, 8);
// Invalidate cache by expanding a group
mAdapter.toggleGroup(1);
// First pass - building up cache
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, true, 1);
assertPositionMetadata(2, ITEM_TYPE_IN_GROUP, false, 1);
assertPositionMetadata(3, ITEM_TYPE_IN_GROUP, false, 2);
assertPositionMetadata(4, ITEM_TYPE_STANDALONE, false, 3);
assertPositionMetadata(5, ITEM_TYPE_GROUP_HEADER, false, 4);
assertPositionMetadata(6, ITEM_TYPE_GROUP_HEADER, false, 6);
assertPositionMetadata(7, ITEM_TYPE_STANDALONE, false, 8);
// Second pass - using cache
assertPositionMetadata(0, ITEM_TYPE_STANDALONE, false, 0);
assertPositionMetadata(1, ITEM_TYPE_GROUP_HEADER, true, 1);
assertPositionMetadata(2, ITEM_TYPE_IN_GROUP, false, 1);
assertPositionMetadata(3, ITEM_TYPE_IN_GROUP, false, 2);
assertPositionMetadata(4, ITEM_TYPE_STANDALONE, false, 3);
assertPositionMetadata(5, ITEM_TYPE_GROUP_HEADER, false, 4);
assertPositionMetadata(6, ITEM_TYPE_GROUP_HEADER, false, 6);
assertPositionMetadata(7, ITEM_TYPE_STANDALONE, false, 8);
|
|