[Test] Add stream metadata tests

This commit is contained in:
Stypox 2020-05-16 20:07:12 +02:00
parent a087b092b4
commit 6127826571
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
5 changed files with 91 additions and 2 deletions

View File

@ -2,6 +2,8 @@ package org.schabi.newpipe.extractor;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.annotation.Nonnull;
@ -10,6 +12,7 @@ import javax.annotation.Nullable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class ExtractorAsserts {
@ -64,4 +67,18 @@ public class ExtractorAsserts {
public static void assertAtLeast(long expected, long actual) {
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);
}
}

View File

@ -21,4 +21,11 @@ public interface BaseStreamExtractorTest extends BaseExtractorTest {
void testVideoStreams() throws Exception;
void testSubtitles() 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;
}

View File

@ -14,7 +14,9 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
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.assertTrue;
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.assertIsValidUrl;
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 List<String> expectedDescriptionContains(); // e.g. for full links
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();
@Nullable public abstract String expectedUploadDate(); // format: "yyyy-MM-dd HH:mm:ss.SSS"
@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 expectedHasSubtitles() { return true; } // default: there are subtitles streams
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
@Override
@ -283,4 +293,46 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
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());
}
}

View File

@ -56,6 +56,7 @@ public class MediaCCCStreamExtractorTest {
@Override public boolean expectedHasRelatedStreams() { return false; }
@Override public boolean expectedHasSubtitles() { return false; }
@Override public boolean expectedHasFrames() { return false; }
@Override public List<String> expectedTags() { return Arrays.asList("gpn18", "105"); }
@Override
@Test
@ -118,6 +119,7 @@ public class MediaCCCStreamExtractorTest {
@Override public boolean expectedHasRelatedStreams() { return false; }
@Override public boolean expectedHasSubtitles() { return false; }
@Override public boolean expectedHasFrames() { return false; }
@Override public List<String> expectedTags() { return Arrays.asList("36c3", "10565", "2019", "Security", "Main"); }
@Override
@Test

View File

@ -84,7 +84,12 @@ public class PeertubeStreamExtractorTest {
@Override public long expectedDislikeCountAtLeast() { return 0; }
@Override public boolean expectedHasAudioStreams() { 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 {
@ -136,6 +141,12 @@ public class PeertubeStreamExtractorTest {
@Override public boolean expectedHasAudioStreams() { return false; }
@Override public boolean expectedHasSubtitles() { 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("ДНР", "ЛНР", "Кремль", "Новороссия", "ФСБ"); }
}