Skip to content

Commit b7e326a

Browse files
Small test case to check cipher_version
1 parent 52399fa commit b7e326a

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package net.zetetic.database.sqlcipher_cts;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
6+
import androidx.test.platform.app.InstrumentationRegistry;
7+
import androidx.test.ext.junit.runners.AndroidJUnit4;
8+
9+
import net.zetetic.database.sqlcipher.SQLiteDatabase;
10+
11+
import org.junit.After;
12+
import org.junit.Before;
13+
import org.junit.runner.RunWith;
14+
15+
import java.io.File;
16+
import java.util.Locale;
17+
18+
import static org.junit.Assert.assertNotNull;
19+
20+
@RunWith(AndroidJUnit4.class)
21+
public abstract class AndroidSQLCipherTestCase {
22+
23+
protected SQLiteDatabase database;
24+
protected String DATABASE_NAME = "database_test.db";
25+
protected String TAG = getClass().getSimpleName();
26+
protected Context context = null;
27+
28+
@Before
29+
public void setUp() throws Exception {
30+
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
31+
System.loadLibrary("sqliteX");
32+
File databasePath = context.getDatabasePath(DATABASE_NAME);
33+
databasePath.mkdirs();
34+
if (databasePath.exists()) { databasePath.delete(); }
35+
database = SQLiteDatabase.openOrCreateDatabase(databasePath,null);
36+
assertNotNull(database);
37+
}
38+
39+
@After
40+
public void tearDown() {
41+
if(database != null){
42+
database.close();
43+
}
44+
if(context != null){
45+
context.deleteDatabase(DATABASE_NAME);
46+
}
47+
}
48+
49+
protected void log(String message, Object...args){
50+
Log.i(TAG, String.format(Locale.getDefault(), message, args));
51+
}
52+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package net.zetetic.database.sqlcipher_cts;
2+
3+
import android.database.Cursor;
4+
5+
import org.junit.Test;
6+
7+
import static org.hamcrest.MatcherAssert.assertThat;
8+
import static org.hamcrest.core.IsEqual.equalTo;
9+
10+
public class SQLCipherVersionTest extends AndroidSQLCipherTestCase {
11+
12+
@Test
13+
public void testCipherVersionReported(){
14+
String cipherVersion = "";
15+
Cursor cursor = database.rawQuery("PRAGMA cipher_version;", new String[]{});
16+
if(cursor != null && cursor.moveToFirst()){
17+
cipherVersion = cursor.getString(0);
18+
cursor.close();
19+
}
20+
assertThat(cipherVersion, equalTo("4.4.3 zetetic"));
21+
}
22+
}

0 commit comments

Comments
 (0)