Skip to content

Commit 31437e1

Browse files
Add script to run test suite across all emulators
1 parent e3d1dd2 commit 31437e1

15 files changed

+542
-127
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.DS_Store
22
**/*.class
33
**/*.apk
4-
target
4+
target
5+
*.log
6+

.idea/compiler.xml

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 437 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="net.zetetic" android:versionCode="1" android:versionName="1.0-SNAPSHOT">
4-
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="21"/>
4+
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="23"/>
55
<uses-permission android:name="android.permission.INTERNET"/>
66
<application android:icon="@drawable/icon"
77
android:debuggable="true"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
To run, clone this repo and make sure you have the Android SDK installed.
2+
- Currently support Android OS 2.1 - 5.0.1, simply run on either an emulator or device.
3+
- More information can be found at [SQLCipher for Android](http://sqlcipher.net/sqlcipher-for-android/).
4+
- Run across all installed emulators via the [`run-testsuite.sh`](https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/run-testsuite.sh) script.
5+
![SQLCipher for Android test suite running](https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/test-suite-screenshot.png)
6+

README.org

Lines changed: 0 additions & 3 deletions
This file was deleted.

net.zetetic.sqlcipher.test.iml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
<root url="jar://$MODULE_DIR$/libs/sqlcipher.jar!/" />
4545
</CLASSES>
4646
<JAVADOC />
47-
<SOURCES>
48-
<root url="file://$MODULE_DIR$/../android-database-sqlcipher/src" />
49-
</SOURCES>
47+
<SOURCES />
5048
</library>
5149
</orderEntry>
5250
</component>

run-testsuite.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#! /usr/bin/env bash
2+
3+
UNLOCK_KEY=82
4+
BIN=target/net.zetetic.sqlcipher.test.apk
5+
INSTALL_ROOT=/data/data/net.zetetic
6+
EMULATOR_CHECK_STATUS="adb shell getprop init.svc.bootanim"
7+
EMULATOR_IS_BOOTED="stopped"
8+
emulators=`android list avd | awk '/Name:/{print $2}' | sort -u`
9+
for emulator in ${emulators}; do
10+
emulator @${emulator} -no-skin -no-audio &> /dev/null &
11+
OUT=$($EMULATOR_CHECK_STATUS 2> /dev/null)
12+
printf "Booting ${emulator}..."
13+
while [[ ${OUT:0:7} != $EMULATOR_IS_BOOTED ]]; do
14+
OUT=$($EMULATOR_CHECK_STATUS 2> /dev/null)
15+
printf "."
16+
sleep 5
17+
done
18+
printf "\n"
19+
20+
# unlock
21+
adb shell input keyevent ${UNLOCK_KEY}
22+
23+
# launch and run test suite
24+
printf "Installing test suite\n"
25+
adb install -r ${BIN} &> /dev/null
26+
27+
printf "Running test suite..."
28+
adb shell am start -n "net.zetetic/net.zetetic.TestSuiteActivity" \
29+
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER -e run 1 &> /dev/null
30+
31+
# remove previous test results
32+
adb shell rm ${INSTALL_ROOT}/files/test-results.log &> /dev/null
33+
34+
#poll for test results
35+
adb pull ${INSTALL_ROOT}/files/test-results.log test-results-$emulator.log &> /dev/null
36+
OUT=$?
37+
printf "."
38+
while [[ ${OUT} != 0 ]]; do
39+
sleep 5
40+
adb pull ${INSTALL_ROOT}/files/test-results.log test-results-$emulator.log &> /dev/null
41+
OUT=$?
42+
printf "."
43+
done
44+
printf "\nTest suite run complete for ${emulator}:\n"
45+
cat test-results-$emulator.log
46+
printf "\n"
47+
sleep 5
48+
49+
# stop emulator
50+
adb emu kill
51+
done

src/main/java/net/zetetic/TestSuiteActivity.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import net.zetetic.tests.TestResult;
1010
import net.zetetic.tests.TestSuiteRunner;
1111

12+
import java.io.File;
13+
import java.io.FileNotFoundException;
14+
import java.io.FileOutputStream;
1215
import java.util.ArrayList;
1316
import java.util.List;
1417

@@ -18,6 +21,7 @@ public class TestSuiteActivity extends Activity implements ResultNotifier {
1821
ListView resultsView;
1922
List<TestResult> results;
2023
View statsView;
24+
File testResults;
2125

2226
public TestSuiteActivity(){
2327
results = new ArrayList<TestResult>();
@@ -28,6 +32,8 @@ public void onCreate(Bundle savedInstanceState) {
2832
super.onCreate(savedInstanceState);
2933
Log.i(TAG, "onCreate");
3034
setContentView(R.layout.main);
35+
testResults = new File(getApplication().getFilesDir(), "test-results.log");
36+
deleteTestResultsLog();
3137
Bundle args = getIntent().getExtras();
3238
if(args != null){
3339
if(args.containsKey("run")){
@@ -38,6 +44,7 @@ public void onCreate(Bundle savedInstanceState) {
3844

3945
public void onButtonClick(View view) {
4046

47+
deleteTestResultsLog();
4148
results.clear();
4249
hideStats();
4350
findViewById(R.id.executeSuite).setEnabled(false);
@@ -68,18 +75,41 @@ public void complete() {
6875

6976
TextView stats = (TextView) statsView.findViewById(R.id.stats);
7077
int successCount = 0;
78+
List<String> failedTests = new ArrayList<String>();
7179
for(TestResult result : results){
7280
if(result.isSuccess()){
7381
successCount += 1;
82+
} else {
83+
failedTests.add(result.getName());
7484
}
7585
}
7686
String message = String.format("Passed: %d Failed: %d", successCount, results.size() - successCount);
87+
deleteTestResultsLog();
88+
try {
89+
FileOutputStream resultStream = new FileOutputStream(testResults);
90+
resultStream.write(String.format("%s\n", message).getBytes());
91+
if(failedTests != null){
92+
for(String test : failedTests){
93+
resultStream.write(test.getBytes());
94+
}
95+
}
96+
resultStream.flush();
97+
resultStream.close();
98+
} catch (Exception e) {
99+
Log.i(TAG, "Failed to write test suite results", e);
100+
}
77101
Log.i(TAG, message);
78102
stats.setText(message);
79103
stats.setVisibility(View.VISIBLE);
80104
findViewById(R.id.executeSuite).setEnabled(true);
81105
}
82106

107+
private void deleteTestResultsLog(){
108+
if(testResults.exists()){
109+
testResults.delete();
110+
}
111+
}
112+
83113
private void hideStats(){
84114
if(statsView != null){
85115
statsView.findViewById(R.id.stats).setVisibility(View.GONE);

src/main/java/net/zetetic/ZeteticApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.app.Application;
55
import android.util.Log;
66
import net.sqlcipher.database.SQLiteDatabase;
7+
import net.sqlcipher.database.SQLiteDatabaseHook;
78

89
import java.io.*;
910

0 commit comments

Comments
 (0)