From 9180be85ba216e501b6ccfac9f9eba20d40d0021 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Sun, 10 Feb 2019 17:59:40 -0500 Subject: Update tests to handle minute timestamps The definition of 'short timestamp' now means minutes and seconds, while 'long timestamp' means hours, minutes, and seconds. The first part of a timestamp may have one or two digits. Tests updated for this new definition. --- .../de/test/antennapod/util/ConverterTest.java | 4 +-- .../antennapod/util/playback/TimelineTest.java | 30 ++++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'app/src/androidTest') diff --git a/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java b/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java index 47fca41ba..c7ed7d812 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java +++ b/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java @@ -17,7 +17,7 @@ public class ConverterTest extends AndroidTestCase { public void testGetDurationStringShort() throws Exception { String expected = "13:05"; - int input = 47110000; + int input = 785000; assertEquals(expected, Converter.getDurationStringShort(input)); } @@ -29,7 +29,7 @@ public class ConverterTest extends AndroidTestCase { public void testDurationStringShortToMs() throws Exception { String input = "8:30"; - long expected = 30600000; + long expected = 510000; assertEquals(expected, Converter.durationStringShortToMs(input)); } } 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 7e535e12c..40e6605d7 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 @@ -50,9 +50,29 @@ public class TimelineTest extends InstrumentationTestCase { checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); } - public void testProcessShownotesAddTimecodeHHMMNoChapters() throws Exception { + public void testProcessShownotesAddTimecodeHMMSSNoChapters() throws Exception { + final String timeStr = "2:11:12"; + final long time = 2 * 60 * 60 * 1000 + 11 * 60 * 1000 + 12 * 1000; + + Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStr + " here.

"); + Timeline t = new Timeline(context, p); + String res = t.processShownotes(true); + checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); + } + + public void testProcessShownotesAddTimecodeMSSNoChapters() throws Exception { + final String timeStr = "1:12"; + final long time = 60 * 1000 + 12 * 1000; + + Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStr + " here.

"); + 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 = 3600 * 1000 * 10 + 60 * 1000 * 11; + final long time = 60 * 1000 * 10 + 1000 * 11; Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStr + " here.

"); Timeline t = new Timeline(context, p); @@ -61,7 +81,7 @@ public class TimelineTest extends InstrumentationTestCase { } public void testProcessShownotesAddTimecodeParentheses() throws Exception { - final String timeStr = "10:11"; + final String timeStr = "10:11:00"; final long time = 3600 * 1000 * 10 + 60 * 1000 * 11; Playable p = newTestPlayable(null, "

Some test text with a timecode (" + timeStr + ") here.

"); @@ -71,7 +91,7 @@ public class TimelineTest extends InstrumentationTestCase { } public void testProcessShownotesAddTimecodeBrackets() throws Exception { - final String timeStr = "10:11"; + final String timeStr = "10:11:00"; final long time = 3600 * 1000 * 10 + 60 * 1000 * 11; Playable p = newTestPlayable(null, "

Some test text with a timecode [" + timeStr + "] here.

"); @@ -81,7 +101,7 @@ public class TimelineTest extends InstrumentationTestCase { } public void testProcessShownotesAddTimecodeAngleBrackets() throws Exception { - final String timeStr = "10:11"; + final String timeStr = "10:11:00"; final long time = 3600 * 1000 * 10 + 60 * 1000 * 11; Playable p = newTestPlayable(null, "

Some test text with a timecode <" + timeStr + "> here.

"); -- cgit v1.2.3 From d0f617880cda8bacfc70610d5ef04a6c8805a74b Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Tue, 12 Feb 2019 17:32:58 -0500 Subject: Converter handles HH:MM and MM:SS --- .../androidTest/java/de/test/antennapod/util/ConverterTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/src/androidTest') diff --git a/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java b/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java index c7ed7d812..cd1a489d8 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java +++ b/app/src/androidTest/java/de/test/antennapod/util/ConverterTest.java @@ -17,8 +17,8 @@ public class ConverterTest extends AndroidTestCase { public void testGetDurationStringShort() throws Exception { String expected = "13:05"; - int input = 785000; - assertEquals(expected, Converter.getDurationStringShort(input)); + assertEquals(expected, Converter.getDurationStringShort(47110000, true)); + assertEquals(expected, Converter.getDurationStringShort(785000, false)); } public void testDurationStringLongToMs() throws Exception { @@ -29,7 +29,7 @@ public class ConverterTest extends AndroidTestCase { public void testDurationStringShortToMs() throws Exception { String input = "8:30"; - long expected = 510000; - assertEquals(expected, Converter.durationStringShortToMs(input)); + assertEquals(30600000, Converter.durationStringShortToMs(input, true)); + assertEquals(510000, Converter.durationStringShortToMs(input, false)); } } -- cgit v1.2.3 From 39b9df50642dae9ac4129f22721093a6ce43148b Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Tue, 12 Feb 2019 19:43:57 -0500 Subject: 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. --- .../antennapod/util/playback/TimelineTest.java | 60 ++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) (limited to 'app/src/androidTest') 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 chapters, String shownotes) { + private Playable newTestPlayable(List 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, "

Some test text with a timecode " + timeStr + " here.

"); + Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStr + " here.

", 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, "

Some test text with a timecode " + timeStr + " here.

", 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, "

Some test text with a timecode " + timeStr + " here.

", 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, "

Some test text with a timecode " + timeStr + " here.

"); + Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStr + " here.

", 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, "

Some test text with a timecode " + timeStr + " here.

"); + Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStr + " here.

", 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, "

Some test text with a timecode " + timeStr + " here.

"); + Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!

", 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, "

Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!

", 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, "

Some test text with a timecode (" + timeStr + ") here.

"); + Playable p = newTestPlayable(null, "

Some test text with a timecode (" + timeStr + ") here.

", 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, "

Some test text with a timecode [" + timeStr + "] here.

"); + Playable p = newTestPlayable(null, "

Some test text with a timecode [" + timeStr + "] here.

", 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, "

Some test text with a timecode <" + timeStr + "> here.

"); + Playable p = newTestPlayable(null, "

Some test text with a timecode <" + timeStr + "> here.

", Integer.MAX_VALUE); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); -- cgit v1.2.3 From c49e98b5462c9511dffe250a94b17be637884c49 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Tue, 12 Feb 2019 20:53:17 -0500 Subject: Handle more then 23 hours --- .../java/de/test/antennapod/util/playback/TimelineTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/src/androidTest') 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 dcec1c61f..157773595 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 @@ -50,6 +50,16 @@ public class TimelineTest extends InstrumentationTestCase { checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); } + public void testProcessShownotesAddTimecodeHHMMSSMoreThen24HoursNoChapters() throws Exception { + final String timeStr = "25:00:00"; + final long time = 25 * 60 * 60 * 1000; + + Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStr + " here.

", 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; -- cgit v1.2.3 From e94e4bc3d03d2e6d5122700fd3161bfa63dc4371 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Wed, 13 Feb 2019 21:06:19 -0500 Subject: Use a single format for short timecodes It is unlikely that multiple formats for short timecodes would be used in one document. Therefor we will parse all the short timecodes to see if they are all less then the duration as HH:MM. If they are we will use that, otherwise we will parse them as MM:SS. --- .../java/de/test/antennapod/util/playback/TimelineTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/src/androidTest') 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 157773595..e6b11a4b0 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 @@ -110,12 +110,14 @@ public class TimelineTest extends InstrumentationTestCase { } public void testProcessShownotesAddTimecodeMultipleShortFormatNoChapters() throws Exception { + + // One of these timecodes fits as HH:MM and one does not so both should be parsed as MM:SS. final String[] timeStrings = new String[]{ "10:12", "2:12" }; Playable p = newTestPlayable(null, "

Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!

", 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); + checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000, 2 * 60 * 1000 + 12 * 1000 }, timeStrings); } public void testProcessShownotesAddTimecodeParentheses() throws Exception { -- cgit v1.2.3 From 6f69b4b1403f2ca4a7fd1125d145bf13252c3732 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Sat, 2 Mar 2019 08:47:52 -0500 Subject: Adjust regext to ignore X:Y timecodes --- .../java/de/test/antennapod/util/playback/TimelineTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/src/androidTest') 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 e6b11a4b0..c88c06a95 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 @@ -150,6 +150,15 @@ public class TimelineTest extends InstrumentationTestCase { checkLinkCorrect(res, new long[]{time}, new String[]{timeStr}); } + public void testProcessShownotesAndInvalidTimecode() throws Exception { + final String timeStr = "2:1"; + + Playable p = newTestPlayable(null, "

Some test text with a timecode <" + timeStr + "> here.

", Integer.MAX_VALUE); + Timeline t = new Timeline(context, p); + String res = t.processShownotes(true); + checkLinkCorrect(res, new long[0], new String[0]); + } + private void checkLinkCorrect(String res, long[] timecodes, String[] timecodeStr) { assertNotNull(res); Document d = Jsoup.parse(res); -- cgit v1.2.3 From 7e3ccd97da53108b8c5cec06cc0ae42454cdf42e Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Sat, 2 Mar 2019 12:12:26 -0500 Subject: Fix regex --- .../java/de/test/antennapod/util/playback/TimelineTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/src/androidTest') 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 c88c06a95..4bef14cd9 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 @@ -151,9 +151,15 @@ public class TimelineTest extends InstrumentationTestCase { } public void testProcessShownotesAndInvalidTimecode() throws Exception { - final String timeStr = "2:1"; + final String[] timeStrs = new String[] {"2:1", "0:0", "000", "00", "00:000"}; - Playable p = newTestPlayable(null, "

Some test text with a timecode <" + timeStr + "> here.

", Integer.MAX_VALUE); + StringBuilder shownotes = new StringBuilder("

Some test text with timecodes "); + for (String timeStr : timeStrs) { + shownotes.append(timeStr).append(" "); + } + shownotes.append("here.

"); + + Playable p = newTestPlayable(null, shownotes.toString(), Integer.MAX_VALUE); Timeline t = new Timeline(context, p); String res = t.processShownotes(true); checkLinkCorrect(res, new long[0], new String[0]); -- cgit v1.2.3