SQLite Android Bindings
Check-in [60c548bff9]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a test to check that SQLiteOpenHelper works with SEE.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 60c548bff9d6c50b14975c02a612fbf6343a22e5
User & Date: dan 2013-12-24 19:16:52
Context
2013-12-25
17:50
Add some documentation files. check-in: 67c837ca6c user: dan tags: trunk
2013-12-24
19:16
Add a test to check that SQLiteOpenHelper works with SEE. check-in: 60c548bff9 user: dan tags: trunk
18:51
Add extra SEE tests. And fix problems revealed by the same. check-in: 0b5fd0b0d3 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/org/sqlite/app/customsqlite/CustomSqlite.java.

12
13
14
15
16
17
18

19
20

21
22
23
24
25
26
27
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
...
216
217
218
219
220
221
222









































223
224
225
226
227
228
229
...
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247
import java.util.Arrays;

import java.lang.InterruptedException;

import org.sqlite.database.sqlite.SQLiteDatabase;
import org.sqlite.database.sqlite.SQLiteStatement;
import org.sqlite.database.sqlite.SQLiteDatabaseCorruptException;


import android.database.Cursor;


/*
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
*/

import org.sqlite.database.DatabaseErrorHandler;
................................................................................
      res = res + "." + x;
    }

    return res;
  }

  /*
  ** Check that using openSeeDatabase() creates encrypted databases. 
  */
  public void see_test_1() throws Exception {
    if( !SQLiteDatabase.hasCodec() ) return;

    SQLiteDatabase.deleteDatabase(DB_PATH);
    String res = "";
    
................................................................................
    
    res = string_from_t1_x(db);
    test_result("see_test_1.1", res, ".one.two.three");
    db.close();

    test_result("see_test_1.2", db_is_encrypted(), "encrypted");

    db = SQLiteDatabase.openOrCreateDatabase(DB_PATH.getPath(), null, new DoNotDeleteErrorHandler());
    db.execSQL("PRAGMA key = 'secretkey'");
    res = string_from_t1_x(db);
    test_result("see_test_1.3", res, ".one.two.three");
    db.close();

    res = "unencrypted";
    try {
................................................................................
    } catch ( SQLiteDatabaseCorruptException e ){
      res = "encrypted";
    } finally {
      db.close();
    }
    test_result("see_test_1.5", res, "encrypted");
  }










































  public void run_the_tests(View view){
    System.loadLibrary("sqliteX");
    DB_PATH = getApplicationContext().getDatabasePath("test.db");
    DB_PATH.mkdirs();

    myTV.setText("");
................................................................................
    myNTest = 0;

    try {
      report_version();
      csr_test_1();
      thread_test_1();
      see_test_1();


      myTV.append("\n" + myNErr + " errors from " + myNTest + " tests\n");
    } catch(Exception e) {
      myTV.append("Exception: " + e.toString() + "\n");
      myTV.append(android.util.Log.getStackTraceString(e) + "\n");
    }
  }
}









>


>







 







|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>










12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import java.util.Arrays;

import java.lang.InterruptedException;

import org.sqlite.database.sqlite.SQLiteDatabase;
import org.sqlite.database.sqlite.SQLiteStatement;
import org.sqlite.database.sqlite.SQLiteDatabaseCorruptException;
import org.sqlite.database.sqlite.SQLiteOpenHelper;

import android.database.Cursor;
import android.content.Context;

/*
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
*/

import org.sqlite.database.DatabaseErrorHandler;
................................................................................
      res = res + "." + x;
    }

    return res;
  }

  /*
  ** If this is a SEE build, check that encrypted databases work.
  */
  public void see_test_1() throws Exception {
    if( !SQLiteDatabase.hasCodec() ) return;

    SQLiteDatabase.deleteDatabase(DB_PATH);
    String res = "";
    
................................................................................
    
    res = string_from_t1_x(db);
    test_result("see_test_1.1", res, ".one.two.three");
    db.close();

    test_result("see_test_1.2", db_is_encrypted(), "encrypted");

    db = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null);
    db.execSQL("PRAGMA key = 'secretkey'");
    res = string_from_t1_x(db);
    test_result("see_test_1.3", res, ".one.two.three");
    db.close();

    res = "unencrypted";
    try {
................................................................................
    } catch ( SQLiteDatabaseCorruptException e ){
      res = "encrypted";
    } finally {
      db.close();
    }
    test_result("see_test_1.5", res, "encrypted");
  }

  class MyHelper extends SQLiteOpenHelper {
    public MyHelper(Context ctx){
      super(ctx, DB_PATH.getPath(), null, 1);
    }
    public void onConfigure(SQLiteDatabase db){
      db.execSQL("PRAGMA key = 'secret'");
    }
    public void onCreate(SQLiteDatabase db){
      db.execSQL("CREATE TABLE t1(x)");
    }
    public void onUpgrade(SQLiteDatabase db, int iOld, int iNew){
    }
  } 

  /*
  ** If this is a SEE build, check that SQLiteOpenHelper still works.
  */
  public void see_test_2() throws Exception {
    if( !SQLiteDatabase.hasCodec() ) return;
    SQLiteDatabase.deleteDatabase(DB_PATH);

    MyHelper helper = new MyHelper(this);
    SQLiteDatabase db = helper.getWritableDatabase();
    db.execSQL("INSERT INTO t1 VALUES ('x'), ('y'), ('z')");

    String res = string_from_t1_x(db);
    test_result("see_test_2.1", res, ".x.y.z");
    test_result("see_test_2.2", db_is_encrypted(), "encrypted");

    helper.close();
    helper = new MyHelper(this);
    db = helper.getReadableDatabase();
    test_result("see_test_2.3", res, ".x.y.z");

    db = helper.getWritableDatabase();
    test_result("see_test_2.4", res, ".x.y.z");

    test_result("see_test_2.5", db_is_encrypted(), "encrypted");
  }


  public void run_the_tests(View view){
    System.loadLibrary("sqliteX");
    DB_PATH = getApplicationContext().getDatabasePath("test.db");
    DB_PATH.mkdirs();

    myTV.setText("");
................................................................................
    myNTest = 0;

    try {
      report_version();
      csr_test_1();
      thread_test_1();
      see_test_1();
      see_test_2();

      myTV.append("\n" + myNErr + " errors from " + myNTest + " tests\n");
    } catch(Exception e) {
      myTV.append("Exception: " + e.toString() + "\n");
      myTV.append(android.util.Log.getStackTraceString(e) + "\n");
    }
  }
}