use of android.database.Cursor in project platform_frameworks_base by android.
the class DatabaseCursorTest method testCursorWindowFailureWhenTooManyCursorWindowsLeftOpen.
/**
* sometimes CursorWindow creation fails due to non-availability of memory create
* another CursorWindow object. One of the scenarios of its occurrence is when
* there are too many CursorWindow objects already opened by the process.
* This test is for that scenario.
*/
@LargeTest
// Failing.
@Suppress
public void testCursorWindowFailureWhenTooManyCursorWindowsLeftOpen() {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");
mDatabase.execSQL("INSERT INTO test values(1, 'test');");
int N = 1024;
ArrayList<Cursor> cursorList = new ArrayList<Cursor>();
// open many cursors until a failure occurs
for (int i = 0; i < N; i++) {
try {
Cursor cursor = mDatabase.rawQuery("select * from test", null);
cursor.getCount();
cursorList.add(cursor);
} catch (CursorWindowAllocationException e) {
// got the exception we wanted
break;
} catch (Exception e) {
fail("unexpected exception: " + e.getMessage());
e.printStackTrace();
break;
}
}
for (Cursor c : cursorList) {
c.close();
}
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class DatabaseCursorTest method testRealColumns.
@MediumTest
public void testRealColumns() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data REAL);");
ContentValues values = new ContentValues();
values.put("data", 42.11);
long id = mDatabase.insert("test", "data", values);
assertTrue(id > 0);
Cursor c = mDatabase.rawQuery("SELECT data FROM test", null);
assertNotNull(c);
assertTrue(c.moveToFirst());
assertEquals(42.11, c.getDouble(0));
c.close();
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class DatabaseCursorTest method testManyRowsTxtLong.
@LargeTest
public void testManyRowsTxtLong() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, txt TEXT, data INT);");
Random random = new Random(System.currentTimeMillis());
StringBuilder randomString = new StringBuilder(1979);
for (int i = 0; i < 1979; i++) {
randomString.append((random.nextInt() & 0xf) % 10);
}
// if cursor window size changed, adjust this value too
final int count = 600;
mDatabase.execSQL("BEGIN Transaction;");
for (int i = 0; i < count; i++) {
StringBuilder sql = new StringBuilder(2100);
sql.append("INSERT INTO test (txt, data) VALUES ('");
sql.append(randomString);
sql.append("','");
sql.append(i);
sql.append("');");
mDatabase.execSQL(sql.toString());
}
mDatabase.execSQL("COMMIT;");
Cursor c = mDatabase.query("test", new String[] { "txt", "data" }, null, null, null, null, null);
assertNotNull(c);
int i = 0;
while (c.moveToNext()) {
assertEquals(randomString.toString(), c.getString(0));
assertEquals(i, c.getInt(1));
i++;
}
assertEquals(count, i);
assertEquals(count, c.getCount());
c.close();
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class DatabaseCursorTest method testCursor2.
@MediumTest
public void testCursor2() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.query("test", null, "_id > 1000", null, null, null, null);
assertEquals(0, c.getCount());
assertTrue(c.isBeforeFirst());
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
int i;
for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
c.getInt(0);
}
assertEquals(0, i);
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.close();
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class DatabaseLocaleTest method testHoge.
@SmallTest
public void testHoge() throws Exception {
Cursor cursor = null;
try {
String expectedString = new String(new int[] { 0xFE000 }, 0, 1);
mDatabase.execSQL("INSERT INTO test(id, data) VALUES(1, '" + expectedString + "')");
cursor = mDatabase.rawQuery("SELECT data FROM test WHERE id = 1", null);
assertNotNull(cursor);
assertTrue(cursor.moveToFirst());
String actualString = cursor.getString(0);
assertEquals(expectedString.length(), actualString.length());
for (int i = 0; i < expectedString.length(); i++) {
assertEquals((int) expectedString.charAt(i), (int) actualString.charAt(i));
}
assertEquals(expectedString, actualString);
} finally {
if (cursor != null)
cursor.close();
}
}
Aggregations