Index: sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java ================================================================== --- sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java +++ sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java @@ -435,10 +435,11 @@ thread_test_2(); see_test_1(); see_test_2(); stmt_jrnl_test_1(); json_test_1(); + load_extension_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"); @@ -493,9 +494,104 @@ db.setTransactionSuccessful(); db.endTransaction(); test_result("json_test_1.3", res, r2, t2); s.close(); + + db.close(); + } + + public void load_extension_test_1() throws Exception { + long t0 = System.nanoTime(); + SQLiteDatabase.deleteDatabase(DB_PATH); + SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH.getAbsolutePath(), null, SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.ENABLE_LOAD_EXTENSION); + + Cursor c = null; + try { + c = db.rawQuery("select load_extension('foo')", new String[] {}); + c.moveToFirst(); + c.close(); + c = null; + } catch (Exception e) { + String exp = "dlopen failed"; + test_result("load_extension_1.1", e.getMessage().substring(0,exp.length()), exp, t0); + } finally { + if (c != null) { + c.close(); + c = null; + } + } + t0 = System.nanoTime(); + + db.disableLoadExtension(); + try { + c = db.rawQuery("select load_extension('foo')", new String[] {}); + c.moveToFirst(); + c.close(); + c = null; + } catch (Exception e) { + String exp = "not authorized"; + test_result("load_extension_1.2", e.getMessage().substring(0,exp.length()), exp, t0); + } finally { + if (c != null) { + c.close(); + c = null; + } + } + t0 = System.nanoTime(); + + db.enableLoadExtension(); + try { + c = db.rawQuery("select load_extension('foo')", new String[] {}); + c.moveToFirst(); + c.close(); + c = null; + } catch (Exception e) { + String exp = "dlopen failed"; + test_result("load_extension_1.3", e.getMessage().substring(0,exp.length()), exp, t0); + } finally { + if (c != null) { + c.close(); + c = null; + } + } + t0 = System.nanoTime(); + + db.close(); + + db = SQLiteDatabase.openDatabase(DB_PATH.getAbsolutePath(), null, SQLiteDatabase.CREATE_IF_NECESSARY); + db.disableLoadExtension(); + try { + c = db.rawQuery("select load_extension('foo')", new String[] {}); + c.moveToFirst(); + c.close(); + c = null; + } catch (Exception e) { + String exp = "not authorized"; + test_result("load_extension_1.4", e.getMessage().substring(0,exp.length()), exp, t0); + } finally { + if (c != null) { + c.close(); + c = null; + } + } + t0 = System.nanoTime(); + + db.enableLoadExtension(); + try { + c = db.rawQuery("select load_extension('foo')", new String[] {}); + c.moveToFirst(); + c.close(); + c = null; + } catch (Exception e) { + String exp = "dlopen failed"; + test_result("load_extension_1.5", e.getMessage().substring(0,exp.length()), exp, t0); + } finally { + if (c != null) { + c.close(); + c = null; + } + } db.close(); } }