diff options
author | Nathan Mascitelli <mascitelli.nathan@gmail.com> | 2019-02-12 19:43:57 -0500 |
---|---|---|
committer | Nathan Mascitelli <mascitelli.nathan@gmail.com> | 2019-02-12 19:43:57 -0500 |
commit | 39b9df50642dae9ac4129f22721093a6ce43148b (patch) | |
tree | fd3a7c565c300d64d35d6bbd142bb8fcc7ef5223 /app | |
parent | d0f617880cda8bacfc70610d5ef04a6c8805a74b (diff) | |
download | AntennaPod-39b9df50642dae9ac4129f22721093a6ce43148b.zip |
Timecode parsing logic now handles two short formats
We now handle both HH:MM and MM:SS when paring timecodes. We will move
in reverse order (assuming that the timecodes will increase over the
course of the document) and parse short codes as HH:MM. When we get a
result that does not fit into the duration we will change to parse as
MM:SS and use that for the rest of the document.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java b/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java index 40e6605d7..dcec1c61f 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java +++ b/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java @@ -30,12 +30,12 @@ public class TimelineTest extends InstrumentationTestCase { context = getInstrumentation().getTargetContext(); } - private Playable newTestPlayable(List<Chapter> chapters, String shownotes) { + private Playable newTestPlayable(List<Chapter> chapters, String shownotes, int duration) { FeedItem item = new FeedItem(0, "Item", "item-id", "http://example.com/item", new Date(), FeedItem.PLAYED, null); item.setChapters(chapters); item.setContentEncoded(shownotes); FeedMedia media = new FeedMedia(item, "http://example.com/episode", 100, "audio/mp3"); - media.setDuration(Integer.MAX_VALUE); + media.setDuration(duration); item.setMedia(media); return media; } @@ -44,7 +44,27 @@ public class TimelineTest extends InstrumentationTestCase { 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>"); + Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE); + 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>", Integer.MAX_VALUE); + Timeline t = new Timeline(context, p); + String res = t.processShownotes(true); + checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); + } + + public void testProcessShownotesAddTimecodeMMSSNoChapters() throws Exception { + final String timeStr = "10:11"; + final long time = 10 * 60 * 1000 + 11 * 1000; + + Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", 11 * 60 * 1000); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); @@ -54,7 +74,7 @@ public class TimelineTest extends InstrumentationTestCase { final String timeStr = "2:11:12"; final long time = 2 * 60 * 60 * 1000 + 11 * 60 * 1000 + 12 * 1000; - Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>"); + Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); @@ -64,47 +84,55 @@ public class TimelineTest extends InstrumentationTestCase { final String timeStr = "1:12"; final long time = 60 * 1000 + 12 * 1000; - Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>"); + Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", 2 * 60 * 1000); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); } - public void testProcessShownotesAddTimecodeMMSSNoChapters() throws Exception { - final String timeStr = "10:11"; - final long time = 60 * 1000 * 10 + 1000 * 11; + public void testProcessShownotesAddTimecodeMultipleFormatsNoChapters() throws Exception { + final String[] timeStrings = new String[]{ "10:12", "1:10:12" }; - Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>"); + Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 2 * 60 * 60 * 1000); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); - checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); + checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000, 60 * 60 * 1000 + 10 * 60 * 1000 + 12 * 1000 }, timeStrings); + } + + public void testProcessShownotesAddTimecodeMultipleShortFormatNoChapters() throws Exception { + final String[] timeStrings = new String[]{ "10:12", "2:12" }; + + Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 3 * 60 * 60 * 1000); + Timeline t = new Timeline(context, p); + String res = t.processShownotes(true); + checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000, 2 * 60 * 60 * 1000 + 12 * 60 * 1000 }, timeStrings); } public void testProcessShownotesAddTimecodeParentheses() throws Exception { - final String timeStr = "10:11:00"; + 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>"); + Playable p = newTestPlayable(null, "<p> Some test text with a timecode (" + timeStr + ") here.</p>", Integer.MAX_VALUE); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); } public void testProcessShownotesAddTimecodeBrackets() throws Exception { - final String timeStr = "10:11:00"; + 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>"); + Playable p = newTestPlayable(null, "<p> Some test text with a timecode [" + timeStr + "] here.</p>", Integer.MAX_VALUE); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); } public void testProcessShownotesAddTimecodeAngleBrackets() throws Exception { - final String timeStr = "10:11:00"; + 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>"); + Playable p = newTestPlayable(null, "<p> Some test text with a timecode <" + timeStr + "> here.</p>", Integer.MAX_VALUE); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); |