Skip to content

Commit 748e37e

Browse files
Add instrumentation tests for SQLCipherDriver for Room3
- Verify Room 3 integration with SQLCipherDriver, including entity insert and query round-trip. - Additional testing with both insertOrReplace and Upset behavior. - Verify PRAGMA cipher_version reports expected SQLCipher version. - Cover statementPrefix() extraction: plain statements, leading whitespace, line/block comments, comment-only and empty input. - Cover isJournalModeSet() dispatch: intercepts journal_mode assignments (case-insensitive, schema-qualified), ignores journal_mode queries to handle connection pool reconfiguration.
1 parent 078a05b commit 748e37e

8 files changed

Lines changed: 615 additions & 108 deletions

File tree

‎sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher/driver/Room3SQLCipherDriverTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import androidx.test.core.app.ApplicationProvider;
1414
import androidx.test.ext.junit.runners.AndroidJUnit4;
1515

16-
import net.zetetic.database.sqlcipher.driver.SQLCipherDriver;
17-
1816
import org.junit.Assert;
1917
import org.junit.Before;
2018
import org.junit.Test;

‎sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher/driver/RoomUpsertTest.java‎

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package net.zetetic.database.sqlcipher.driver
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import junit.framework.Assert.assertEquals
5+
import junit.framework.Assert.assertFalse
6+
import junit.framework.Assert.assertNull
7+
import junit.framework.Assert.assertTrue
8+
import org.junit.Test
9+
import org.junit.runner.RunWith
10+
11+
@RunWith(AndroidJUnit4::class)
12+
class SQLCipherConnectionStatementPrefixTests {
13+
14+
@Test
15+
fun shouldExtractPrefixFromPlainStatements() {
16+
assertEquals("SEL", SQLCipherConnection.statementPrefix("SELECT * FROM t"))
17+
assertEquals("BEG", SQLCipherConnection.statementPrefix("BEGIN"))
18+
assertEquals("PRA", SQLCipherConnection.statementPrefix("PRAGMA user_version"))
19+
}
20+
21+
@Test
22+
fun shouldSkipLeadingWhitespace() {
23+
assertEquals("BEG", SQLCipherConnection.statementPrefix(" \n\t BEGIN IMMEDIATE"))
24+
}
25+
26+
@Test
27+
fun shouldSkipLineComments() {
28+
assertEquals("BEG", SQLCipherConnection.statementPrefix("-- start txn\nBEGIN IMMEDIATE"))
29+
}
30+
31+
@Test
32+
fun shouldSkipBlockComments() {
33+
assertEquals("COM", SQLCipherConnection.statementPrefix("/* finish\n the txn */ COMMIT"))
34+
}
35+
36+
@Test
37+
fun shouldReturnNullForCommentOnlyInput() {
38+
assertNull(SQLCipherConnection.statementPrefix("-- nothing here"))
39+
assertNull(SQLCipherConnection.statementPrefix("/* nothing here */"))
40+
}
41+
42+
@Test
43+
fun shouldTolerateShortInput() {
44+
assertNull(SQLCipherConnection.statementPrefix(""))
45+
assertNull(SQLCipherConnection.statementPrefix(" "))
46+
}
47+
48+
@Test
49+
fun shouldInterceptJournalModeSets() {
50+
assertTrue(journalFor("PRAGMA journal_mode = WAL"))
51+
assertTrue(journalFor("pragma journal_mode=delete"))
52+
assertTrue(journalFor("PRAGMA main.journal_mode = TRUNCATE"))
53+
}
54+
55+
@Test
56+
fun shouldNotInterceptJournalModeQueries() {
57+
assertFalse(journalFor("PRAGMA journal_mode"))
58+
}
59+
60+
@Test
61+
fun shouldNotInterceptOtherPragmas() {
62+
assertFalse(journalFor("PRAGMA foreign_keys = ON"))
63+
assertFalse(journalFor("PRAGMA busy_timeout = 3000"))
64+
assertFalse(journalFor("PRAGMA synchronous = NORMAL"))
65+
}
66+
67+
private fun journalFor(sql: String): Boolean {
68+
val trimmed = sql.trim()
69+
return SQLCipherConnection.isJournalModeSet(
70+
SQLCipherConnection.statementPrefix(trimmed),
71+
trimmed)
72+
}
73+
}

0 commit comments

Comments
 (0)