11package net .zetetic .tests ;
22
33import android .database .Cursor ;
4+
45import net .sqlcipher .database .SQLiteDatabase ;
56import net .zetetic .ZeteticApplication ;
67
8+ import android .util .Log ;
9+
710import java .io .File ;
811import java .io .IOException ;
912
@@ -12,21 +15,43 @@ public class QueryNonEncryptedDatabaseTest extends SQLCipherTest {
1215 @ Override
1316 public boolean execute (SQLiteDatabase database ) {
1417
15- boolean success = false ;
18+ database .close ();
19+ File unencryptedDatabase = ZeteticApplication .getInstance ().getDatabasePath ("unencrypted.db" );
20+
1621 try {
17- File unencryptedDatabase = ZeteticApplication .getInstance ().getDatabasePath ("unencrypted.db" );
1822 ZeteticApplication .getInstance ().extractAssetToDatabaseDirectory ("unencrypted.db" );
19- database .close ();
23+ } catch (IOException e ) {
24+ Log .e (ZeteticApplication .TAG , "NOT EXPECTED: caught IOException" , e );
25+ return false ;
26+ }
27+
28+ boolean success = false ;
29+
30+ // XXX CRASHING:
31+ try {
32+ char [] nullPassword = null ;
33+ database = SQLiteDatabase .openOrCreateDatabase (unencryptedDatabase .getPath (), nullPassword , null , null );
34+ } catch (Exception e ) {
35+ Log .e (ZeteticApplication .TAG , "NOT EXPECTED: exception" , e );
36+ return false ;
37+ }
38+
39+ try {
2040 database = SQLiteDatabase .openOrCreateDatabase (unencryptedDatabase , "" , null );
2141 Cursor cursor = database .rawQuery ("select * from t1" , new String []{});
2242 cursor .moveToFirst ();
2343 String a = cursor .getString (0 );
2444 String b = cursor .getString (1 );
2545 cursor .close ();
2646 database .close ();
47+
2748 success = a .equals ("one for the money" ) &&
2849 b .equals ("two for the show" );
29- } catch (IOException e ) {}
50+ } catch (Exception e ) {
51+ Log .e (ZeteticApplication .TAG , "NOT EXPECTED: exception when reading database with blank password" , e );
52+ return false ;
53+ }
54+
3055 return success ;
3156 }
3257
0 commit comments