summaryrefslogtreecommitdiff
path: root/src/instrumentationTest/de/test
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2014-06-29 02:38:25 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2014-06-29 02:50:09 +0200
commitc9c69aa7c796da59c29fad2c4d4c9464d353416b (patch)
tree57d0d94d11a46fda5ea38b85d35573393f89ed35 /src/instrumentationTest/de/test
parent2633d17046ab2373d0f1a8976a16a3e0ee15a5cf (diff)
downloadAntennaPod-c9c69aa7c796da59c29fad2c4d4c9464d353416b.zip
Added first implementation of the Timeline class
Diffstat (limited to 'src/instrumentationTest/de/test')
-rw-r--r--src/instrumentationTest/de/test/antennapod/util/ConverterTest.java35
-rw-r--r--src/instrumentationTest/de/test/antennapod/util/playback/TimelineTest.java96
2 files changed, 131 insertions, 0 deletions
diff --git a/src/instrumentationTest/de/test/antennapod/util/ConverterTest.java b/src/instrumentationTest/de/test/antennapod/util/ConverterTest.java
new file mode 100644
index 000000000..8e5674b06
--- /dev/null
+++ b/src/instrumentationTest/de/test/antennapod/util/ConverterTest.java
@@ -0,0 +1,35 @@
+package instrumentationTest.de.test.antennapod.util;
+
+import android.test.AndroidTestCase;
+
+import de.danoeh.antennapod.util.Converter;
+
+/**
+ * Test class for converter
+ */
+public class ConverterTest extends AndroidTestCase {
+
+ public void testGetDurationStringLong() throws Exception {
+ String expected = "13:05:10";
+ int input = 47110000;
+ assertEquals(expected, Converter.getDurationStringLong(input));
+ }
+
+ public void testGetDurationStringShort() throws Exception {
+ String expected = "13:05";
+ int input = 47110000;
+ assertEquals(expected, Converter.getDurationStringShort(input));
+ }
+
+ public void testDurationStringLongToMs() throws Exception {
+ String input = "01:20:30";
+ long expected = 4830000;
+ assertEquals(expected, Converter.durationStringLongToMs(input));
+ }
+
+ public void testDurationStringShortToMs() throws Exception {
+ String input = "8:30";
+ long expected = 30600000;
+ assertEquals(expected, Converter.durationStringShortToMs(input));
+ }
+}
diff --git a/src/instrumentationTest/de/test/antennapod/util/playback/TimelineTest.java b/src/instrumentationTest/de/test/antennapod/util/playback/TimelineTest.java
new file mode 100644
index 000000000..a89be210e
--- /dev/null
+++ b/src/instrumentationTest/de/test/antennapod/util/playback/TimelineTest.java
@@ -0,0 +1,96 @@
+package instrumentationTest.de.test.antennapod.util.playback;
+
+import android.content.Context;
+import android.test.InstrumentationTestCase;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import java.util.Date;
+import java.util.List;
+
+import de.danoeh.antennapod.feed.Chapter;
+import de.danoeh.antennapod.feed.FeedItem;
+import de.danoeh.antennapod.feed.FeedMedia;
+import de.danoeh.antennapod.util.playback.Playable;
+import de.danoeh.antennapod.util.playback.Timeline;
+
+/**
+ * Test class for timeline
+ */
+public class TimelineTest extends InstrumentationTestCase {
+
+ private Context context;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ context = getInstrumentation().getTargetContext();
+ }
+
+ private Playable newTestPlayable(List<Chapter> chapters, String shownotes) {
+ FeedItem item = new FeedItem(0, "Item", "item-id", "http://example.com/item", new Date(), true, null);
+ item.setChapters(chapters);
+ item.setContentEncoded(shownotes);
+ FeedMedia media = new FeedMedia(item, "http://example.com/episode", 100, "audio/mp3");
+ item.setMedia(media);
+ return media;
+ }
+
+ public void testProcessShownotesAddTimecodeHHMMSSNoChapters() throws Exception {
+ final String timeStr = "10:11:12";
+ final long time = 3600 * 1000 * 10 + 60 * 1000 * 11 + 12 * 1000;
+
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>");
+ Timeline t = new Timeline(context, p);
+ String res = t.processShownotes(true);
+ checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
+ }
+
+ public void testProcessShownotesAddTimecodeHHMMNoChapters() throws Exception {
+ final String timeStr = "10:11";
+ final long time = 3600 * 1000 * 10 + 60 * 1000 * 11;
+
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>");
+ Timeline t = new Timeline(context, p);
+ String res = t.processShownotes(true);
+ checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
+ }
+
+ private void checkLinkCorrect(String res, long[] timecodes, String[] timecodeStr) {
+ assertNotNull(res);
+ Document d = Jsoup.parse(res);
+ Elements links = d.body().getElementsByTag("a");
+ int countedLinks = 0;
+ for (Element link : links) {
+ String href = link.attributes().get("href");
+ String text = link.text();
+ if (href.startsWith("antennapod://")) {
+ assertTrue(href.endsWith(String.valueOf(timecodes[countedLinks])));
+ assertEquals(timecodeStr[countedLinks], text);
+ countedLinks++;
+ assertTrue("Contains too many links: " + countedLinks + " > " + timecodes.length, countedLinks <= timecodes.length);
+ }
+ }
+ assertEquals(timecodes.length, countedLinks);
+ }
+
+ public void testIsTimecodeLink() throws Exception {
+ assertFalse(Timeline.isTimecodeLink(null));
+ assertFalse(Timeline.isTimecodeLink("http://antennapod/timecode/123123"));
+ assertFalse(Timeline.isTimecodeLink("antennapod://timecode/"));
+ assertFalse(Timeline.isTimecodeLink("antennapod://123123"));
+ assertFalse(Timeline.isTimecodeLink("antennapod://timecode/123123a"));
+ assertTrue(Timeline.isTimecodeLink("antennapod://timecode/123"));
+ assertTrue(Timeline.isTimecodeLink("antennapod://timecode/1"));
+ }
+
+ public void testGetTimecodeLinkTime() throws Exception {
+ assertEquals(-1, Timeline.getTimecodeLinkTime(null));
+ assertEquals(-1, Timeline.getTimecodeLinkTime("http://timecode/123"));
+ assertEquals(123, Timeline.getTimecodeLinkTime("antennapod://timecode/123"));
+
+ }
+}