Add option to FakeTrackOutput to de-duplicate repeated formats
Expose this through ExtractorAsserts via a new AssertionConfig object PiperOrigin-RevId: 308980701
This commit is contained in:
parent
625c734726
commit
922b8a2c15
@ -38,18 +38,18 @@ public final class AmrExtractorParameterizedTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void extractingNarrowBandSamples() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_nb.amr", assertionConfig);
|
||||
createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_nb.amr", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractingWideBandSamples() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_wb.amr", assertionConfig);
|
||||
createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_wb.amr", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -57,7 +57,7 @@ public final class AmrExtractorParameterizedTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
createAmrExtractorFactory(/* withSeeking= */ true),
|
||||
"amr/sample_nb_cbr.amr",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -65,7 +65,7 @@ public final class AmrExtractorParameterizedTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
createAmrExtractorFactory(/* withSeeking= */ true),
|
||||
"amr/sample_wb_cbr.amr",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.google.android.exoplayer2.extractor.flac;
|
||||
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.AssertionConfig;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -33,95 +34,107 @@ public class FlacExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_flac");
|
||||
"flac/bear.flac",
|
||||
new AssertionConfig.Builder().setDumpFilesPrefix("flac/bear_flac").build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithId3HeaderAndId3Enabled() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_with_id3.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_with_id3_enabled_flac");
|
||||
"flac/bear_with_id3.flac",
|
||||
new AssertionConfig.Builder().setDumpFilesPrefix("flac/bear_with_id3_enabled_flac").build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithId3HeaderAndId3Disabled() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA),
|
||||
/* file= */ "flac/bear_with_id3.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_with_id3_disabled_flac");
|
||||
"flac/bear_with_id3.flac",
|
||||
new AssertionConfig.Builder()
|
||||
.setDumpFilesPrefix("flac/bear_with_id3_disabled_flac")
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleUnseekable() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_no_seek_table_no_num_samples.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_no_seek_table_no_num_samples_flac");
|
||||
"flac/bear_no_seek_table_no_num_samples.flac",
|
||||
new AssertionConfig.Builder()
|
||||
.setDumpFilesPrefix("flac/bear_no_seek_table_no_num_samples_flac")
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithVorbisComments() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_with_vorbis_comments.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_with_vorbis_comments_flac");
|
||||
"flac/bear_with_vorbis_comments.flac",
|
||||
new AssertionConfig.Builder()
|
||||
.setDumpFilesPrefix("flac/bear_with_vorbis_comments_flac")
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithPicture() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_with_picture.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_with_picture_flac");
|
||||
"flac/bear_with_picture.flac",
|
||||
new AssertionConfig.Builder().setDumpFilesPrefix("flac/bear_with_picture_flac").build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneMetadataBlock() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_one_metadata_block.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_one_metadata_block_flac");
|
||||
"flac/bear_one_metadata_block.flac",
|
||||
new AssertionConfig.Builder()
|
||||
.setDumpFilesPrefix("flac/bear_one_metadata_block_flac")
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noMinMaxFrameSize() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_no_min_max_frame_size.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_no_min_max_frame_size_flac");
|
||||
"flac/bear_no_min_max_frame_size.flac",
|
||||
new AssertionConfig.Builder()
|
||||
.setDumpFilesPrefix("flac/bear_no_min_max_frame_size_flac")
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noNumSamples() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_no_num_samples.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_no_num_samples_flac");
|
||||
"flac/bear_no_num_samples.flac",
|
||||
new AssertionConfig.Builder().setDumpFilesPrefix("flac/bear_no_num_samples_flac").build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uncommonSampleRate() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
FlacExtractor::new,
|
||||
/* file= */ "flac/bear_uncommon_sample_rate.flac",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "flac/bear_uncommon_sample_rate_flac");
|
||||
"flac/bear_uncommon_sample_rate.flac",
|
||||
new AssertionConfig.Builder()
|
||||
.setDumpFilesPrefix("flac/bear_uncommon_sample_rate_flac")
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ public final class FlvExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(FlvExtractor::new, "flv/sample.flv", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(FlvExtractor::new, "flv/sample.flv", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -33,39 +33,40 @@ public final class MatroskaExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void mkvSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(MatroskaExtractor::new, "mkv/sample.mkv", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(MatroskaExtractor::new, "mkv/sample.mkv", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkvSample_withSubripSubtitles() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
MatroskaExtractor::new, "mkv/sample_with_srt.mkv", assertionConfig);
|
||||
MatroskaExtractor::new, "mkv/sample_with_srt.mkv", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkvSample_withHtcRotationInfoInTrackName() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
MatroskaExtractor::new, "mkv/sample_with_htc_rotation_track_name.mkv", assertionConfig);
|
||||
MatroskaExtractor::new, "mkv/sample_with_htc_rotation_track_name.mkv", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkvFullBlocksSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(MatroskaExtractor::new, "mkv/full_blocks.mkv", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(
|
||||
MatroskaExtractor::new, "mkv/full_blocks.mkv", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webmSubsampleEncryption() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
MatroskaExtractor::new, "mkv/subsample_encrypted_noaltref.webm", assertionConfig);
|
||||
MatroskaExtractor::new, "mkv/subsample_encrypted_noaltref.webm", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webmSubsampleEncryptionWithAltrefFrames() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
MatroskaExtractor::new, "mkv/subsample_encrypted_altref.webm", assertionConfig);
|
||||
MatroskaExtractor::new, "mkv/subsample_encrypted_altref.webm", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.google.android.exoplayer2.extractor.mp3;
|
||||
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.AssertionConfig;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -33,18 +34,18 @@ public final class Mp3ExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void mp3SampleWithXingHeader() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
Mp3Extractor::new, "mp3/bear-vbr-xing-header.mp3", assertionConfig);
|
||||
Mp3Extractor::new, "mp3/bear-vbr-xing-header.mp3", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp3SampleWithCbrSeeker() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
Mp3Extractor::new, "mp3/bear-cbr-variable-frame-size-no-seek-table.mp3", assertionConfig);
|
||||
Mp3Extractor::new, "mp3/bear-cbr-variable-frame-size-no-seek-table.mp3", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -52,29 +53,29 @@ public final class Mp3ExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new Mp3Extractor(Mp3Extractor.FLAG_ENABLE_INDEX_SEEKING),
|
||||
"mp3/bear-vbr-no-seek-table.mp3",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trimmedMp3Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Mp3Extractor::new, "mp3/play-trimmed.mp3", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Mp3Extractor::new, "mp3/play-trimmed.mp3", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp3SampleWithId3Enabled() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
Mp3Extractor::new,
|
||||
/* file= */ "mp3/bear-id3.mp3",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "mp3/bear-id3-enabled");
|
||||
"mp3/bear-id3.mp3",
|
||||
new AssertionConfig.Builder().setDumpFilesPrefix("mp3/bear-id3-enabled").build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp3SampleWithId3Disabled() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new Mp3Extractor(Mp3Extractor.FLAG_DISABLE_ID3_METADATA),
|
||||
/* file= */ "mp3/bear-id3.mp3",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "mp3/bear-id3-disabled");
|
||||
"mp3/bear-id3.mp3",
|
||||
new AssertionConfig.Builder().setDumpFilesPrefix("mp3/bear-id3-disabled").build(),
|
||||
simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ public final class FragmentedMp4ExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_fragmented.mp4", assertionConfig);
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_fragmented.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -51,7 +51,7 @@ public final class FragmentedMp4ExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
getExtractorFactory(ImmutableList.of()),
|
||||
"mp4/sample_fragmented_seekable.mp4",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -62,31 +62,33 @@ public final class FragmentedMp4ExtractorTest {
|
||||
Collections.singletonList(
|
||||
new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_CEA608).build()));
|
||||
ExtractorAsserts.assertBehavior(
|
||||
extractorFactory, "mp4/sample_fragmented_sei.mp4", assertionConfig);
|
||||
extractorFactory, "mp4/sample_fragmented_sei.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithAc3Track() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_ac3_fragmented.mp4", assertionConfig);
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_ac3_fragmented.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithAc4Track() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_ac4_fragmented.mp4", assertionConfig);
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_ac4_fragmented.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithProtectedAc4Track() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_ac4_protected.mp4", assertionConfig);
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_ac4_protected.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithEac3Track() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
getExtractorFactory(ImmutableList.of()), "mp4/sample_eac3_fragmented.mp4", assertionConfig);
|
||||
getExtractorFactory(ImmutableList.of()),
|
||||
"mp4/sample_eac3_fragmented.mp4",
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,7 +96,7 @@ public final class FragmentedMp4ExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
getExtractorFactory(ImmutableList.of()),
|
||||
"mp4/sample_eac3joc_fragmented.mp4",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
private static ExtractorFactory getExtractorFactory(final List<Format> closedCaptionFormats) {
|
||||
|
@ -33,17 +33,17 @@ public final class Mp4ExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void mp4Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample.mp4", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp4SampleWithSlowMotionMetadata() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
Mp4Extractor::new, "mp4/sample_android_slow_motion.mp4", assertionConfig);
|
||||
Mp4Extractor::new, "mp4/sample_android_slow_motion.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,26 +53,26 @@ public final class Mp4ExtractorTest {
|
||||
@Test
|
||||
public void mp4SampleWithMdatTooLong() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
Mp4Extractor::new, "mp4/sample_mdat_too_long.mp4", assertionConfig);
|
||||
Mp4Extractor::new, "mp4/sample_mdat_too_long.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp4SampleWithAc3Track() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_ac3.mp4", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_ac3.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp4SampleWithAc4Track() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_ac4.mp4", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_ac4.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp4SampleWithEac3Track() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_eac3.mp4", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_eac3.mp4", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp4SampleWithEac3jocTrack() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_eac3joc.mp4", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Mp4Extractor::new, "mp4/sample_eac3joc.mp4", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -37,26 +37,26 @@ public final class OggExtractorParameterizedTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void opus() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear.opus", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear.opus", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flac() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_flac.ogg", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_flac.ogg", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flacNoSeektable() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
OggExtractor::new, "ogg/bear_flac_noseektable.ogg", assertionConfig);
|
||||
OggExtractor::new, "ogg/bear_flac_noseektable.ogg", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vorbis() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_vorbis.ogg", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_vorbis.ogg", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public final class RawCcExtractorTest {
|
||||
}
|
||||
|
||||
@ParameterizedRobolectricTestRunner.Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void rawCcSample() throws Exception {
|
||||
@ -44,6 +44,6 @@ public final class RawCcExtractorTest {
|
||||
.setAccessibilityChannel(1)
|
||||
.build();
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new RawCcExtractor(format), "rawcc/sample.rawcc", assertionConfig);
|
||||
() -> new RawCcExtractor(format), "rawcc/sample.rawcc", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -33,20 +33,20 @@ public final class Ac3ExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void ac3Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Ac3Extractor::new, "ts/sample.ac3", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Ac3Extractor::new, "ts/sample.ac3", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eAc3Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Ac3Extractor::new, "ts/sample.eac3", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Ac3Extractor::new, "ts/sample.eac3", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eAc3jocSample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Ac3Extractor::new, "ts/sample_eac3joc.ec3", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Ac3Extractor::new, "ts/sample_eac3joc.ec3", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ public final class Ac4ExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void ac4Sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(Ac4Extractor::new, "ts/sample.ac4", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(Ac4Extractor::new, "ts/sample.ac4", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -33,16 +33,17 @@ public final class AdtsExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(AdtsExtractor::new, "ts/sample.adts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(AdtsExtractor::new, "ts/sample.adts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sample_with_id3() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(AdtsExtractor::new, "ts/sample_with_id3.adts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(
|
||||
AdtsExtractor::new, "ts/sample_with_id3.adts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -50,7 +51,7 @@ public final class AdtsExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new AdtsExtractor(/* flags= */ AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING),
|
||||
"ts/sample_cbs.adts",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
// https://github.com/google/ExoPlayer/issues/6700
|
||||
@ -59,6 +60,6 @@ public final class AdtsExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new AdtsExtractor(/* flags= */ AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING),
|
||||
"ts/sample_cbs_truncated.adts",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -33,16 +33,16 @@ public final class PsExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void sampleWithH262AndMpegAudio() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
PsExtractor::new, "ts/sample_h262_mpeg_audio.ps", assertionConfig);
|
||||
PsExtractor::new, "ts/sample_h262_mpeg_audio.ps", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithAc3() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(PsExtractor::new, "ts/sample_ac3.ps", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(PsExtractor::new, "ts/sample_ac3.ps", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.android.exoplayer2.util.TimestampAdjuster;
|
||||
import java.util.List;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.ParameterizedRobolectricTestRunner;
|
||||
@ -54,18 +53,18 @@ public final class TsExtractorTest {
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void sampleWithH262AndMpegAudio() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
TsExtractor::new, "ts/sample_h262_mpeg_audio.ts", assertionConfig);
|
||||
TsExtractor::new, "ts/sample_h262_mpeg_audio.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithH264AndMpegAudio() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
TsExtractor::new, "ts/sample_h264_mpeg_audio.ts", assertionConfig);
|
||||
TsExtractor::new, "ts/sample_h264_mpeg_audio.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -73,7 +72,7 @@ public final class TsExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new TsExtractor(FLAG_DETECT_ACCESS_UNITS),
|
||||
"ts/sample_h264_no_access_unit_delimiters.ts",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -81,58 +80,64 @@ public final class TsExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
() -> new TsExtractor(DefaultTsPayloadReaderFactory.FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS),
|
||||
"ts/sample_h264_dts_audio.ts",
|
||||
assertionConfig);
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithH265() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_h265.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_h265.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO(internal: b/153539929) Re-enable when ExtractorAsserts is less strict around repeated
|
||||
// formats and seeking.
|
||||
public void sampleWithScte35() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_scte35.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(
|
||||
TsExtractor::new,
|
||||
"ts/sample_scte35.ts",
|
||||
new ExtractorAsserts.AssertionConfig.Builder()
|
||||
.setDeduplicateConsecutiveFormats(true)
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO(internal: b/153539929) Re-enable when ExtractorAsserts is less strict around repeated
|
||||
// formats and seeking.
|
||||
public void sampleWithAit() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_ait.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(
|
||||
TsExtractor::new,
|
||||
"ts/sample_ait.ts",
|
||||
new ExtractorAsserts.AssertionConfig.Builder()
|
||||
.setDeduplicateConsecutiveFormats(true)
|
||||
.build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithAc3() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_ac3.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_ac3.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithAc4() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_ac4.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_ac4.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithEac3() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_eac3.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_eac3.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithEac3joc() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_eac3joc.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_eac3joc.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleWithLatm() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_latm.ts", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_latm.ts", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamWithJunkData() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_with_junk", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_with_junk", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.google.android.exoplayer2.extractor.wav;
|
||||
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts.AssertionConfig;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -31,11 +32,11 @@ public final class WavExtractorTest {
|
||||
}
|
||||
|
||||
@ParameterizedRobolectricTestRunner.Parameter(0)
|
||||
public ExtractorAsserts.Config assertionConfig;
|
||||
public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||
|
||||
@Test
|
||||
public void sample() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(WavExtractor::new, "wav/sample.wav", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(WavExtractor::new, "wav/sample.wav", simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -43,12 +44,13 @@ public final class WavExtractorTest {
|
||||
ExtractorAsserts.assertBehavior(
|
||||
WavExtractor::new,
|
||||
"wav/sample_with_trailing_bytes.wav",
|
||||
assertionConfig,
|
||||
/* dumpFilesPrefix= */ "wav/sample.wav");
|
||||
new AssertionConfig.Builder().setDumpFilesPrefix("wav/sample.wav").build(),
|
||||
simulationConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sample_imaAdpcm() throws Exception {
|
||||
ExtractorAsserts.assertBehavior(WavExtractor::new, "wav/sample_ima_adpcm.wav", assertionConfig);
|
||||
ExtractorAsserts.assertBehavior(
|
||||
WavExtractor::new, "wav/sample_ima_adpcm.wav", simulationConfig);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ track 600:
|
||||
sample count = 3
|
||||
format 0:
|
||||
sampleMimeType = application/x-scte35
|
||||
subsampleOffsetUs = -1400000
|
||||
subsampleOffsetUs = -1377756
|
||||
sample 0:
|
||||
time = 55610
|
||||
flags = 1
|
||||
|
@ -55,7 +55,7 @@ track 600:
|
||||
sample count = 3
|
||||
format 0:
|
||||
sampleMimeType = application/x-scte35
|
||||
subsampleOffsetUs = -1400000
|
||||
subsampleOffsetUs = -1355512
|
||||
sample 0:
|
||||
time = 77854
|
||||
flags = 1
|
||||
|
@ -39,7 +39,7 @@ track 600:
|
||||
sample count = 0
|
||||
format 0:
|
||||
sampleMimeType = application/x-scte35
|
||||
subsampleOffsetUs = -1400000
|
||||
subsampleOffsetUs = -1355512
|
||||
track 8448:
|
||||
total output bytes = 0
|
||||
sample count = 0
|
||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.testutil;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
@ -31,6 +32,7 @@ import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
/**
|
||||
* Assertion methods for {@link Extractor}.
|
||||
@ -38,27 +40,27 @@ import java.util.List;
|
||||
public final class ExtractorAsserts {
|
||||
|
||||
/**
|
||||
* Returns a list of arrays containing {@link Config} objects to exercise different extractor
|
||||
* paths.
|
||||
* Returns a list of arrays containing {@link SimulationConfig} objects to exercise different
|
||||
* extractor paths.
|
||||
*
|
||||
* <p>This is intended to be used from tests using {@code ParameterizedRobolectricTestRunner} or
|
||||
* {@code org.junit.runners.Parameterized}.
|
||||
*/
|
||||
public static List<Object[]> configs() {
|
||||
return Arrays.asList(
|
||||
new Object[] {new Config(true, false, false, false)},
|
||||
new Object[] {new Config(true, false, false, true)},
|
||||
new Object[] {new Config(true, false, true, false)},
|
||||
new Object[] {new Config(true, false, true, true)},
|
||||
new Object[] {new Config(true, true, false, false)},
|
||||
new Object[] {new Config(true, true, false, true)},
|
||||
new Object[] {new Config(true, true, true, false)},
|
||||
new Object[] {new Config(true, true, true, true)},
|
||||
new Object[] {new Config(false, false, false, false)});
|
||||
new Object[] {new SimulationConfig(true, false, false, false)},
|
||||
new Object[] {new SimulationConfig(true, false, false, true)},
|
||||
new Object[] {new SimulationConfig(true, false, true, false)},
|
||||
new Object[] {new SimulationConfig(true, false, true, true)},
|
||||
new Object[] {new SimulationConfig(true, true, false, false)},
|
||||
new Object[] {new SimulationConfig(true, true, false, true)},
|
||||
new Object[] {new SimulationConfig(true, true, true, false)},
|
||||
new Object[] {new SimulationConfig(true, true, true, true)},
|
||||
new Object[] {new SimulationConfig(false, false, false, false)});
|
||||
}
|
||||
|
||||
/** A config of different environments to simulate and extractor behaviour to test. */
|
||||
public static class Config {
|
||||
/** A config of different environments to simulate and extractor behaviours to test. */
|
||||
public static class SimulationConfig {
|
||||
|
||||
/**
|
||||
* Whether to sniff the data by calling {@link Extractor#sniff(ExtractorInput)} prior to
|
||||
@ -72,7 +74,7 @@ public final class ExtractorAsserts {
|
||||
/** Whether to simulate partial reads. */
|
||||
public final boolean simulatePartialReads;
|
||||
|
||||
private Config(
|
||||
private SimulationConfig(
|
||||
boolean sniffFirst,
|
||||
boolean simulateIOErrors,
|
||||
boolean simulateUnknownLength,
|
||||
@ -91,6 +93,49 @@ public final class ExtractorAsserts {
|
||||
}
|
||||
}
|
||||
|
||||
/** A config for the assertions made (e.g. dump file location). */
|
||||
public static class AssertionConfig {
|
||||
|
||||
/**
|
||||
* The prefix prepended to the dump files path. If not set, the path to the source data will be
|
||||
* used.
|
||||
*/
|
||||
@Nullable public final String dumpFilesPrefix;
|
||||
|
||||
/**
|
||||
* Controls how consecutive formats with no intervening samples are handled. If true, only the
|
||||
* last format received is retained. If false, consecutive formats with no samples cause the
|
||||
* test to fail.
|
||||
*/
|
||||
public final boolean deduplicateConsecutiveFormats;
|
||||
|
||||
private AssertionConfig(
|
||||
@Nullable String dumpFilesPrefix, boolean deduplicateConsecutiveFormats) {
|
||||
this.dumpFilesPrefix = dumpFilesPrefix;
|
||||
this.deduplicateConsecutiveFormats = deduplicateConsecutiveFormats;
|
||||
}
|
||||
|
||||
/** Builder for {@link AssertionConfig} instances. */
|
||||
public static class Builder {
|
||||
private @MonotonicNonNull String dumpFilesPrefix;
|
||||
private boolean deduplicateConsecutiveFormats;
|
||||
|
||||
public Builder setDumpFilesPrefix(String dumpFilesPrefix) {
|
||||
this.dumpFilesPrefix = dumpFilesPrefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDeduplicateConsecutiveFormats(boolean deduplicateConsecutiveFormats) {
|
||||
this.deduplicateConsecutiveFormats = deduplicateConsecutiveFormats;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AssertionConfig build() {
|
||||
return new AssertionConfig(dumpFilesPrefix, deduplicateConsecutiveFormats);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A factory for {@link Extractor} instances. */
|
||||
public interface ExtractorFactory {
|
||||
Extractor create();
|
||||
@ -127,7 +172,7 @@ public final class ExtractorAsserts {
|
||||
* <li>Calls {@link Extractor#seek(long, long)} and {@link Extractor#release()} without calling
|
||||
* {@link Extractor#init(ExtractorOutput)} to check these calls do not fail.
|
||||
* <li>Calls {@link #assertOutput(Extractor, String, byte[], Context, boolean, boolean, boolean,
|
||||
* boolean)} with all possible combinations of "simulate" parameters.
|
||||
* boolean, boolean)} with all possible combinations of "simulate" parameters.
|
||||
* </ul>
|
||||
*
|
||||
* @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
|
||||
@ -146,7 +191,7 @@ public final class ExtractorAsserts {
|
||||
* <li>Calls {@link Extractor#seek(long, long)} and {@link Extractor#release()} without calling
|
||||
* {@link Extractor#init(ExtractorOutput)} to check these calls do not fail.
|
||||
* <li>Calls {@link #assertOutput(Extractor, String, byte[], Context, boolean, boolean, boolean,
|
||||
* boolean)} with all possible combinations of "simulate" parameters.
|
||||
* boolean, boolean)} with all possible combinations of "simulate" parameters.
|
||||
* </ul>
|
||||
*
|
||||
* @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
|
||||
@ -169,7 +214,7 @@ public final class ExtractorAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that an extractor consumes valid input data successfully under the conditions specified
|
||||
* by {@code config}.
|
||||
* by {@code simulationConfig}.
|
||||
*
|
||||
* <p>The output of the extractor is compared against prerecorded dump files whose names are
|
||||
* derived from the {@code file} parameter.
|
||||
@ -177,29 +222,29 @@ public final class ExtractorAsserts {
|
||||
* @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
|
||||
* class which is to be tested.
|
||||
* @param file The path to the input sample.
|
||||
* @param config Details on the environment to simulate and behaviours to assert.
|
||||
* @param simulationConfig Details on the environment to simulate and behaviours to assert.
|
||||
* @throws IOException If reading from the input fails.
|
||||
*/
|
||||
public static void assertBehavior(ExtractorFactory factory, String file, Config config)
|
||||
throws IOException {
|
||||
assertBehavior(factory, file, config, file);
|
||||
public static void assertBehavior(
|
||||
ExtractorFactory factory, String file, SimulationConfig simulationConfig) throws IOException {
|
||||
assertBehavior(factory, file, new AssertionConfig.Builder().build(), simulationConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an extractor consumes valid input data successfully successfully under the
|
||||
* conditions specified by {@code config}.
|
||||
* conditions specified by {@code simulationConfig}.
|
||||
*
|
||||
* <p>The output of the extractor is compared against prerecorded dump files.
|
||||
*
|
||||
* @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
|
||||
* class which is to be tested.
|
||||
* @param file The path to the input sample.
|
||||
* @param config Details on the environment to simulate and behaviours to assert.
|
||||
* @param dumpFilesPrefix The dump files prefix prepended to the dump files path.
|
||||
* @param assertionConfig Details of how to read and process the source and dump files.
|
||||
* @param simulationConfig Details on the environment to simulate and behaviours to assert.
|
||||
* @throws IOException If reading from the input fails.
|
||||
*/
|
||||
public static void assertBehavior(
|
||||
ExtractorFactory factory, String file, Config config, String dumpFilesPrefix)
|
||||
ExtractorFactory factory,
|
||||
String file,
|
||||
AssertionConfig assertionConfig,
|
||||
SimulationConfig simulationConfig)
|
||||
throws IOException {
|
||||
// Check behavior prior to initialization.
|
||||
Extractor extractor = factory.create();
|
||||
@ -208,22 +253,25 @@ public final class ExtractorAsserts {
|
||||
// Assert output.
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
byte[] fileData = TestUtil.getByteArray(context, file);
|
||||
String dumpFilesPrefix =
|
||||
assertionConfig.dumpFilesPrefix != null ? assertionConfig.dumpFilesPrefix : file;
|
||||
assertOutput(
|
||||
factory.create(),
|
||||
dumpFilesPrefix,
|
||||
fileData,
|
||||
context,
|
||||
config.sniffFirst,
|
||||
config.simulateIOErrors,
|
||||
config.simulateUnknownLength,
|
||||
config.simulatePartialReads);
|
||||
assertionConfig.deduplicateConsecutiveFormats,
|
||||
simulationConfig.sniffFirst,
|
||||
simulationConfig.simulateIOErrors,
|
||||
simulationConfig.simulateUnknownLength,
|
||||
simulationConfig.simulatePartialReads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link #assertOutput(Extractor, String, byte[], Context, boolean, boolean, boolean,
|
||||
* boolean)} with all possible combinations of "simulate" parameters with {@code sniffFirst} set
|
||||
* to true, and makes one additional call with the "simulate" and {@code sniffFirst} parameters
|
||||
* all set to false.
|
||||
* boolean, boolean)} with all possible combinations of "simulate" parameters with {@code
|
||||
* sniffFirst} set to true, and makes one additional call with the "simulate" and {@code
|
||||
* sniffFirst} parameters all set to false.
|
||||
*
|
||||
* @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
|
||||
* class which is to be tested.
|
||||
@ -235,15 +283,17 @@ public final class ExtractorAsserts {
|
||||
private static void assertOutput(
|
||||
ExtractorFactory factory, String dumpFilesPrefix, byte[] data, Context context)
|
||||
throws IOException {
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, false, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, false, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, true, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, true, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, true, false, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, true, false, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, true, true, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, true, true, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, false, false, false);
|
||||
assertOutput(
|
||||
factory.create(), dumpFilesPrefix, data, context, false, true, false, false, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, true, false, false, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, true, false, true, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, true, false, true, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, true, true, false, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, true, true, false, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, true, true, true, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, false, true, true, true, true);
|
||||
assertOutput(
|
||||
factory.create(), dumpFilesPrefix, data, context, false, false, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,6 +317,7 @@ public final class ExtractorAsserts {
|
||||
String dumpFilesPrefix,
|
||||
byte[] data,
|
||||
Context context,
|
||||
boolean deduplicateConsecutiveFormats,
|
||||
boolean sniffFirst,
|
||||
boolean simulateIOErrors,
|
||||
boolean simulateUnknownLength,
|
||||
@ -282,7 +333,8 @@ public final class ExtractorAsserts {
|
||||
input.resetPeekPosition();
|
||||
}
|
||||
|
||||
FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, 0, true);
|
||||
FakeExtractorOutput extractorOutput =
|
||||
consumeTestData(extractor, input, 0, true, deduplicateConsecutiveFormats);
|
||||
if (simulateUnknownLength) {
|
||||
extractorOutput.assertOutput(context, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
|
||||
} else {
|
||||
@ -323,9 +375,14 @@ public final class ExtractorAsserts {
|
||||
private ExtractorAsserts() {}
|
||||
|
||||
private static FakeExtractorOutput consumeTestData(
|
||||
Extractor extractor, FakeExtractorInput input, long timeUs, boolean retryFromStartIfLive)
|
||||
Extractor extractor,
|
||||
FakeExtractorInput input,
|
||||
long timeUs,
|
||||
boolean retryFromStartIfLive,
|
||||
boolean deduplicateConsecutiveFormats)
|
||||
throws IOException {
|
||||
FakeExtractorOutput output = new FakeExtractorOutput();
|
||||
FakeExtractorOutput output =
|
||||
new FakeExtractorOutput((id, type) -> new FakeTrackOutput(deduplicateConsecutiveFormats));
|
||||
extractor.init(output);
|
||||
consumeTestData(extractor, input, timeUs, output, retryFromStartIfLive);
|
||||
return output;
|
||||
|
@ -68,12 +68,18 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
||||
@DumpFilesAction private static final int DUMP_FILE_ACTION = COMPARE_WITH_EXISTING;
|
||||
|
||||
public final SparseArray<FakeTrackOutput> trackOutputs;
|
||||
private final FakeTrackOutput.Factory trackOutputFactory;
|
||||
|
||||
public int numberOfTracks;
|
||||
public boolean tracksEnded;
|
||||
public @MonotonicNonNull SeekMap seekMap;
|
||||
|
||||
public FakeExtractorOutput() {
|
||||
this(FakeTrackOutput.DEFAULT_FACTORY);
|
||||
}
|
||||
|
||||
public FakeExtractorOutput(FakeTrackOutput.Factory trackOutputFactory) {
|
||||
this.trackOutputFactory = trackOutputFactory;
|
||||
trackOutputs = new SparseArray<>();
|
||||
}
|
||||
|
||||
@ -83,7 +89,7 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
||||
if (output == null) {
|
||||
assertThat(tracksEnded).isFalse();
|
||||
numberOfTracks++;
|
||||
output = new FakeTrackOutput();
|
||||
output = trackOutputFactory.create(id, type);
|
||||
trackOutputs.put(id, output);
|
||||
}
|
||||
return output;
|
||||
|
@ -35,11 +35,18 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
/**
|
||||
* A fake {@link TrackOutput}.
|
||||
*/
|
||||
/** A fake {@link TrackOutput}. */
|
||||
public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
|
||||
public static final Factory DEFAULT_FACTORY =
|
||||
(id, type) -> new FakeTrackOutput(/* deduplicateConsecutiveFormats= */ false);
|
||||
|
||||
/** Factory for {@link FakeTrackOutput} instances. */
|
||||
public interface Factory {
|
||||
FakeTrackOutput create(int id, int type);
|
||||
}
|
||||
|
||||
private final boolean deduplicateConsecutiveFormats;
|
||||
private final ArrayList<DumpableSampleInfo> sampleInfos;
|
||||
private final ArrayList<Dumpable> dumpables;
|
||||
|
||||
@ -49,7 +56,8 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
|
||||
@Nullable public Format lastFormat;
|
||||
|
||||
public FakeTrackOutput() {
|
||||
public FakeTrackOutput(boolean deduplicateConsecutiveFormats) {
|
||||
this.deduplicateConsecutiveFormats = deduplicateConsecutiveFormats;
|
||||
sampleInfos = new ArrayList<>();
|
||||
dumpables = new ArrayList<>();
|
||||
sampleData = Util.EMPTY_BYTE_ARRAY;
|
||||
@ -67,9 +75,19 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
|
||||
@Override
|
||||
public void format(Format format) {
|
||||
Assertions.checkState(
|
||||
receivedSampleInFormat,
|
||||
"TrackOutput must receive at least one sampleMetadata() call between format() calls.");
|
||||
if (!deduplicateConsecutiveFormats) {
|
||||
Assertions.checkState(
|
||||
receivedSampleInFormat,
|
||||
"deduplicateConsecutiveFormats=false so TrackOutput must receive at least one"
|
||||
+ " sampleMetadata() call between format() calls.");
|
||||
} else if (!receivedSampleInFormat) {
|
||||
Dumpable dumpable = dumpables.remove(dumpables.size() - 1);
|
||||
formatCount--;
|
||||
Assertions.checkState(
|
||||
dumpable instanceof DumpableFormat,
|
||||
"receivedSampleInFormat=false so expected last dumpable to be a DumpableFormat. Found: "
|
||||
+ dumpable.getClass().getCanonicalName());
|
||||
}
|
||||
receivedSampleInFormat = false;
|
||||
addFormat(format);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user