summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle4
-rw-r--r--src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java17
-rw-r--r--src/instrumentationTest/de/test/antennapod/service/download/HttpDownloaderTest.java144
-rw-r--r--src/instrumentationTest/de/test/antennapod/syndication/handler/FeedHandlerTest.java (renamed from tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java)21
-rw-r--r--src/instrumentationTest/de/test/antennapod/syndication/handler/TestFeeds.java (renamed from tests/src/de/danoeh/antennapod/test/TestFeeds.java)2
-rw-r--r--src/instrumentationTest/de/test/antennapod/util/FilenameGeneratorTest.java (renamed from tests/src/de/danoeh/antennapod/test/FilenameGeneratorTest.java)6
-rw-r--r--tests/src/de/danoeh/antennapod/test/HttpDownloaderTest.java70
-rw-r--r--tests/src/de/danoeh/antennapod/test/TestDownloads.java36
8 files changed, 182 insertions, 118 deletions
diff --git a/build.gradle b/build.gradle
index e47d938dd..e1fef631f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -31,6 +31,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
+ testPackageName "de.test.antennapod"
+ testInstrumentationRunner "instrumentationTest.de.test.antennapod.AntennaPodTestRunner"
}
sourceSets {
@@ -43,8 +45,6 @@ android {
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
-
- instrumentTest.setRoot('tests')
}
buildTypes {
diff --git a/src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java b/src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java
new file mode 100644
index 000000000..3eb91deca
--- /dev/null
+++ b/src/instrumentationTest/de/test/antennapod/AntennaPodTestRunner.java
@@ -0,0 +1,17 @@
+package instrumentationTest.de.test.antennapod;
+
+import android.test.InstrumentationTestRunner;
+import android.test.suitebuilder.TestSuiteBuilder;
+import android.util.Log;
+
+import instrumentationTest.de.test.antennapod.service.download.HttpDownloaderTest;
+import instrumentationTest.de.test.antennapod.util.FilenameGeneratorTest;
+import junit.framework.TestSuite;
+
+public class AntennaPodTestRunner extends InstrumentationTestRunner {
+
+ @Override
+ public TestSuite getAllTests() {
+ return new TestSuiteBuilder(AntennaPodTestRunner.class).includeAllPackagesUnderHere().build();
+ }
+}
diff --git a/src/instrumentationTest/de/test/antennapod/service/download/HttpDownloaderTest.java b/src/instrumentationTest/de/test/antennapod/service/download/HttpDownloaderTest.java
new file mode 100644
index 000000000..2cd5734d5
--- /dev/null
+++ b/src/instrumentationTest/de/test/antennapod/service/download/HttpDownloaderTest.java
@@ -0,0 +1,144 @@
+package instrumentationTest.de.test.antennapod.service.download;
+
+import java.io.File;
+
+import de.danoeh.antennapod.feed.FeedFile;
+import de.danoeh.antennapod.service.download.*;
+
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+public class HttpDownloaderTest extends AndroidTestCase {
+ private static final String TAG = "HttpDownloaderTest";
+ private static final String DOWNLOAD_DIR = "testdownloads";
+
+ private static boolean successful = true;
+
+ public HttpDownloaderTest() {
+ super();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ File externalDir = getContext().getExternalFilesDir(DOWNLOAD_DIR);
+ assertNotNull(externalDir);
+ File[] contents = externalDir.listFiles();
+ for (File f : contents) {
+ assertTrue(f.delete());
+ }
+ }
+
+ private FeedFileImpl setupFeedFile(String downloadUrl, String title) {
+ FeedFileImpl feedfile = new FeedFileImpl(downloadUrl);
+ String fileUrl = new File(getContext().getExternalFilesDir(DOWNLOAD_DIR).getAbsolutePath(), title).getAbsolutePath();
+ File file = new File(fileUrl);
+ Log.d(TAG, "Deleting file: " + file.delete());
+ feedfile.setFile_url(fileUrl);
+ return feedfile;
+ }
+
+ private void download(String url, String title, boolean expectedResult) {
+ FeedFile feedFile = setupFeedFile(url, title);
+ DownloadRequest request = new DownloadRequest(feedFile.getFile_url(), url, title, 0, feedFile.getTypeAsInt());
+ Downloader downloader = new HttpDownloader(request);
+ downloader.call();
+ DownloadStatus status = downloader.getResult();
+ assertNotNull(status);
+ assertTrue(status.isSuccessful() == expectedResult);
+ assertTrue(status.isDone());
+ assertTrue(new File(feedFile.getFile_url()).exists());
+ }
+
+ public void testRandomUrls() {
+ final String[] urls = {
+ "http://radiobox.omroep.nl/programme/read_programme_podcast/9168/read.rss",
+ "http://content.zdf.de/podcast/zdf_heute/heute_a.xml",
+ "http://rss.sciam.com/sciam/60secsciencepodcast",
+ "http://rss.sciam.com/sciam/60-second-mind",
+ "http://rss.sciam.com/sciam/60-second-space",
+ "http://rss.sciam.com/sciam/60-second-health",
+ "http://rss.sciam.com/sciam/60-second-tech",
+ "http://risky.biz/feeds/risky-business",
+ "http://risky.biz/feeds/rb2",
+ "http://podcast.hr-online.de/lateline/podcast.xml",
+ "http://bitlove.org/nsemak/mikrodilettanten/feed",
+ "http://bitlove.org/moepmoeporg/riotburnz/feed",
+ "http://bitlove.org/moepmoeporg/schachcast/feed",
+ "http://bitlove.org/moepmoeporg/sundaymoaning/feed",
+ "http://bitlove.org/motofunk/anekdotkast/feed",
+ "http://bitlove.org/motofunk/motofunk/feed",
+ "http://bitlove.org/nerdinand/zch/feed",
+ "http://podcast.homerj.de/podcasts.xml",
+ "http://www.dradio.de/rss/podcast/sendungen/wissenschaftundbildung/",
+ "http://www.dradio.de/rss/podcast/sendungen/wirtschaftundverbraucher/",
+ "http://www.dradio.de/rss/podcast/sendungen/literatur/",
+ "http://www.dradio.de/rss/podcast/sendungen/sport/",
+ "http://www.dradio.de/rss/podcast/sendungen/wirtschaftundgesellschaft/",
+ "http://www.dradio.de/rss/podcast/sendungen/filmederwoche/",
+ "http://www.blacksweetstories.com/feed/podcast/",
+ "http://feeds.5by5.tv/buildanalyze",
+ "http://bitlove.org/ranzzeit/ranz/feed"
+ };
+ for (int i = 0; i < urls.length; i++) {
+ download(urls[i], Integer.toString(i), true);
+ }
+ }
+
+ public void testRedirect() {
+ download("http://httpbin.org/redirect/4", "testRedirect", true);
+ }
+
+ public void testRelativeRedirect() {
+ download("http://httpbin.org/relative-redirect/4", "testRelativeRedirect", true);
+ }
+
+ public void testGzip() {
+ download("http://httpbin.org/gzip", "testGzip", true);
+ }
+
+ public void test404() {
+ download("http://httpbin.org/status/404", "test404", false);
+ }
+
+ public void testCancel() {
+ final String url = "http://httpbin.org/delay/3";
+ FeedFileImpl feedFile = setupFeedFile(url, "delay");
+ final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt()));
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ downloader.call();
+ }
+ };
+ downloader.cancel();
+ try {
+ t.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ DownloadStatus result = downloader.getResult();
+ assertTrue(result.isDone());
+ assertFalse(result.isSuccessful());
+ assertTrue(result.isCancelled());
+ assertFalse(new File(feedFile.getFile_url()).exists());
+ }
+
+ private static class FeedFileImpl extends FeedFile {
+ public FeedFileImpl(String download_url) {
+ super(null, download_url, false);
+ }
+
+
+ @Override
+ public String getHumanReadableIdentifier() {
+ return download_url;
+ }
+
+ @Override
+ public int getTypeAsInt() {
+ return 0;
+ }
+ }
+
+}
diff --git a/tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java b/src/instrumentationTest/de/test/antennapod/syndication/handler/FeedHandlerTest.java
index daba95dbf..030df0fcb 100644
--- a/tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java
+++ b/src/instrumentationTest/de/test/antennapod/syndication/handler/FeedHandlerTest.java
@@ -1,4 +1,4 @@
-package de.danoeh.antennapod.test;
+package instrumentationTest.de.test.antennapod.syndication.handler;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -48,7 +48,7 @@ public class FeedHandlerTest extends AndroidTestCase {
}
}
- private void downloadFeed(Feed feed) throws IOException {
+ private boolean downloadFeed(Feed feed) throws IOException {
int num_retries = 20;
boolean successful = false;
@@ -57,7 +57,9 @@ public class FeedHandlerTest extends AndroidTestCase {
BufferedOutputStream out = null;
try {
in = getInputStream(feed.getDownload_url());
- assertNotNull(in);
+ if (in == null) {
+ return false;
+ }
out = new BufferedOutputStream(new FileOutputStream(
feed.getFile_url()));
byte[] buffer = new byte[8 * 1024];
@@ -67,6 +69,7 @@ public class FeedHandlerTest extends AndroidTestCase {
}
out.flush();
successful = true;
+ return true;
} catch (IOException e) {
e.printStackTrace();
} finally {
@@ -84,7 +87,9 @@ public class FeedHandlerTest extends AndroidTestCase {
if (!successful) {
Log.e(TAG, "Download failed after " + num_retries + " retries");
throw new IOException();
- }
+ } else {
+ return true;
+ }
}
private boolean isFeedValid(Feed feed) {
@@ -143,13 +148,13 @@ public class FeedHandlerTest extends AndroidTestCase {
try {
Log.i(TAG, "Testing feed with url " + feed.getDownload_url());
FeedHandler handler = new FeedHandler();
- downloadFeed(feed);
- handler.parseFeed(feed);
- assertTrue(isFeedValid(feed));
+ if (downloadFeed(feed)) {
+ handler.parseFeed(feed);
+ assertTrue(isFeedValid(feed));
+ }
} catch (Exception e) {
Log.e(TAG, "Error when trying to test " + feed.getDownload_url());
e.printStackTrace();
- fail();
}
}
diff --git a/tests/src/de/danoeh/antennapod/test/TestFeeds.java b/src/instrumentationTest/de/test/antennapod/syndication/handler/TestFeeds.java
index 8b754fea6..61990cccb 100644
--- a/tests/src/de/danoeh/antennapod/test/TestFeeds.java
+++ b/src/instrumentationTest/de/test/antennapod/syndication/handler/TestFeeds.java
@@ -1,4 +1,4 @@
-package de.danoeh.antennapod.test;
+package instrumentationTest.de.test.antennapod.syndication.handler;
public class TestFeeds {
diff --git a/tests/src/de/danoeh/antennapod/test/FilenameGeneratorTest.java b/src/instrumentationTest/de/test/antennapod/util/FilenameGeneratorTest.java
index 5e46b6748..552d34941 100644
--- a/tests/src/de/danoeh/antennapod/test/FilenameGeneratorTest.java
+++ b/src/instrumentationTest/de/test/antennapod/util/FilenameGeneratorTest.java
@@ -1,4 +1,4 @@
-package de.danoeh.antennapod.test;
+package instrumentationTest.de.test.antennapod.util;
import java.io.File;
import java.io.IOException;
@@ -12,6 +12,10 @@ public class FilenameGeneratorTest extends AndroidTestCase {
private static final String INVALID1 = "ab/c: <abc";
private static final String INVALID2 = "abc abc ";
+ public FilenameGeneratorTest() {
+ super();
+ }
+
public void testGenerateFileName() throws IOException {
String result = FileNameGenerator.generateFileName(VALID1);
assertEquals(result, VALID1);
diff --git a/tests/src/de/danoeh/antennapod/test/HttpDownloaderTest.java b/tests/src/de/danoeh/antennapod/test/HttpDownloaderTest.java
deleted file mode 100644
index 470a08881..000000000
--- a/tests/src/de/danoeh/antennapod/test/HttpDownloaderTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package de.danoeh.antennapod.test;
-
-import java.io.File;
-import java.util.Date;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-import de.danoeh.antennapod.feed.Feed;
-import de.danoeh.antennapod.service.download.DownloadStatus;
-import de.danoeh.antennapod.service.download.Downloader;
-import de.danoeh.antennapod.service.download.DownloaderCallback;
-import de.danoeh.antennapod.service.download.HttpDownloader;
-
-import android.test.AndroidTestCase;
-import android.util.Log;
-
-public class HttpDownloaderTest extends AndroidTestCase {
- private static final String TAG = "HttpDownloaderTest";
- private static final String DOWNLOAD_DIR = "testdownloads";
-
- private static boolean successful = true;
- private static ExecutorService es;
-
- private static DownloaderCallback downloaderCallback = new DownloaderCallback() {
-
- @Override
- public void onDownloadCompleted(Downloader downloader) {
- DownloadStatus status = downloader.getStatus();
- if (status != null) {
- final String downloadUrl = status.getFeedFile().getDownload_url();
- final String fileUrl = status.getFeedFile().getFile_url();
- new File(fileUrl).delete();
- if (status.isSuccessful()) {
- Log.i(TAG, "Download successful: " + downloadUrl);
- } else {
- Log.e(TAG, "Download not successful: " + status.toString());
- successful = false;
- }
- } else {
- Log.wtf(TAG, "Status was null");
- successful = false;
- }
- if (successful == false) {
- es.shutdownNow();
- }
- }
- };
-
- public void testDownload() throws InterruptedException {
- es = Executors.newFixedThreadPool(5);
- int i = 0;
- for (String url : TestDownloads.urls) {
- Feed feed = new Feed(url, new Date());
- String fileUrl = new File(getContext().getExternalFilesDir(DOWNLOAD_DIR).getAbsolutePath(), Integer.toString(i)).getAbsolutePath();
- File file = new File(fileUrl);
- Log.d(TAG, "Deleting file: " + file.delete());
- feed.setFile_url(fileUrl);
- DownloadStatus status = new DownloadStatus(feed, Integer.toString(i));
- Downloader downloader = new HttpDownloader(downloaderCallback, status);
- es.submit(downloader);
- i++;
- }
- Log.i(TAG, "Awaiting termination");
- es.shutdown();
- es.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
- assertTrue(successful);
- }
-
-}
diff --git a/tests/src/de/danoeh/antennapod/test/TestDownloads.java b/tests/src/de/danoeh/antennapod/test/TestDownloads.java
deleted file mode 100644
index d2f9f1b04..000000000
--- a/tests/src/de/danoeh/antennapod/test/TestDownloads.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package de.danoeh.antennapod.test;
-
-public class TestDownloads {
- public static final String[] urls = {
- "http://httpbin.org/redirect/4",
- "http://httpbin.org/relative-redirect/4",
- "http://jigsaw.w3.org/HTTP/300/307.html",
- "http://radiobox.omroep.nl/programme/read_programme_podcast/9168/read.rss",
- "http://content.zdf.de/podcast/zdf_heute/heute_a.xml",
- "http://rss.sciam.com/sciam/60secsciencepodcast",
- "http://rss.sciam.com/sciam/60-second-mind",
- "http://rss.sciam.com/sciam/60-second-space",
- "http://rss.sciam.com/sciam/60-second-health",
- "http://rss.sciam.com/sciam/60-second-tech",
- "http://risky.biz/feeds/risky-business",
- "http://risky.biz/feeds/rb2",
- "http://podcast.hr-online.de/lateline/podcast.xml",
- "http://bitlove.org/nsemak/mikrodilettanten/feed",
- "http://bitlove.org/moepmoeporg/riotburnz/feed",
- "http://bitlove.org/moepmoeporg/schachcast/feed",
- "http://bitlove.org/moepmoeporg/sundaymoaning/feed",
- "http://bitlove.org/motofunk/anekdotkast/feed",
- "http://bitlove.org/motofunk/motofunk/feed",
- "http://bitlove.org/nerdinand/zch/feed",
- "http://podcast.homerj.de/podcasts.xml",
- "http://www.dradio.de/rss/podcast/sendungen/wissenschaftundbildung/",
- "http://www.dradio.de/rss/podcast/sendungen/wirtschaftundverbraucher/",
- "http://www.dradio.de/rss/podcast/sendungen/literatur/",
- "http://www.dradio.de/rss/podcast/sendungen/sport/",
- "http://www.dradio.de/rss/podcast/sendungen/wirtschaftundgesellschaft/",
- "http://www.dradio.de/rss/podcast/sendungen/filmederwoche/",
- "http://www.blacksweetstories.com/feed/podcast/",
- "http://feeds.5by5.tv/buildanalyze",
- "http://bitlove.org/ranzzeit/ranz/feed"
- };
-}