Skip to content

Commit ec1173d

Browse files
Initial test with password provided as argument to open database
1 parent a267c4b commit ec1173d

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher_cts/AndroidSQLCipherTestCase.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ public abstract class AndroidSQLCipherTestCase {
2727

2828
@Before
2929
public void setUp() throws Exception {
30-
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
30+
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
3131
System.loadLibrary("sqliteX");
3232
File databasePath = context.getDatabasePath(DATABASE_NAME);
3333
databasePath.mkdirs();
34-
if (databasePath.exists()) { databasePath.delete(); }
35-
database = SQLiteDatabase.openOrCreateDatabase(databasePath,null);
34+
if (databasePath.exists()) {
35+
databasePath.delete();
36+
}
37+
database = SQLiteDatabase.openOrCreateDatabase(databasePath, null);
3638
assertNotNull(database);
3739
}
3840

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package net.zetetic.database.sqlcipher_cts;
2+
3+
import android.database.Cursor;
4+
5+
import net.zetetic.database.sqlcipher.SQLiteConnection;
6+
import net.zetetic.database.sqlcipher.SQLiteDatabase;
7+
import net.zetetic.database.sqlcipher.SQLiteDatabaseHook;
8+
9+
import org.junit.Test;
10+
11+
import java.io.File;
12+
13+
import static org.hamcrest.MatcherAssert.assertThat;
14+
import static org.hamcrest.core.Is.is;
15+
16+
public class SQLCipherDatabaseTest extends AndroidSQLCipherTestCase {
17+
18+
@Test
19+
public void testConnectionWithPassword(){
20+
int a = 0, b = 0;
21+
database.close();
22+
database = null;
23+
File databasePath = context.getDatabasePath("foo.db");
24+
if(databasePath.exists()){
25+
databasePath.delete();
26+
}
27+
database = SQLiteDatabase.openOrCreateDatabase(databasePath, "foo", null, null);
28+
database.execSQL("create table t1(a,b);");
29+
database.execSQL("insert into t1(a,b) values(?,?)", new Object[]{1, 2});
30+
Cursor cursor = database.rawQuery("select * from t1;", new String[]{});
31+
if(cursor != null && cursor.moveToFirst()){
32+
a = cursor.getInt(0);
33+
b = cursor.getInt(1);
34+
}
35+
assertThat(a, is(1));
36+
assertThat(b, is(2));
37+
}
38+
}

sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher_cts/SQLCipherVersionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import static org.hamcrest.MatcherAssert.assertThat;
88
import static org.hamcrest.core.IsEqual.equalTo;
9+
import static org.hamcrest.core.StringContains.containsString;
910

1011
public class SQLCipherVersionTest extends AndroidSQLCipherTestCase {
1112

@@ -17,6 +18,6 @@ public void testCipherVersionReported(){
1718
cipherVersion = cursor.getString(0);
1819
cursor.close();
1920
}
20-
assertThat(cipherVersion, equalTo("4.4.3 zetetic"));
21+
assertThat(cipherVersion, containsString("4.4.3"));
2122
}
2223
}

0 commit comments

Comments
 (0)