Skip to content

Commit 6aa1e80

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Use MatrixCursor instead of ArrayListCursor."
2 parents aac01f6 + c755ae3 commit 6aa1e80

File tree

3 files changed

+47
-324
lines changed

3 files changed

+47
-324
lines changed

core/tests/coretests/src/android/database/CursorWindowTest.java

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@
1616

1717
package android.database;
1818

19-
import android.database.AbstractCursor;
2019
import android.test.suitebuilder.annotation.SmallTest;
21-
import com.android.common.ArrayListCursor;
2220
import android.database.CursorWindow;
2321
import android.test.PerformanceTestCase;
2422

25-
import com.google.android.collect.Lists;
26-
27-
import java.util.ArrayList;
2823
import java.util.Arrays;
29-
import java.util.Random;
3024

3125
import junit.framework.TestCase;
3226

@@ -40,48 +34,6 @@ public int startPerformance(Intermediates intermediates) {
4034
return 1;
4135
}
4236

43-
@SmallTest
44-
public void testWriteCursorToWindow() throws Exception {
45-
// create cursor
46-
String[] colNames = new String[]{"name", "number", "profit"};
47-
int colsize = colNames.length;
48-
ArrayList<ArrayList> list = createTestList(10, colsize);
49-
AbstractCursor cursor = new ArrayListCursor(colNames, (ArrayList<ArrayList>) list);
50-
51-
// fill window
52-
CursorWindow window = new CursorWindow(false);
53-
cursor.fillWindow(0, window);
54-
55-
// read from cursor window
56-
for (int i = 0; i < list.size(); i++) {
57-
ArrayList<Integer> col = list.get(i);
58-
for (int j = 0; j < colsize; j++) {
59-
String s = window.getString(i, j);
60-
int r2 = col.get(j);
61-
int r1 = Integer.parseInt(s);
62-
assertEquals(r2, r1);
63-
}
64-
}
65-
66-
// test cursor window handle startpos != 0
67-
window.clear();
68-
cursor.fillWindow(1, window);
69-
// read from cursor from window
70-
for (int i = 1; i < list.size(); i++) {
71-
ArrayList<Integer> col = list.get(i);
72-
for (int j = 0; j < colsize; j++) {
73-
String s = window.getString(i, j);
74-
int r2 = col.get(j);
75-
int r1 = Integer.parseInt(s);
76-
assertEquals(r2, r1);
77-
}
78-
}
79-
80-
// Clear the window and make sure it's empty
81-
window.clear();
82-
assertEquals(0, window.getNumRows());
83-
}
84-
8537
@SmallTest
8638
public void testValuesLocalWindow() {
8739
doTestValues(new CursorWindow(true));
@@ -124,50 +76,4 @@ private void doTestValues(CursorWindow window) {
12476
assertTrue(window.putBlob(blob, 0, 6));
12577
assertTrue(Arrays.equals(blob, window.getBlob(0, 6)));
12678
}
127-
128-
@SmallTest
129-
public void testNull() {
130-
CursorWindow window = getOneByOneWindow();
131-
132-
// Put in a null value and read it back as various types
133-
assertTrue(window.putNull(0, 0));
134-
assertNull(window.getString(0, 0));
135-
assertEquals(0, window.getLong(0, 0));
136-
assertEquals(0.0, window.getDouble(0, 0));
137-
assertNull(window.getBlob(0, 0));
138-
}
139-
140-
@SmallTest
141-
public void testEmptyString() {
142-
CursorWindow window = getOneByOneWindow();
143-
144-
// put size 0 string and read it back as various types
145-
assertTrue(window.putString("", 0, 0));
146-
assertEquals("", window.getString(0, 0));
147-
assertEquals(0, window.getLong(0, 0));
148-
assertEquals(0.0, window.getDouble(0, 0));
149-
}
150-
151-
private CursorWindow getOneByOneWindow() {
152-
CursorWindow window = new CursorWindow(false);
153-
assertTrue(window.setNumColumns(1));
154-
assertTrue(window.allocRow());
155-
return window;
156-
}
157-
158-
private static ArrayList<ArrayList> createTestList(int rows, int cols) {
159-
ArrayList<ArrayList> list = Lists.newArrayList();
160-
Random generator = new Random();
161-
162-
for (int i = 0; i < rows; i++) {
163-
ArrayList<Integer> col = Lists.newArrayList();
164-
list.add(col);
165-
for (int j = 0; j < cols; j++) {
166-
// generate random number
167-
Integer r = generator.nextInt();
168-
col.add(r);
169-
}
170-
}
171-
return list;
172-
}
17379
}

core/tests/coretests/src/android/widget/SimpleCursorAdapterTest.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package android.widget;
1818

19-
import com.android.common.ArrayListCursor;
2019
import com.google.android.collect.Lists;
2120

2221
import android.content.Context;
2322
import android.database.Cursor;
23+
import android.database.MatrixCursor;
2424
import android.test.AndroidTestCase;
2525
import android.test.suitebuilder.annotation.SmallTest;
2626

@@ -52,14 +52,14 @@ public void setUp() throws Exception {
5252
super.setUp();
5353

5454
// all the pieces needed for the various tests
55-
mFrom = new String[]{"Column1", "Column2"};
55+
mFrom = new String[]{"Column1", "Column2", "_id"};
5656
mTo = new int[]{com.android.internal.R.id.text1, com.android.internal.R.id.text2};
5757
mLayout = com.android.internal.R.layout.simple_list_item_2;
5858
mContext = getContext();
5959

6060
// raw data for building a basic test cursor
6161
mData2x2 = createTestList(2, 2);
62-
mCursor2x2 = new ArrayListCursor(mFrom, mData2x2);
62+
mCursor2x2 = createCursor(mFrom, mData2x2);
6363
}
6464

6565
/**
@@ -77,6 +77,7 @@ private ArrayList<ArrayList> createTestList(int rows, int cols) {
7777
Integer r = generator.nextInt();
7878
col.add(r);
7979
}
80+
col.add(i);
8081
}
8182
return list;
8283
}
@@ -115,7 +116,7 @@ public void testChangeCursorLive() {
115116

116117
// now put in a different cursor (5 rows)
117118
ArrayList<ArrayList> data2 = createTestList(5, 2);
118-
Cursor c2 = new ArrayListCursor(mFrom, data2);
119+
Cursor c2 = createCursor(mFrom, data2);
119120
ca.changeCursor(c2);
120121

121122
// Now see if we can pull 5 rows from the adapter
@@ -155,8 +156,8 @@ public void testChangeCursorColumns() {
155156
assertEquals(columns[1], 1);
156157

157158
// Now make a new cursor with similar data but rearrange the columns
158-
String[] swappedFrom = new String[]{"Column2", "Column1"};
159-
Cursor c2 = new ArrayListCursor(swappedFrom, mData2x2);
159+
String[] swappedFrom = new String[]{"Column2", "Column1", "_id"};
160+
Cursor c2 = createCursor(swappedFrom, mData2x2);
160161
ca.changeCursor(c2);
161162
assertEquals(2, ca.getCount());
162163

@@ -235,7 +236,15 @@ public void testChangeMapping() {
235236
assertEquals(1, viewIds.length);
236237
assertEquals(com.android.internal.R.id.text2, viewIds[0]);
237238
}
238-
239+
240+
private static MatrixCursor createCursor(String[] columns, ArrayList<ArrayList> list) {
241+
MatrixCursor cursor = new MatrixCursor(columns, list.size());
242+
for (ArrayList row : list) {
243+
cursor.addRow(row);
244+
}
245+
return cursor;
246+
}
247+
239248
/**
240249
* This is simply a way to sneak a look at the protected mFrom() array. A more API-
241250
* friendly way to do this would be to mock out a View and a ViewBinder and exercise

0 commit comments

Comments
 (0)