[Test] Add stream metadata tests
This commit is contained in:
parent
a087b092b4
commit
6127826571
5 changed files with 91 additions and 2 deletions
|
@ -2,6 +2,8 @@ package org.schabi.newpipe.extractor;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -10,6 +12,7 @@ import javax.annotation.Nullable;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ExtractorAsserts {
|
public class ExtractorAsserts {
|
||||||
|
@ -64,4 +67,18 @@ public class ExtractorAsserts {
|
||||||
public static void assertAtLeast(long expected, long actual) {
|
public static void assertAtLeast(long expected, long actual) {
|
||||||
assertTrue(actual + " is not at least " + expected, actual >= expected);
|
assertTrue(actual + " is not at least " + expected, actual >= expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this assumes that sorting a and b in-place is not an issue, so it's only intended for tests
|
||||||
|
public static void assertEqualsOrderIndependent(List<String> expected, List<String> actual) {
|
||||||
|
if (expected == null) {
|
||||||
|
assertNull(actual);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
assertNotNull(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(expected);
|
||||||
|
Collections.sort(actual);
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,11 @@ public interface BaseStreamExtractorTest extends BaseExtractorTest {
|
||||||
void testVideoStreams() throws Exception;
|
void testVideoStreams() throws Exception;
|
||||||
void testSubtitles() throws Exception;
|
void testSubtitles() throws Exception;
|
||||||
void testFrames() throws Exception;
|
void testFrames() throws Exception;
|
||||||
|
void testHost() throws Exception;
|
||||||
|
void testPrivacy() throws Exception;
|
||||||
|
void testCategory() throws Exception;
|
||||||
|
void testLicence() throws Exception;
|
||||||
|
void testLanguageInfo() throws Exception;
|
||||||
|
void testTags() throws Exception;
|
||||||
|
void testSupportInfo() throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,9 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -27,6 +29,7 @@ import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertAtLeast;
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertAtLeast;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEqualsOrderIndependent;
|
||||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems;
|
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems;
|
||||||
|
@ -42,7 +45,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
|
||||||
public abstract String expectedUploaderUrl();
|
public abstract String expectedUploaderUrl();
|
||||||
public abstract List<String> expectedDescriptionContains(); // e.g. for full links
|
public abstract List<String> expectedDescriptionContains(); // e.g. for full links
|
||||||
public abstract long expectedLength();
|
public abstract long expectedLength();
|
||||||
public long expectedTimestamp() { return 0; }; // default: there is no timestamp
|
public long expectedTimestamp() { return 0; } // default: there is no timestamp
|
||||||
public abstract long expectedViewCountAtLeast();
|
public abstract long expectedViewCountAtLeast();
|
||||||
@Nullable public abstract String expectedUploadDate(); // format: "yyyy-MM-dd HH:mm:ss.SSS"
|
@Nullable public abstract String expectedUploadDate(); // format: "yyyy-MM-dd HH:mm:ss.SSS"
|
||||||
@Nullable public abstract String expectedTextualUploadDate();
|
@Nullable public abstract String expectedTextualUploadDate();
|
||||||
|
@ -55,6 +58,13 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
|
||||||
public boolean expectedHasAudioStreams() { return true; } // default: there are audio streams
|
public boolean expectedHasAudioStreams() { return true; } // default: there are audio streams
|
||||||
public boolean expectedHasSubtitles() { return true; } // default: there are subtitles streams
|
public boolean expectedHasSubtitles() { return true; } // default: there are subtitles streams
|
||||||
public boolean expectedHasFrames() { return true; } // default: there are frames
|
public boolean expectedHasFrames() { return true; } // default: there are frames
|
||||||
|
public String expectedHost() { return ""; } // default: no host for centralized platforms
|
||||||
|
public String expectedPrivacy() { return ""; } // default: no privacy policy available
|
||||||
|
public String expectedCategory() { return ""; } // default: no category
|
||||||
|
public String expectedLicence() { return ""; } // default: no licence
|
||||||
|
public Locale expectedLanguageInfo() { return null; } // default: no language info available
|
||||||
|
public List<String> expectedTags() { return Collections.emptyList(); } // default: no tags
|
||||||
|
public String expectedSupportInfo() { return ""; } // default: no support info available
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
|
@ -283,4 +293,46 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
|
||||||
assertTrue(frames.isEmpty());
|
assertTrue(frames.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testHost() throws Exception {
|
||||||
|
assertEquals(expectedHost(), extractor().getHost());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testPrivacy() throws Exception {
|
||||||
|
assertEquals(expectedPrivacy(), extractor().getPrivacy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testCategory() throws Exception {
|
||||||
|
assertEquals(expectedCategory(), extractor().getCategory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testLicence() throws Exception {
|
||||||
|
assertEquals(expectedLicence(), extractor().getLicence());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testLanguageInfo() throws Exception {
|
||||||
|
assertEquals(expectedLanguageInfo(), extractor().getLanguageInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testTags() throws Exception {
|
||||||
|
assertEqualsOrderIndependent(expectedTags(), extractor().getTags());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testSupportInfo() throws Exception {
|
||||||
|
assertEquals(expectedSupportInfo(), extractor().getSupportInfo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ public class MediaCCCStreamExtractorTest {
|
||||||
@Override public boolean expectedHasRelatedStreams() { return false; }
|
@Override public boolean expectedHasRelatedStreams() { return false; }
|
||||||
@Override public boolean expectedHasSubtitles() { return false; }
|
@Override public boolean expectedHasSubtitles() { return false; }
|
||||||
@Override public boolean expectedHasFrames() { return false; }
|
@Override public boolean expectedHasFrames() { return false; }
|
||||||
|
@Override public List<String> expectedTags() { return Arrays.asList("gpn18", "105"); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
|
@ -118,6 +119,7 @@ public class MediaCCCStreamExtractorTest {
|
||||||
@Override public boolean expectedHasRelatedStreams() { return false; }
|
@Override public boolean expectedHasRelatedStreams() { return false; }
|
||||||
@Override public boolean expectedHasSubtitles() { return false; }
|
@Override public boolean expectedHasSubtitles() { return false; }
|
||||||
@Override public boolean expectedHasFrames() { return false; }
|
@Override public boolean expectedHasFrames() { return false; }
|
||||||
|
@Override public List<String> expectedTags() { return Arrays.asList("36c3", "10565", "2019", "Security", "Main"); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -84,7 +84,12 @@ public class PeertubeStreamExtractorTest {
|
||||||
@Override public long expectedDislikeCountAtLeast() { return 0; }
|
@Override public long expectedDislikeCountAtLeast() { return 0; }
|
||||||
@Override public boolean expectedHasAudioStreams() { return false; }
|
@Override public boolean expectedHasAudioStreams() { return false; }
|
||||||
@Override public boolean expectedHasFrames() { return false; }
|
@Override public boolean expectedHasFrames() { return false; }
|
||||||
|
@Override public String expectedHost() { return "framatube.org"; }
|
||||||
|
@Override public String expectedPrivacy() { return "Public"; }
|
||||||
|
@Override public String expectedCategory() { return "Science & Technology"; }
|
||||||
|
@Override public String expectedLicence() { return "Attribution - Share Alike"; }
|
||||||
|
@Override public Locale expectedLanguageInfo() { return Locale.forLanguageTag("en"); }
|
||||||
|
@Override public List<String> expectedTags() { return Arrays.asList("framasoft", "peertube"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AgeRestricted extends DefaultStreamExtractorTest {
|
public static class AgeRestricted extends DefaultStreamExtractorTest {
|
||||||
|
@ -136,6 +141,12 @@ public class PeertubeStreamExtractorTest {
|
||||||
@Override public boolean expectedHasAudioStreams() { return false; }
|
@Override public boolean expectedHasAudioStreams() { return false; }
|
||||||
@Override public boolean expectedHasSubtitles() { return false; }
|
@Override public boolean expectedHasSubtitles() { return false; }
|
||||||
@Override public boolean expectedHasFrames() { return false; }
|
@Override public boolean expectedHasFrames() { return false; }
|
||||||
|
@Override public String expectedHost() { return "peertube.iriseden.eu"; }
|
||||||
|
@Override public String expectedPrivacy() { return "Public"; }
|
||||||
|
@Override public String expectedCategory() { return "News & Politics"; }
|
||||||
|
@Override public String expectedLicence() { return "Attribution - Share Alike"; }
|
||||||
|
@Override public Locale expectedLanguageInfo() { return Locale.forLanguageTag("ru"); }
|
||||||
|
@Override public List<String> expectedTags() { return Arrays.asList("ДНР", "ЛНР", "Кремль", "Новороссия", "ФСБ"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue