TestUtil.assertOutput() uses ExtractorFactory to create a new instance of the Extractor for each combination of simulation parameters.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123506162
This commit is contained in:
eguven 2016-05-28 14:11:34 -07:00 committed by Oliver Woodman
parent 8322592ee8
commit 430985322d
2 changed files with 31 additions and 14 deletions

View file

@ -15,7 +15,9 @@
*/
package com.google.android.exoplayer.extractor.ogg;
import com.google.android.exoplayer.extractor.Extractor;
import com.google.android.exoplayer.testutil.TestUtil;
import com.google.android.exoplayer.testutil.TestUtil.ExtractorFactory;
import android.test.InstrumentationTestCase;
@ -24,21 +26,28 @@ import android.test.InstrumentationTestCase;
*/
public final class OggExtractorFileTests extends InstrumentationTestCase {
private static final ExtractorFactory OGG_EXTRACTOR_FACTORY = new ExtractorFactory() {
@Override
public Extractor create() {
return new OggExtractor();
}
};
public void testOpus() throws Exception {
TestUtil.assertOutput(new OggExtractor(), "ogg/bear.opus", getInstrumentation());
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear.opus", getInstrumentation());
}
public void testFlac() throws Exception {
TestUtil.assertOutput(new OggExtractor(), "ogg/bear_flac.ogg", getInstrumentation());
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_flac.ogg", getInstrumentation());
}
public void testFlacNoSeektable() throws Exception {
TestUtil.assertOutput(new OggExtractor(), "ogg/bear_flac_noseektable.ogg",
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_flac_noseektable.ogg",
getInstrumentation());
}
public void testVorbis() throws Exception {
TestUtil.assertOutput(new OggExtractor(), "ogg/bear_vorbis.ogg", getInstrumentation());
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_vorbis.ogg", getInstrumentation());
}
}

View file

@ -36,6 +36,13 @@ import java.util.Random;
*/
public class TestUtil {
/**
* A factory for {@link Extractor} instances.
*/
public interface ExtractorFactory {
Extractor create();
}
private static final String DUMP_EXTENSION = ".dump";
private static final String UNKNOWN_LENGTH_EXTENSION = ".unklen";
@ -170,23 +177,24 @@ public class TestUtil {
* 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 factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
* class which is 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,
public static void assertOutput(ExtractorFactory factory, 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);
assertOutput(factory.create(), sampleFile, instrumentation, false, false, false);
assertOutput(factory.create(), sampleFile, instrumentation, true, false, false);
assertOutput(factory.create(), sampleFile, instrumentation, false, true, false);
assertOutput(factory.create(), sampleFile, instrumentation, true, true, false);
assertOutput(factory.create(), sampleFile, instrumentation, false, false, true);
assertOutput(factory.create(), sampleFile, instrumentation, true, false, true);
assertOutput(factory.create(), sampleFile, instrumentation, false, true, true);
assertOutput(factory.create(), sampleFile, instrumentation, true, true, true);
}
/**