File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
src/main/java/net/zetetic/tests Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 55import android .database .Cursor ;
66
77import net .sqlcipher .database .SQLiteDatabase ;
8+ import net .sqlcipher .database .SQLiteDatabaseCorruptException ;
89
910import net .zetetic .ZeteticApplication ;
1011
@@ -42,6 +43,27 @@ public boolean execute(SQLiteDatabase null_database_ignored) {
4243 return false ;
4344 }
4445
46+ Cursor cursor = database .rawQuery ("select * from sqlite_master;" , null );
47+
48+ if (cursor == null ) {
49+ Log .e (TAG , "NOT EXPECTED: database.rawQuery() returned null cursor" );
50+ return false ;
51+ }
52+
53+ // *Should* corrupt the database file that is already open:
54+ ZeteticApplication .getInstance ().extractAssetToDatabaseDirectory ("corrupt.db" );
55+
56+ try {
57+ // Attempt to write to corrupt database file *should* fail:
58+ database .execSQL ("CREATE TABLE t1(a,b);" );
59+
60+ // NOT EXPECTED to get here:
61+ Log .e (TAG , "NOT EXPECTED: CREATE TABLE succeeded " );
62+ return false ;
63+ } catch (SQLiteDatabaseCorruptException ex ) {
64+ Log .v (TAG , "Caught SQLiteDatabaseCorruptException as expected OK" );
65+ }
66+
4567 database .close ();
4668
4769 return true ;
You can’t perform that action at this time.
0 commit comments