mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Switch lib-decoder-flac
FlacExtractorTest
to parameterization
The blocking bug has been resolved. Also delete the now unused methods in `ExtractorAsserts`. PiperOrigin-RevId: 737568115
This commit is contained in:
parent
8837ab2564
commit
b47b8ffcd8
@ -18,17 +18,27 @@ package androidx.media3.decoder.flac;
|
|||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import androidx.media3.test.utils.ExtractorAsserts;
|
import androidx.media3.test.utils.ExtractorAsserts;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.media3.test.utils.ExtractorAsserts.AssertionConfig;
|
||||||
|
import androidx.media3.test.utils.ExtractorAsserts.SimulationConfig;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.junit.runners.Parameterized.Parameter;
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
/** Unit test for {@link FlacExtractor}. */
|
/** Unit test for {@link FlacExtractor}. */
|
||||||
// TODO(internal: b/26110951): Use org.junit.runners.Parameterized (and corresponding methods on
|
@RunWith(Parameterized.class)
|
||||||
// ExtractorAsserts) when it's supported by our testing infrastructure.
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class FlacExtractorTest {
|
public class FlacExtractorTest {
|
||||||
|
|
||||||
|
@Parameters(name = "{0}")
|
||||||
|
public static ImmutableList<SimulationConfig> params() {
|
||||||
|
return ExtractorAsserts.configs();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parameter public ExtractorAsserts.SimulationConfig simulationConfig;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
if (!FlacLibrary.isAvailable()) {
|
if (!FlacLibrary.isAvailable()) {
|
||||||
@ -38,89 +48,120 @@ public class FlacExtractorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sample() throws Exception {
|
public void sample() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear.flac",
|
"media/flac/bear.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_raw");
|
new AssertionConfig.Builder().setDumpFilesPrefix("extractordumps/flac/bear_raw").build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sample32bit() throws Exception {
|
public void sample32bit() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_32bit.flac",
|
"media/flac/bear_32bit.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_32bit_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_32bit_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sampleWithId3HeaderAndId3Enabled() throws Exception {
|
public void sampleWithId3HeaderAndId3Enabled() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_with_id3.flac",
|
"media/flac/bear_with_id3.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_with_id3_enabled_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_with_id3_enabled_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sampleWithId3HeaderAndId3Disabled() throws Exception {
|
public void sampleWithId3HeaderAndId3Disabled() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
() -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA),
|
() -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA),
|
||||||
/* file= */ "media/flac/bear_with_id3.flac",
|
"media/flac/bear_with_id3.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_with_id3_disabled_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_with_id3_disabled_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sampleUnseekable() throws Exception {
|
public void sampleUnseekable() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_no_seek_table_no_num_samples.flac",
|
"media/flac/bear_no_seek_table_no_num_samples.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_no_seek_table_no_num_samples_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_no_seek_table_no_num_samples_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sampleWithVorbisComments() throws Exception {
|
public void sampleWithVorbisComments() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_with_vorbis_comments.flac",
|
"media/flac/bear_with_vorbis_comments.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_with_vorbis_comments_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_with_vorbis_comments_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sampleWithPicture() throws Exception {
|
public void sampleWithPicture() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_with_picture.flac",
|
"media/flac/bear_with_picture.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_with_picture_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_with_picture_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void oneMetadataBlock() throws Exception {
|
public void oneMetadataBlock() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_one_metadata_block.flac",
|
"media/flac/bear_one_metadata_block.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_one_metadata_block_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_one_metadata_block_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noMinMaxFrameSize() throws Exception {
|
public void noMinMaxFrameSize() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_no_min_max_frame_size.flac",
|
"media/flac/bear_no_min_max_frame_size.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_no_min_max_frame_size_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_no_min_max_frame_size_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noNumSamples() throws Exception {
|
public void noNumSamples() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_no_num_samples.flac",
|
"media/flac/bear_no_num_samples.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_no_num_samples_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_no_num_samples_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uncommonSampleRate() throws Exception {
|
public void uncommonSampleRate() throws Exception {
|
||||||
ExtractorAsserts.assertAllBehaviors(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new,
|
FlacExtractor::new,
|
||||||
/* file= */ "media/flac/bear_uncommon_sample_rate.flac",
|
"media/flac/bear_uncommon_sample_rate.flac",
|
||||||
/* dumpFilesPrefix= */ "extractordumps/flac/bear_uncommon_sample_rate_raw");
|
new AssertionConfig.Builder()
|
||||||
|
.setDumpFilesPrefix("extractordumps/flac/bear_uncommon_sample_rate_raw")
|
||||||
|
.build(),
|
||||||
|
simulationConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import androidx.media3.common.util.UnstableApi;
|
|||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.extractor.Extractor;
|
import androidx.media3.extractor.Extractor;
|
||||||
import androidx.media3.extractor.ExtractorInput;
|
import androidx.media3.extractor.ExtractorInput;
|
||||||
import androidx.media3.extractor.ExtractorOutput;
|
|
||||||
import androidx.media3.extractor.PositionHolder;
|
import androidx.media3.extractor.PositionHolder;
|
||||||
import androidx.media3.extractor.SeekMap;
|
import androidx.media3.extractor.SeekMap;
|
||||||
import androidx.media3.test.utils.FakeExtractorInput.SimulatedIOException;
|
import androidx.media3.test.utils.FakeExtractorInput.SimulatedIOException;
|
||||||
@ -202,142 +201,6 @@ public final class ExtractorAsserts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that an extractor behaves correctly given valid input data.
|
|
||||||
*
|
|
||||||
* <ul>
|
|
||||||
* <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, boolean)} with all possible combinations of "simulate" parameters.
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @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.
|
|
||||||
* @throws IOException If reading from the input fails.
|
|
||||||
*/
|
|
||||||
public static void assertAllBehaviors(ExtractorFactory factory, String file) throws IOException {
|
|
||||||
assertAllBehaviors(factory, file, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that an extractor behaves correctly given valid input data:
|
|
||||||
*
|
|
||||||
* <ul>
|
|
||||||
* <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, boolean)} with all possible combinations of "simulate" parameters.
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @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 dumpFilesPrefix The dump files prefix appended to the dump files path.
|
|
||||||
* @throws IOException If reading from the input fails.
|
|
||||||
*/
|
|
||||||
public static void assertAllBehaviors(
|
|
||||||
ExtractorFactory factory, String file, String dumpFilesPrefix) throws IOException {
|
|
||||||
// Check behavior prior to initialization.
|
|
||||||
Extractor extractor = factory.create();
|
|
||||||
extractor.seek(0, 0);
|
|
||||||
extractor.release();
|
|
||||||
// Assert output.
|
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
|
||||||
byte[] fileData = TestUtil.getByteArray(context, file);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ false,
|
|
||||||
/* simulateUnknownLength= */ false,
|
|
||||||
/* simulatePartialReads= */ false);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ false,
|
|
||||||
/* simulateUnknownLength= */ false,
|
|
||||||
/* simulatePartialReads= */ true);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ false,
|
|
||||||
/* simulateUnknownLength= */ true,
|
|
||||||
/* simulatePartialReads= */ false);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ false,
|
|
||||||
/* simulateUnknownLength= */ true,
|
|
||||||
/* simulatePartialReads= */ true);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ true,
|
|
||||||
/* simulateUnknownLength= */ false,
|
|
||||||
/* simulatePartialReads= */ false);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ true,
|
|
||||||
/* simulateUnknownLength= */ false,
|
|
||||||
/* simulatePartialReads= */ true);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ true,
|
|
||||||
/* simulateUnknownLength= */ true,
|
|
||||||
/* simulatePartialReads= */ false);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ true,
|
|
||||||
/* simulateIOErrors= */ true,
|
|
||||||
/* simulateUnknownLength= */ true,
|
|
||||||
/* simulatePartialReads= */ true);
|
|
||||||
assertOutput(
|
|
||||||
factory.create(),
|
|
||||||
dumpFilesPrefix,
|
|
||||||
fileData,
|
|
||||||
context,
|
|
||||||
/* deduplicateConsecutiveFormats= */ false,
|
|
||||||
/* sniffFirst= */ false,
|
|
||||||
/* simulateIOErrors= */ false,
|
|
||||||
/* simulateUnknownLength= */ false,
|
|
||||||
/* simulatePartialReads= */ false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that an extractor consumes valid input data successfully under the conditions specified
|
* Asserts that an extractor consumes valid input data successfully under the conditions specified
|
||||||
* by {@code simulationConfig}.
|
* by {@code simulationConfig}.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user