aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorStephan Merker <merker.stephan@googlemail.com>2011-11-09 23:13:31 +0100
committerStephan Merker <merker.stephan@googlemail.com>2011-11-09 23:13:31 +0100
commit759f158b115fe27f7c61409d5f540d1effb6c0e1 (patch)
treeb3acf25fd5445ccb7d9b9e0e81818ecee010c3d7 /tests/src
parentdc1dcb57cf7b4b3b183e240e1a529816d3107ff4 (diff)
downloadcgeo-759f158b115fe27f7c61409d5f540d1effb6c0e1.zip
cgeo-759f158b115fe27f7c61409d5f540d1effb6c0e1.tar.gz
cgeo-759f158b115fe27f7c61409d5f540d1effb6c0e1.tar.bz2
new: cancel GPX import with back button
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/files/GPXImporterTest.java20
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java3
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java3
3 files changed, 19 insertions, 7 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
index f560d6b..182e5e9 100644
--- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
@@ -4,8 +4,8 @@ import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgSearch;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.test.R;
+import cgeo.geocaching.utils.CancellableHandler;
-import android.os.Handler;
import android.os.Message;
import android.test.InstrumentationTestCase;
@@ -118,6 +118,20 @@ public class GPXImporterTest extends InstrumentationTestCase {
assertEquals(GPXImporter.IMPORT_STEP_FINISHED_WITH_ERROR, importStepHandler.messages.get(1).what);
}
+ public void testImportGpxCancel() throws IOException {
+ File gc31j2h = new File(tempDir, "gc31j2h.gpx");
+ copyResourceToFile(R.raw.gc31j2h, gc31j2h);
+
+ progressHandler.cancel();
+ GPXImporter.ImportGpxFileThread importThread = new GPXImporter.ImportGpxFileThread(gc31j2h, listId, importStepHandler, progressHandler);
+ importThread.run();
+ importStepHandler.waitForCompletion();
+
+ assertEquals(2, importStepHandler.messages.size());
+ assertEquals(GPXImporter.IMPORT_STEP_READ_FILE, importStepHandler.messages.get(0).what);
+ assertEquals(GPXImporter.IMPORT_STEP_CANCELED, importStepHandler.messages.get(1).what);
+ }
+
private void copyResourceToFile(int resourceId, File file) throws IOException {
final InputStream is = getInstrumentation().getContext().getResources().openRawResource(resourceId);
final FileOutputStream os = new FileOutputStream(file);
@@ -134,12 +148,12 @@ public class GPXImporterTest extends InstrumentationTestCase {
}
}
- static class TestHandler extends Handler {
+ static class TestHandler extends CancellableHandler {
private final List<Message> messages = new ArrayList<Message>();
private long lastMessage = System.currentTimeMillis();
@Override
- public synchronized void handleMessage(Message msg) {
+ public synchronized void handleRegularMessage(Message msg) {
final Message msg1 = new Message();
msg1.copyFrom(msg);
messages.add(msg1);
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index bc4b9d1..6f585b3 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -11,7 +11,6 @@ import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.test.R;
import android.content.res.Resources;
-import android.os.Handler;
import android.test.InstrumentationTestCase;
import java.io.IOException;
@@ -190,7 +189,7 @@ public class GPXParserTest extends InstrumentationTestCase {
final Resources res = getInstrumentation().getContext().getResources();
final InputStream instream = res.openRawResource(resourceId);
try {
- caches = parser.parse(instream, new Handler());
+ caches = parser.parse(instream, null);
assertNotNull(caches);
} finally {
instream.close();
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index 6fa8182..31e8e13 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -6,7 +6,6 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.R;
import android.content.res.Resources;
-import android.os.Handler;
import android.test.InstrumentationTestCase;
import java.io.IOException;
@@ -22,7 +21,7 @@ public class LocParserTest extends InstrumentationTestCase {
final Resources res = getInstrumentation().getContext().getResources();
final InputStream instream = res.openRawResource(resourceId);
try {
- caches = parser.parse(instream, new Handler());
+ caches = parser.parse(instream, null);
assertNotNull(caches);
assertTrue(caches.size() > 0);
} finally {