mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Moved/renamed OggExtractorFileTests.parseFile(...) methods to TestUtil.assertOutput(...).
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123410374
This commit is contained in:
parent
800006d08d
commit
651237ac4f
3 changed files with 72 additions and 58 deletions
|
|
@ -15,9 +15,6 @@
|
|||
*/
|
||||
package com.google.android.exoplayer.extractor.ogg;
|
||||
|
||||
import com.google.android.exoplayer.testutil.FakeExtractorInput;
|
||||
import com.google.android.exoplayer.testutil.FakeExtractorOutput;
|
||||
import com.google.android.exoplayer.testutil.FakeTrackOutput;
|
||||
import com.google.android.exoplayer.testutil.TestUtil;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
|
@ -27,69 +24,21 @@ import android.test.InstrumentationTestCase;
|
|||
*/
|
||||
public final class OggExtractorFileTests extends InstrumentationTestCase {
|
||||
|
||||
private static final String OPUS_TEST_FILE = "ogg/bear.opus";
|
||||
private static final String FLAC_TEST_FILE = "ogg/bear_flac.ogg";
|
||||
private static final String FLAC_NS_TEST_FILE = "ogg/bear_flac_noseektable.ogg";
|
||||
private static final String VORBIS_TEST_FILE = "ogg/bear_vorbis.ogg";
|
||||
private static final String DUMP_EXTENSION = ".dump";
|
||||
private static final String UNKNOWN_LENGTH_EXTENSION = ".unklen";
|
||||
|
||||
public void testOpus() throws Exception {
|
||||
parseFile(OPUS_TEST_FILE);
|
||||
TestUtil.assertOutput(new OggExtractor(), "ogg/bear.opus", getInstrumentation());
|
||||
}
|
||||
|
||||
public void testFlac() throws Exception {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
testFlac((i & 1) != 0, (i & 2) != 0, (i & 4) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void testFlac(boolean simulateIOErrors, boolean simulateUnknownLength,
|
||||
boolean simulatePartialReads) throws Exception {
|
||||
FakeExtractorOutput extractorOutput = parseFile(FLAC_TEST_FILE, simulateIOErrors,
|
||||
simulateUnknownLength, simulatePartialReads);
|
||||
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
|
||||
for (int i = 0; i < 33; i++) {
|
||||
byte[] sampleData = trackOutput.getSampleData(i);
|
||||
assertTrue(FlacReader.isAudioPacket(sampleData));
|
||||
}
|
||||
TestUtil.assertOutput(new OggExtractor(), "ogg/bear_flac.ogg", getInstrumentation());
|
||||
}
|
||||
|
||||
public void testFlacNoSeektable() throws Exception {
|
||||
parseFile(FLAC_NS_TEST_FILE);
|
||||
TestUtil.assertOutput(new OggExtractor(), "ogg/bear_flac_noseektable.ogg",
|
||||
getInstrumentation());
|
||||
}
|
||||
|
||||
public void testVorbis() throws Exception {
|
||||
parseFile(VORBIS_TEST_FILE);
|
||||
}
|
||||
|
||||
private void parseFile(String testFile) throws Exception {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
parseFile(testFile, (i & 1) != 0, (i & 2) != 0, (i & 4) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
private FakeExtractorOutput parseFile(String testFile, boolean simulateIOErrors,
|
||||
boolean simulateUnknownLength, boolean simulatePartialReads) throws Exception {
|
||||
byte[] fileData = TestUtil.getByteArray(getInstrumentation(), testFile);
|
||||
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData)
|
||||
.setSimulateIOErrors(simulateIOErrors)
|
||||
.setSimulateUnknownLength(simulateUnknownLength)
|
||||
.setSimulatePartialReads(simulatePartialReads).build();
|
||||
|
||||
OggExtractor extractor = new OggExtractor();
|
||||
assertTrue(TestUtil.sniffTestData(extractor, input));
|
||||
input.resetPeekPosition();
|
||||
FakeExtractorOutput extractorOutput = TestUtil.consumeTestData(extractor, input, true);
|
||||
|
||||
String dumpFile = testFile;
|
||||
if (simulateUnknownLength) {
|
||||
dumpFile += UNKNOWN_LENGTH_EXTENSION;
|
||||
}
|
||||
dumpFile += DUMP_EXTENSION;
|
||||
extractorOutput.assertOutput(getInstrumentation(), dumpFile);
|
||||
|
||||
return extractorOutput;
|
||||
TestUtil.assertOutput(new OggExtractor(), "ogg/bear_vorbis.ogg", getInstrumentation());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import com.google.android.exoplayer.util.Util;
|
|||
|
||||
import android.app.Instrumentation;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import junit.framework.Assert;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -35,6 +36,9 @@ import java.util.Random;
|
|||
*/
|
||||
public class TestUtil {
|
||||
|
||||
private static final String DUMP_EXTENSION = ".dump";
|
||||
private static final String UNKNOWN_LENGTH_EXTENSION = ".unklen";
|
||||
|
||||
private TestUtil() {}
|
||||
|
||||
public static boolean sniffTestData(Extractor extractor, byte[] data)
|
||||
|
|
@ -162,4 +166,66 @@ public class TestUtil {
|
|||
return new FakeExtractorInput.Builder().setData(data).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link #assertOutput(Extractor, String, Instrumentation, boolean, boolean, boolean)} with
|
||||
* all possible combinations of "simulate" parameters.
|
||||
*
|
||||
* @param extractor The {@link Extractor} to be tested.
|
||||
* @param sampleFile The path to the input sample.
|
||||
* @param instrumentation To be used to load the sample file.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
* @see #assertOutput(Extractor, String, Instrumentation, boolean, boolean, boolean)
|
||||
*/
|
||||
public static void assertOutput(Extractor extractor, String sampleFile,
|
||||
Instrumentation instrumentation) throws IOException, InterruptedException {
|
||||
assertOutput(extractor, sampleFile, instrumentation, false, false, false);
|
||||
assertOutput(extractor, sampleFile, instrumentation, true, false, false);
|
||||
assertOutput(extractor, sampleFile, instrumentation, false, true, false);
|
||||
assertOutput(extractor, sampleFile, instrumentation, true, true, false);
|
||||
assertOutput(extractor, sampleFile, instrumentation, false, false, true);
|
||||
assertOutput(extractor, sampleFile, instrumentation, true, false, true);
|
||||
assertOutput(extractor, sampleFile, instrumentation, false, true, true);
|
||||
assertOutput(extractor, sampleFile, instrumentation, true, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that {@code extractor} consumes {@code sampleFile} successfully and its output equals
|
||||
* to a prerecorded output dump file. The prerecorded output dump file name is determined by
|
||||
* appending "{@value UNKNOWN_LENGTH_EXTENSION}" if {@code simulateUnknownLength} is true and
|
||||
* appending "{@value DUMP_EXTENSION}" to the end of {@code sampleFile}.
|
||||
*
|
||||
* @param extractor The {@link Extractor} to be tested.
|
||||
* @param sampleFile The path to the input sample.
|
||||
* @param instrumentation To be used to load the sample file.
|
||||
* @param simulateIOErrors If true simulates IOErrors.
|
||||
* @param simulateUnknownLength If true simulates unknown input length.
|
||||
* @param simulatePartialReads If true simulates partial reads.
|
||||
* @return The {@link FakeExtractorOutput} used in the test.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
public static FakeExtractorOutput assertOutput(Extractor extractor, String sampleFile,
|
||||
Instrumentation instrumentation, boolean simulateIOErrors, boolean simulateUnknownLength,
|
||||
boolean simulatePartialReads) throws IOException, InterruptedException {
|
||||
byte[] fileData = getByteArray(instrumentation, sampleFile);
|
||||
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData)
|
||||
.setSimulateIOErrors(simulateIOErrors)
|
||||
.setSimulateUnknownLength(simulateUnknownLength)
|
||||
.setSimulatePartialReads(simulatePartialReads).build();
|
||||
|
||||
Assert.assertTrue(sniffTestData(extractor, input));
|
||||
input.resetPeekPosition();
|
||||
FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, true);
|
||||
|
||||
String dumpFile = sampleFile;
|
||||
if (simulateUnknownLength) {
|
||||
dumpFile += UNKNOWN_LENGTH_EXTENSION;
|
||||
}
|
||||
dumpFile += DUMP_EXTENSION;
|
||||
extractorOutput.assertOutput(instrumentation, dumpFile);
|
||||
|
||||
return extractorOutput;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ import java.util.List;
|
|||
}
|
||||
}
|
||||
|
||||
//@VisibleForTesting
|
||||
public static boolean isAudioPacket(byte[] data) {
|
||||
private static boolean isAudioPacket(byte[] data) {
|
||||
return data[0] == AUDIO_PACKET_TYPE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue