diff --git a/app/src/main/java/net/zetetic/tests/SQLCompileStatementFinalizeTest.java b/app/src/main/java/net/zetetic/tests/SQLCompileStatementFinalizeTest.java new file mode 100644 index 0000000..23cc063 --- /dev/null +++ b/app/src/main/java/net/zetetic/tests/SQLCompileStatementFinalizeTest.java @@ -0,0 +1,96 @@ +package net.zetetic.tests; + +import android.util.Log; + +import androidx.annotation.NonNull; + +import net.sqlcipher.database.SQLiteDatabase; +import net.sqlcipher.database.SQLiteStatement; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class SQLCompileStatementFinalizeTest extends SQLCipherTest { + + private final int count = 2; + private final boolean isLocking; + + public SQLCompileStatementFinalizeTest(Boolean useLocking) { + isLocking = useLocking; + } + + @Override + public boolean execute(final SQLiteDatabase database) { + database.setLockingEnabled(isLocking); + final CountDownLatch latchMain = new CountDownLatch(1); + final CountDownLatch latchTransaction = new CountDownLatch(1); + final CountDownLatch latchSQLRelease = new CountDownLatch(1); + + database.execSQL("CREATE TABLE TestTable(text_value TEXT);"); + + Thread thread1 = new Thread(new Runnable() { + @Override + public void run() { + + for (int i = 0; i < count; i++) { + SQLiteStatement statement = database.compileStatement("DELETE FROM TestTable"); + statement.executeUpdateDelete(); + } + + latchSQLRelease.countDown(); + + try { + latchTransaction.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + + Thread thread2 = new Thread(new Runnable() { + @Override + public void run() { + try { + latchSQLRelease.await(); + + database.beginTransaction(); + + latchTransaction.countDown(); + + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() < start + TimeUnit.SECONDS.toMillis(40)) { + new Object(); + System.gc(); + } + database.setTransactionSuccessful(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + database.endTransaction(); + } + + latchMain.countDown(); + } + }); + + thread1.start(); + thread2.start(); + + try { + latchMain.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + @Override + public String getName() { + return "SQLCompileStatement crash, locking=" + isLocking; + } + +} diff --git a/app/src/main/java/net/zetetic/tests/TestSuiteRunner.java b/app/src/main/java/net/zetetic/tests/TestSuiteRunner.java index 7d869cc..bfff213 100644 --- a/app/src/main/java/net/zetetic/tests/TestSuiteRunner.java +++ b/app/src/main/java/net/zetetic/tests/TestSuiteRunner.java @@ -8,7 +8,6 @@ import net.sqlcipher.CursorWindow; import net.sqlcipher.CursorWindowAllocation; -import net.sqlcipher.database.SQLiteDatabase; import net.zetetic.ZeteticApplication; import java.util.ArrayList; @@ -70,6 +69,8 @@ private void runSuite() { private List getTestsToRun() { List tests = new ArrayList<>(); + tests.add(new SQLCompileStatementFinalizeTest(false)); + tests.add(new SQLCompileStatementFinalizeTest(true)); tests.add(new SummingStepTest()); tests.add(new JsonCastTest());