Skip to content

Commit e684de7

Browse files
Making the TestSuiteRunner an async task
Tests run on Android between versions 2.1 and 3.2
1 parent 4f1783b commit e684de7

File tree

8 files changed

+144
-120
lines changed

8 files changed

+144
-120
lines changed

AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
</activity>
1212
<provider android:name=".ZeteticContentProvider" android:authorities="net.zetetic.sqlcipher.zeteticprovider" />
1313
</application>
14+
<uses-permission android:name="android.permission.READ_CONTACTS" />
1415
</manifest>
1516

libs/sqlcipher.jar

-8.48 KB
Binary file not shown.

net.zetetic.sqlcipher.test.iws

Lines changed: 84 additions & 112 deletions
Large diffs are not rendered by default.

res/layout/main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:layout_height="fill_parent"
66
>
77
<Button
8-
android:id="@+id/button1"
8+
android:id="@+id/executeSuite"
99
android:layout_width="fill_parent"
1010
android:layout_height="wrap_content"
1111
android:text="@string/test_suite_button"

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ public void onCreate(Bundle savedInstanceState) {
2323

2424
public void onButtonClick(View view) {
2525

26+
findViewById(R.id.executeSuite).setEnabled(false);
2627
resultsView = (TextView) findViewById(R.id.test_suite_results);
2728
ZeteticApplication.getInstance().setCurrentActivity(this);
28-
TestSuiteRunner runner = new TestSuiteRunner(this);
29-
runner.runSuite();
29+
new TestSuiteRunner().execute(this);
3030
}
3131

3232
@Override
3333
public void send(TestResult result) {
3434
resultsView.append(result.toString());
3535
}
36+
37+
@Override
38+
public void complete() {
39+
findViewById(R.id.executeSuite).setEnabled(true);
40+
}
3641
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.zetetic.tests;
2+
3+
import android.database.Cursor;
4+
import info.guardianproject.database.sqlcipher.SQLiteDatabase;
5+
6+
public class LoopingCountQueryTest extends SQLCipherTest {
7+
8+
@Override
9+
public boolean execute(SQLiteDatabase database) {
10+
int counter = 0;
11+
int iterations = 10;
12+
database.execSQL("create table t1(a);");
13+
database.execSQL("insert into t1(a) values (?)", new Object[]{"foo"});
14+
StringBuilder buffer = new StringBuilder();
15+
while(counter < iterations){
16+
Cursor cursor = database.rawQuery("select count(*) from t1", null);
17+
if(cursor != null){
18+
cursor.moveToFirst();
19+
buffer.append(cursor.getInt(0));
20+
cursor.close();
21+
}
22+
counter++;
23+
}
24+
return buffer.toString().length() > 0;
25+
}
26+
27+
@Override
28+
public String getName() {
29+
return "Looping Count Query Test";
30+
}
31+
}

src/main/java/net/zetetic/tests/ResultNotifier.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
public interface ResultNotifier {
44
void send(TestResult result);
5+
void complete();
56
}

src/main/java/net/zetetic/tests/TestSuiteRunner.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
package net.zetetic.tests;
22

3+
import android.os.AsyncTask;
34
import android.util.Log;
45
import info.guardianproject.database.sqlcipher.SQLiteDatabase;
56
import net.zetetic.ZeteticApplication;
67

78
import java.util.ArrayList;
89
import java.util.List;
910

10-
public class TestSuiteRunner {
11+
public class TestSuiteRunner extends AsyncTask<ResultNotifier, TestResult, Void> {
1112

1213
private ResultNotifier notifier;
1314

14-
public TestSuiteRunner(ResultNotifier notifier) {
15-
this.notifier = notifier;
15+
@Override
16+
protected Void doInBackground(ResultNotifier... resultNotifiers) {
17+
this.notifier = resultNotifiers[0];
18+
runSuite();
19+
return null;
1620
}
1721

18-
public void runSuite(){
22+
@Override
23+
protected void onProgressUpdate(TestResult... values) {
24+
notifier.send(values[0]);
25+
}
26+
27+
@Override
28+
protected void onPostExecute(Void aVoid) {
29+
notifier.complete();
30+
}
31+
32+
private void runSuite(){
1933

2034
SQLiteDatabase.loadLibs(ZeteticApplication.getInstance());
2135
for(SQLCipherTest test : getTestsToRun()){
2236
Log.i(ZeteticApplication.TAG, "Running test:" + test.getName());
23-
notifier.send(test.run());
37+
publishProgress(test.run());
2438
}
2539
}
2640

0 commit comments

Comments
 (0)