use of android.database.CursorIndexOutOfBoundsException in project platform_frameworks_base by android.
the class DatabaseCursorTest method testCursor1.
@MediumTest
public void testCursor1() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int dataColumn = c.getColumnIndexOrThrow("data");
// The cursor should ignore text before the last period when looking for a column. (This
// is a temporary hack in all implementations of getColumnIndex.)
int dataColumn2 = c.getColumnIndexOrThrow("junk.data");
assertEquals(dataColumn, dataColumn2);
assertSame(3, c.getCount());
assertTrue(c.isBeforeFirst());
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.moveToNext();
assertEquals(1, c.getInt(0));
String s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString2, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString3, s);
c.moveToPosition(-1);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToPosition(2);
s = c.getString(dataColumn);
assertEquals(sString3, s);
int i;
for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
c.getInt(0);
}
assertEquals(3, i);
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.close();
}
use of android.database.CursorIndexOutOfBoundsException 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.CursorIndexOutOfBoundsException in project android_frameworks_base by ParanoidAndroid.
the class DatabaseCursorTest method testCursor1.
@MediumTest
public void testCursor1() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int dataColumn = c.getColumnIndexOrThrow("data");
// The cursor should ignore text before the last period when looking for a column. (This
// is a temporary hack in all implementations of getColumnIndex.)
int dataColumn2 = c.getColumnIndexOrThrow("junk.data");
assertEquals(dataColumn, dataColumn2);
assertSame(3, c.getCount());
assertTrue(c.isBeforeFirst());
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.moveToNext();
assertEquals(1, c.getInt(0));
String s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString2, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString3, s);
c.moveToPosition(-1);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToPosition(2);
s = c.getString(dataColumn);
assertEquals(sString3, s);
int i;
for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
c.getInt(0);
}
assertEquals(3, i);
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.close();
}
use of android.database.CursorIndexOutOfBoundsException in project android_frameworks_base by ResurrectionRemix.
the class DatabaseCursorTest method testCursor1.
@MediumTest
public void testCursor1() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int dataColumn = c.getColumnIndexOrThrow("data");
// The cursor should ignore text before the last period when looking for a column. (This
// is a temporary hack in all implementations of getColumnIndex.)
int dataColumn2 = c.getColumnIndexOrThrow("junk.data");
assertEquals(dataColumn, dataColumn2);
assertSame(3, c.getCount());
assertTrue(c.isBeforeFirst());
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.moveToNext();
assertEquals(1, c.getInt(0));
String s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString2, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString3, s);
c.moveToPosition(-1);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToPosition(2);
s = c.getString(dataColumn);
assertEquals(sString3, s);
int i;
for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
c.getInt(0);
}
assertEquals(3, i);
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.close();
}
use of android.database.CursorIndexOutOfBoundsException in project android_frameworks_base by ResurrectionRemix.
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();
}
Aggregations