Skip to content

Commit ff7b782

Browse files
Add cipher_compatibility test case
1 parent 821303c commit ff7b782

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package net.zetetic.database.sqlcipher_cts;
2+
3+
import static org.hamcrest.Matchers.greaterThan;
4+
import static org.junit.Assert.assertThat;
5+
6+
import android.database.Cursor;
7+
import android.util.Log;
8+
9+
import net.zetetic.database.sqlcipher.SQLiteConnection;
10+
import net.zetetic.database.sqlcipher.SQLiteDatabase;
11+
import net.zetetic.database.sqlcipher.SQLiteDatabaseHook;
12+
13+
import org.junit.Test;
14+
15+
import java.io.File;
16+
import java.io.IOException;
17+
18+
public class CipherCompatibilityTest extends AndroidSQLCipherTestCase {
19+
20+
@Test
21+
public void shouldOpenSQLCipher3Database() {
22+
int count = 0;
23+
database.close();
24+
File file = null;
25+
try {
26+
file = extractAssetToDatabaseDirectory("sqlcipher-3.0-testkey.db");
27+
database = SQLiteDatabase.openDatabase(file.getAbsolutePath(), "testkey", null, SQLiteDatabase.OPEN_READWRITE, hook);
28+
Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM sqlite_master;", null);
29+
if(cursor != null && cursor.moveToFirst()){
30+
count = cursor.getInt(0);
31+
cursor.close();
32+
}
33+
assertThat(count, greaterThan(0));
34+
} finally {
35+
delete(file);
36+
}
37+
}
38+
39+
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
40+
public void preKey(SQLiteConnection connection) {}
41+
public void postKey(SQLiteConnection connection) {
42+
connection.execute("PRAGMA cipher_compatibility = 3;", null, null);
43+
}
44+
};
45+
}

0 commit comments

Comments
 (0)