SQLite Android Bindings
Check-in [251698dcb8]
Not logged in

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

Overview
Comment:Add tests for new extension loading code to android app
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | api-level-9
Files: files | file ages | folders
SHA1: 251698dcb8b5161358d47d6de27eebea6a6a5872
User & Date: pjw 2017-05-02 15:20:55
Context
2017-05-02
15:20
Add tests for new extension loading code to android app Leaf check-in: 251698dcb8 user: pjw tags: api-level-9
14:39
Throw SQLiteMisuseException if built with SQLITE_OMIT_LOAD_EXTENSION and client attempts to enable extension load check-in: 566a4f756b user: pjw tags: api-level-9
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java.

   433    433               csr_test_2();
   434    434               thread_test_1();
   435    435               thread_test_2();
   436    436               see_test_1();
   437    437               see_test_2();
   438    438               stmt_jrnl_test_1();
   439    439               json_test_1();
          440  +            load_extension_test_1();
   440    441   
   441    442               myTV.append("\n" + myNErr + " errors from " + myNTest + " tests\n");
   442    443           } catch(Exception e) {
   443    444               myTV.append("Exception: " + e.toString() + "\n");
   444    445               myTV.append(android.util.Log.getStackTraceString(e) + "\n");
   445    446           }
   446    447       }
................................................................................
   491    492           s = db.compileStatement("Select x from t1 where json_extract(x, '$.Foo') > 1 order by json_extract(x, '$.Foo') limit 1");
   492    493           res = s.simpleQueryForString();
   493    494           db.setTransactionSuccessful();
   494    495           db.endTransaction();
   495    496           test_result("json_test_1.3", res, r2, t2);
   496    497   
   497    498           s.close();
          499  +
          500  +        db.close();
          501  +    }
          502  +
          503  +    public void load_extension_test_1() throws Exception {
          504  +        long t0 = System.nanoTime();
          505  +        SQLiteDatabase.deleteDatabase(DB_PATH);
          506  +        SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH.getAbsolutePath(), null, SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.ENABLE_LOAD_EXTENSION);
          507  +
          508  +        Cursor c = null;
          509  +        try {
          510  +            c = db.rawQuery("select load_extension('foo')", new String[] {});
          511  +            c.moveToFirst();
          512  +            c.close();
          513  +            c = null;
          514  +        } catch (Exception e) {
          515  +            String exp = "dlopen failed";
          516  +            test_result("load_extension_1.1", e.getMessage().substring(0,exp.length()), exp, t0);
          517  +        } finally {
          518  +            if (c != null) {
          519  +                c.close();
          520  +                c = null;
          521  +            }
          522  +        }
          523  +        t0 = System.nanoTime();
          524  +
          525  +        db.disableLoadExtension();
          526  +        try {
          527  +            c = db.rawQuery("select load_extension('foo')", new String[] {});
          528  +            c.moveToFirst();
          529  +            c.close();
          530  +            c = null;
          531  +        } catch (Exception e) {
          532  +            String exp = "not authorized";
          533  +            test_result("load_extension_1.2", e.getMessage().substring(0,exp.length()), exp, t0);
          534  +        } finally {
          535  +            if (c != null) {
          536  +                c.close();
          537  +                c = null;
          538  +            }
          539  +        }
          540  +        t0 = System.nanoTime();
          541  +
          542  +        db.enableLoadExtension();
          543  +        try {
          544  +            c = db.rawQuery("select load_extension('foo')", new String[] {});
          545  +            c.moveToFirst();
          546  +            c.close();
          547  +            c = null;
          548  +        } catch (Exception e) {
          549  +            String exp = "dlopen failed";
          550  +            test_result("load_extension_1.3", e.getMessage().substring(0,exp.length()), exp, t0);
          551  +        } finally {
          552  +            if (c != null) {
          553  +                c.close();
          554  +                c = null;
          555  +            }
          556  +        }
          557  +        t0 = System.nanoTime();
          558  +
          559  +        db.close();
          560  +
          561  +        db = SQLiteDatabase.openDatabase(DB_PATH.getAbsolutePath(), null, SQLiteDatabase.CREATE_IF_NECESSARY);
          562  +        db.disableLoadExtension();
          563  +        try {
          564  +            c = db.rawQuery("select load_extension('foo')", new String[] {});
          565  +            c.moveToFirst();
          566  +            c.close();
          567  +            c = null;
          568  +        } catch (Exception e) {
          569  +            String exp = "not authorized";
          570  +            test_result("load_extension_1.4", e.getMessage().substring(0,exp.length()), exp, t0);
          571  +        } finally {
          572  +            if (c != null) {
          573  +                c.close();
          574  +                c = null;
          575  +            }
          576  +        }
          577  +        t0 = System.nanoTime();
          578  +
          579  +        db.enableLoadExtension();
          580  +        try {
          581  +            c = db.rawQuery("select load_extension('foo')", new String[] {});
          582  +            c.moveToFirst();
          583  +            c.close();
          584  +            c = null;
          585  +        } catch (Exception e) {
          586  +            String exp = "dlopen failed";
          587  +            test_result("load_extension_1.5", e.getMessage().substring(0,exp.length()), exp, t0);
          588  +        } finally {
          589  +            if (c != null) {
          590  +                c.close();
          591  +                c = null;
          592  +            }
          593  +        }
   498    594   
   499    595           db.close();
   500    596       }
   501    597   }