Search in sources :

Example 1 with CursorIndexOutOfBoundsException

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();
}
Also used : CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException) SQLiteCursor(android.database.sqlite.SQLiteCursor) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 2 with CursorIndexOutOfBoundsException

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();
}
Also used : CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException) SQLiteCursor(android.database.sqlite.SQLiteCursor) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 3 with CursorIndexOutOfBoundsException

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();
}
Also used : CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException) SQLiteCursor(android.database.sqlite.SQLiteCursor) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 4 with CursorIndexOutOfBoundsException

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();
}
Also used : CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException) SQLiteCursor(android.database.sqlite.SQLiteCursor) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 5 with CursorIndexOutOfBoundsException

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();
}
Also used : CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException) SQLiteCursor(android.database.sqlite.SQLiteCursor) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

CursorIndexOutOfBoundsException (android.database.CursorIndexOutOfBoundsException)17 Cursor (android.database.Cursor)14 SQLiteCursor (android.database.sqlite.SQLiteCursor)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Entry (com.newsrob.Entry)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 Timing (com.newsrob.util.Timing)1 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1