diff options
Diffstat (limited to 'app/src/androidTest')
4 files changed, 139 insertions, 18 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java index a96c9a6d3..1f6a907d4 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java @@ -2,6 +2,12 @@ package de.test.antennapod.storage; import android.content.Context; import android.test.InstrumentationTestCase; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; + import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; @@ -10,11 +16,6 @@ import de.danoeh.antennapod.core.storage.FeedItemStatistics; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.flattr.FlattrStatus; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Random; - import static de.test.antennapod.storage.DBTestUtils.saveFeedlist; /** @@ -325,7 +326,7 @@ public class DBReaderTest extends InstrumentationTestCase { public void testGetPlaybackHistory() { final Context context = getInstrumentation().getTargetContext(); - final int numItems = (DBReader.PLAYBACK_HISTORY_SIZE+1) * 2; + final int numItems = (DBReader.PLAYBACK_HISTORY_SIZE + 1) * 2; final int playedItems = DBReader.PLAYBACK_HISTORY_SIZE + 1; final int numReturnedItems = Math.min(playedItems, DBReader.PLAYBACK_HISTORY_SIZE); final int numFeeds = 1; @@ -405,4 +406,64 @@ public class DBReaderTest extends InstrumentationTestCase { assertEquals(NUM_UNREAD, navDrawerData.numUnreadItems); assertEquals(NUM_QUEUE, navDrawerData.queueSize); } + + public void testGetFeedItemlistCheckChaptersFalse() throws Exception { + Context context = getInstrumentation().getTargetContext(); + List<Feed> feeds = DBTestUtils.saveFeedlist(context, 10, 10, false, false, 0); + for (Feed feed : feeds) { + for (FeedItem item : feed.getItems()) { + assertFalse(item.hasChapters()); + } + } + } + + public void testGetFeedItemlistCheckChaptersTrue() throws Exception { + Context context = getInstrumentation().getTargetContext(); + List<Feed> feeds = saveFeedlist(context, 10, 10, false, true, 10); + for (Feed feed : feeds) { + for (FeedItem item : feed.getItems()) { + assertTrue(item.hasChapters()); + } + } + } + + public void testLoadChaptersOfFeedItemNoChapters() throws Exception { + Context context = getInstrumentation().getTargetContext(); + List<Feed> feeds = saveFeedlist(context, 1, 3, false, false, 0); + saveFeedlist(context, 1, 3, false, true, 3); + for (Feed feed : feeds) { + for (FeedItem item : feed.getItems()) { + assertFalse(item.hasChapters()); + DBReader.loadChaptersOfFeedItem(context, item); + assertFalse(item.hasChapters()); + assertNull(item.getChapters()); + } + } + } + + public void testLoadChaptersOfFeedItemWithChapters() throws Exception { + Context context = getInstrumentation().getTargetContext(); + final int NUM_CHAPTERS = 3; + DBTestUtils.saveFeedlist(context, 1, 3, false, false, 0); + List<Feed> feeds = saveFeedlist(context, 1, 3, false, true, NUM_CHAPTERS); + for (Feed feed : feeds) { + for (FeedItem item : feed.getItems()) { + assertTrue(item.hasChapters()); + DBReader.loadChaptersOfFeedItem(context, item); + assertTrue(item.hasChapters()); + assertNotNull(item.getChapters()); + assertEquals(NUM_CHAPTERS, item.getChapters().size()); + } + } + } + + public void testGetItemWithChapters() throws Exception { + Context context = getInstrumentation().getTargetContext(); + final int NUM_CHAPTERS = 3; + List<Feed> feeds = saveFeedlist(context, 1, 1, false, true, NUM_CHAPTERS); + FeedItem item1 = feeds.get(0).getItems().get(0); + FeedItem item2 = DBReader.getFeedItem(context, item1.getId()); + assertTrue(item2.hasChapters()); + assertEquals(item1.getChapters(), item2.getChapters()); + } } diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java b/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java index 9e5f6546d..17c926cc2 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java @@ -1,12 +1,7 @@ package de.test.antennapod.storage; import android.content.Context; -import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.feed.FeedMedia; -import de.danoeh.antennapod.core.storage.PodDBAdapter; -import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; -import de.danoeh.antennapod.core.util.flattr.FlattrStatus; + import junit.framework.Assert; import java.util.ArrayList; @@ -14,12 +9,32 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import de.danoeh.antennapod.core.feed.Chapter; +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.feed.SimpleChapter; +import de.danoeh.antennapod.core.storage.PodDBAdapter; +import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; +import de.danoeh.antennapod.core.util.flattr.FlattrStatus; + /** * Utility methods for DB* tests. */ public class DBTestUtils { + /** + * Use this method when tests don't involve chapters. + */ public static List<Feed> saveFeedlist(Context context, int numFeeds, int numItems, boolean withMedia) { + return saveFeedlist(context, numFeeds, numItems, withMedia, false, 0); + } + + /** + * Use this method when tests involve chapters. + */ + public static List<Feed> saveFeedlist(Context context, int numFeeds, int numItems, boolean withMedia, + boolean withChapters, int numChapters) { if (numFeeds <= 0) { throw new IllegalArgumentException("numFeeds<=0"); } @@ -36,11 +51,18 @@ public class DBTestUtils { 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); + true, f, withChapters); if (withMedia) { FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3"); item.setMedia(media); } + if (withChapters) { + List<Chapter> chapters = new ArrayList<>(); + item.setChapters(chapters); + for (int k = 0; k < numChapters; k++) { + chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k, item, "http://example.com")); + } + } f.getItems().add(item); } Collections.sort(f.getItems(), new FeedItemPubdateComparator()); @@ -52,6 +74,7 @@ public class DBTestUtils { feeds.add(f); } adapter.close(); + return feeds; } } diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java index 4678a843b..ec8e19e22 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java @@ -4,10 +4,13 @@ import android.content.Context; import android.database.Cursor; import android.test.InstrumentationTestCase; import android.util.Log; + +import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedImage; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.feed.SimpleChapter; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.PodDBAdapter; @@ -101,7 +104,7 @@ public class DBWriterTest extends InstrumentationTestCase { List<File> itemFiles = new ArrayList<File>(); // create items with downloaded media files for (int i = 0; i < 10; i++) { - FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), true, feed); + FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), true, feed, true); feed.getItems().add(item); File enc = new File(destFolder, "file " + i); @@ -110,6 +113,9 @@ public class DBWriterTest extends InstrumentationTestCase { FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", true, null, 0); item.setMedia(media); + + item.setChapters(new ArrayList<Chapter>()); + item.getChapters().add(new SimpleChapter(0, "item " + i, item, "example.com")); } PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getContext()); @@ -122,6 +128,7 @@ public class DBWriterTest extends InstrumentationTestCase { for (FeedItem item : feed.getItems()) { assertTrue(item.getId() != 0); assertTrue(item.getMedia().getId() != 0); + assertTrue(item.getChapters().get(0).getId() != 0); } DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS); @@ -135,18 +142,20 @@ public class DBWriterTest extends InstrumentationTestCase { adapter = new PodDBAdapter(getInstrumentation().getContext()); adapter.open(); Cursor c = adapter.getFeedCursor(feed.getId()); - assertTrue(c.getCount() == 0); + assertEquals(0, c.getCount()); c.close(); c = adapter.getImageCursor(image.getId()); - assertTrue(c.getCount() == 0); + assertEquals(0, c.getCount()); c.close(); for (FeedItem item : feed.getItems()) { c = adapter.getFeedItemCursor(String.valueOf(item.getId())); - assertTrue(c.getCount() == 0); + assertEquals(0, c.getCount()); c.close(); c = adapter.getSingleFeedMediaCursor(item.getMedia().getId()); - assertTrue(c.getCount() == 0); + assertEquals(0, c.getCount()); c.close(); + c = adapter.getSimpleChaptersOfFeedItemCursor(item); + assertEquals(0, c.getCount()); } } diff --git a/app/src/androidTest/java/de/test/antennapod/util/URLCheckerTest.java b/app/src/androidTest/java/de/test/antennapod/util/URLCheckerTest.java index 47b58268b..aa197b6e1 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/URLCheckerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/util/URLCheckerTest.java @@ -73,4 +73,32 @@ public class URLCheckerTest extends AndroidTestCase { final String out = URLChecker.prepareURL(in); assertEquals("https://example.com", out); } + + public void testProtocolRelativeUrlIsAbsolute() throws Exception { + final String in = "https://example.com"; + final String inBase = "http://examplebase.com"; + final String out = URLChecker.prepareURL(in, inBase); + assertEquals(in, out); + } + + public void testProtocolRelativeUrlIsRelativeHttps() throws Exception { + final String in = "//example.com"; + final String inBase = "https://examplebase.com"; + final String out = URLChecker.prepareURL(in, inBase); + assertEquals("https://example.com", out); + + } + + public void testProtocolRelativeUrlIsHttpsWithAPSubscribeProtocol() throws Exception { + final String in = "//example.com"; + final String inBase = "antennapod-subscribe://https://examplebase.com"; + final String out = URLChecker.prepareURL(in, inBase); + assertEquals("https://example.com", out); + } + + public void testProtocolRelativeUrlBaseUrlNull() throws Exception { + final String in = "example.com"; + final String out = URLChecker.prepareURL(in, null); + assertEquals("http://example.com", out); + } } |