summaryrefslogtreecommitdiff
path: root/src/instrumentationTest/de/test/antennapod
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2013-10-09 19:52:33 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2013-10-09 19:52:33 +0200
commitdf9f6661e140ca7ea5fa24897b74071f49f9e86d (patch)
tree1b7d13315062e8f4721215da67d69029d8d0b119 /src/instrumentationTest/de/test/antennapod
parent09b93a8b4b9e1bf050c683a88503d695bea701fa (diff)
downloadAntennaPod-df9f6661e140ca7ea5fa24897b74071f49f9e86d.zip
Fixed a bug that might cause the wrong episode to be auto-deleted
Diffstat (limited to 'src/instrumentationTest/de/test/antennapod')
-rw-r--r--src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java52
-rw-r--r--src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java25
-rw-r--r--src/instrumentationTest/de/test/antennapod/storage/DBTestUtils.java56
3 files changed, 89 insertions, 44 deletions
diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java b/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java
index 445092ebc..91ac61867 100644
--- a/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java
+++ b/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java
@@ -4,10 +4,9 @@ import android.content.Context;
import android.test.InstrumentationTestCase;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedItem;
-import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.PodDBAdapter;
-import de.danoeh.antennapod.util.comparator.FeedItemPubdateComparator;
+import static instrumentationTest.de.test.antennapod.storage.DBTestUtils.*;
import java.util.*;
@@ -65,46 +64,11 @@ public class DBReaderTest extends InstrumentationTestCase {
expiredFeedListTestHelper(System.currentTimeMillis() - expirationTime / 2, expirationTime, false);
}
- private List<Feed> saveFeedlist(int numFeeds, int numItems, boolean withMedia) {
- if (numFeeds <= 0) {
- throw new IllegalArgumentException("numFeeds<=0");
- }
- if (numItems < 0) {
- throw new IllegalArgumentException("numItems<0");
- }
- final Context context = getInstrumentation().getTargetContext();
- List<Feed> feeds = new ArrayList<Feed>();
- PodDBAdapter adapter = new PodDBAdapter(context);
- adapter.open();
- for (int i = 0; i < numFeeds; i++) {
- Feed f = new Feed(0, new Date(), "feed " + i, "link" + i, "descr", null, null,
- null, null, "id" + i, null, null, "url" + i, false);
- f.setItems(new ArrayList<FeedItem>());
- for (int j = 0; j < numItems; j++) {
- FeedItem item = new FeedItem(0, "item " + j, "id" + j, "link" + j, new Date(),
- true, f);
- if (withMedia) {
- FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3");
- item.setMedia(media);
- }
- f.getItems().add(item);
- }
- Collections.sort(f.getItems(), new FeedItemPubdateComparator());
- adapter.setCompleteFeed(f);
- assertTrue(f.getId() != 0);
- for (FeedItem item : f.getItems()) {
- assertTrue(item.getId() != 0);
- }
- feeds.add(f);
- }
- adapter.close();
- return feeds;
- }
public void testGetFeedList() {
final Context context = getInstrumentation().getTargetContext();
- List<Feed> feeds = saveFeedlist(10, 0, false);
+ List<Feed> feeds = saveFeedlist(context, 10, 0, false);
List<Feed> savedFeeds = DBReader.getFeedList(context);
assertNotNull(savedFeeds);
assertTrue(savedFeeds.size() == feeds.size());
@@ -115,7 +79,7 @@ public class DBReaderTest extends InstrumentationTestCase {
public void testFeedListDownloadUrls() {
final Context context = getInstrumentation().getTargetContext();
- List<Feed> feeds = saveFeedlist(10, 0, false);
+ List<Feed> feeds = saveFeedlist(context, 10, 0, false);
List<String> urls = DBReader.getFeedListDownloadUrls(context);
assertNotNull(urls);
assertTrue(urls.size() == feeds.size());
@@ -128,7 +92,7 @@ public class DBReaderTest extends InstrumentationTestCase {
final Context context = getInstrumentation().getTargetContext();
final int numFeeds = 10;
final int numItems = 1;
- List<Feed> feeds = saveFeedlist(numFeeds, numItems, false);
+ List<Feed> feeds = saveFeedlist(context, numFeeds, numItems, false);
List<FeedItem> items = new ArrayList<FeedItem>();
for (Feed f : feeds) {
for (FeedItem item : f.getItems()) {
@@ -152,7 +116,7 @@ public class DBReaderTest extends InstrumentationTestCase {
final Context context = getInstrumentation().getTargetContext();
final int numFeeds = 1;
final int numItems = 10;
- Feed feed = saveFeedlist(numFeeds, numItems, false).get(0);
+ Feed feed = saveFeedlist(context, numFeeds, numItems, false).get(0);
List<FeedItem> items = feed.getItems();
feed.setItems(null);
List<FeedItem> savedItems = DBReader.getFeedItemList(context, feed);
@@ -168,7 +132,7 @@ public class DBReaderTest extends InstrumentationTestCase {
throw new IllegalArgumentException("numItems<=0");
}
final Context context = getInstrumentation().getTargetContext();
- List<Feed> feeds = saveFeedlist(numItems, numItems, false);
+ List<Feed> feeds = saveFeedlist(context, numItems, numItems, false);
List<FeedItem> allItems = new ArrayList<FeedItem>();
for (Feed f : feeds) {
allItems.addAll(f.getItems());
@@ -220,7 +184,7 @@ public class DBReaderTest extends InstrumentationTestCase {
throw new IllegalArgumentException("numItems<=0");
}
final Context context = getInstrumentation().getTargetContext();
- List<Feed> feeds = saveFeedlist(numItems, numItems, true);
+ List<Feed> feeds = saveFeedlist(context, numItems, numItems, true);
List<FeedItem> items = new ArrayList<FeedItem>();
for (Feed f : feeds) {
items.addAll(f.getItems());
@@ -263,7 +227,7 @@ public class DBReaderTest extends InstrumentationTestCase {
throw new IllegalArgumentException("numItems<=0");
}
final Context context = getInstrumentation().getTargetContext();
- List<Feed> feeds = saveFeedlist(numItems, numItems, true);
+ List<Feed> feeds = saveFeedlist(context, numItems, numItems, true);
List<FeedItem> items = new ArrayList<FeedItem>();
for (Feed f : feeds) {
items.addAll(f.getItems());
diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java b/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java
index 3f928bd9b..e9b871867 100644
--- a/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java
+++ b/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java
@@ -19,6 +19,8 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
+import static instrumentationTest.de.test.antennapod.storage.DBTestUtils.*;
+
/**
* Test class for DBTasks
*/
@@ -167,6 +169,29 @@ public class DBTasksTest extends InstrumentationTestCase {
}
}
+ /**
+ * Reproduces a bug where DBTasks.performAutoCleanup(android.content.Context) would use the ID of the FeedItem in the
+ * call to DBWriter.deleteFeedMediaOfItem instead of the ID of the FeedMedia. This would cause the wrong item to be deleted.
+ * @throws IOException
+ */
+ public void testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia() throws IOException {
+ final Context context = getInstrumentation().getTargetContext();
+ // add feed with no enclosures so that item ID != media ID
+ saveFeedlist(context, 1, 10, false);
+
+ // add candidate for performAutoCleanup
+ List<Feed> feeds = saveFeedlist(getInstrumentation().getTargetContext(), 1, 1, true);
+ FeedMedia m = feeds.get(0).getItems().get(0).getMedia();
+ m.setDownloaded(true);
+ m.setFile_url("file");
+ PodDBAdapter adapter = new PodDBAdapter(context);
+ adapter.open();
+ adapter.setMedia(m);
+ adapter.close();
+
+ testPerformAutoCleanupShouldNotDeleteBecauseInQueue();
+ }
+
public void testUpdateFeedNewFeed() {
final Context context = getInstrumentation().getTargetContext();
final int NUM_ITEMS = 10;
diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBTestUtils.java b/src/instrumentationTest/de/test/antennapod/storage/DBTestUtils.java
new file mode 100644
index 000000000..fbb7b0386
--- /dev/null
+++ b/src/instrumentationTest/de/test/antennapod/storage/DBTestUtils.java
@@ -0,0 +1,56 @@
+package instrumentationTest.de.test.antennapod.storage;
+
+import android.content.Context;
+import de.danoeh.antennapod.feed.Feed;
+import de.danoeh.antennapod.feed.FeedItem;
+import de.danoeh.antennapod.feed.FeedMedia;
+import de.danoeh.antennapod.storage.PodDBAdapter;
+import de.danoeh.antennapod.util.comparator.FeedItemPubdateComparator;
+import junit.framework.Assert;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Utility methods for DB* tests.
+ */
+public class DBTestUtils {
+
+ public static List<Feed> saveFeedlist(Context context, int numFeeds, int numItems, boolean withMedia) {
+ if (numFeeds <= 0) {
+ throw new IllegalArgumentException("numFeeds<=0");
+ }
+ if (numItems < 0) {
+ throw new IllegalArgumentException("numItems<0");
+ }
+
+ List<Feed> feeds = new ArrayList<Feed>();
+ PodDBAdapter adapter = new PodDBAdapter(context);
+ adapter.open();
+ for (int i = 0; i < numFeeds; i++) {
+ Feed f = new Feed(0, new Date(), "feed " + i, "link" + i, "descr", null, null,
+ null, null, "id" + i, null, null, "url" + i, false);
+ f.setItems(new ArrayList<FeedItem>());
+ for (int j = 0; j < numItems; j++) {
+ FeedItem item = new FeedItem(0, "item " + j, "id" + j, "link" + j, new Date(),
+ true, f);
+ if (withMedia) {
+ FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3");
+ item.setMedia(media);
+ }
+ f.getItems().add(item);
+ }
+ Collections.sort(f.getItems(), new FeedItemPubdateComparator());
+ adapter.setCompleteFeed(f);
+ Assert.assertTrue(f.getId() != 0);
+ for (FeedItem item : f.getItems()) {
+ Assert.assertTrue(item.getId() != 0);
+ }
+ feeds.add(f);
+ }
+ adapter.close();
+ return feeds;
+ }
+}