Commit 04af8e60 by kimvde Committed by kim-vde

Add the possibility to specify the dump files path in ExtractorAsserts

PiperOrigin-RevId: 293554489
parent 79a3bad4
......@@ -87,13 +87,7 @@ public final class ExtractorAsserts {
*/
public static void assertBehavior(ExtractorFactory factory, String file)
throws IOException, InterruptedException {
// Check behavior prior to initialization.
Extractor extractor = factory.create();
extractor.seek(0, 0);
extractor.release();
// Assert output.
byte[] fileData = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), file);
assertOutput(factory, file, fileData, ApplicationProvider.getApplicationContext());
assertBehavior(factory, file, ApplicationProvider.getApplicationContext());
}
/**
......@@ -115,13 +109,37 @@ public final class ExtractorAsserts {
*/
public static void assertBehavior(ExtractorFactory factory, String file, Context context)
throws IOException, InterruptedException {
assertBehavior(factory, file, context, 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)} 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 context To be used to load the sample file.
* @param dumpFilesPrefix The dump files prefix appended to the dump files path.
* @throws IOException If reading from the input fails.
* @throws InterruptedException If interrupted while reading from the input.
*/
public static void assertBehavior(
ExtractorFactory factory, String file, Context context, String dumpFilesPrefix)
throws IOException, InterruptedException {
// Check behavior prior to initialization.
Extractor extractor = factory.create();
extractor.seek(0, 0);
extractor.release();
// Assert output.
byte[] fileData = TestUtil.getByteArray(context, file);
assertOutput(factory, file, fileData, context);
assertOutput(factory, dumpFilesPrefix, fileData, context);
}
/**
......@@ -132,24 +150,24 @@ 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 dumpFilesPrefix The dump files prefix appended to the dump files path.
* @param data Content of the input file.
* @param context 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.
*/
public static void assertOutput(
ExtractorFactory factory, String file, byte[] data, Context context)
ExtractorFactory factory, String dumpFilesPrefix, byte[] data, Context context)
throws IOException, InterruptedException {
assertOutput(factory.create(), file, data, context, true, false, false, false);
assertOutput(factory.create(), file, data, context, true, false, false, true);
assertOutput(factory.create(), file, data, context, true, false, true, false);
assertOutput(factory.create(), file, data, context, true, false, true, true);
assertOutput(factory.create(), file, data, context, true, true, false, false);
assertOutput(factory.create(), file, data, context, true, true, false, true);
assertOutput(factory.create(), file, data, context, true, true, true, false);
assertOutput(factory.create(), file, data, context, true, true, true, true);
assertOutput(factory.create(), file, data, context, false, false, false, false);
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);
}
/**
......@@ -159,7 +177,7 @@ public final class ExtractorAsserts {
* #UNKNOWN_LENGTH_EXTENSION}" exists, it's preferred.
*
* @param extractor The {@link Extractor} to be tested.
* @param file The path to the input sample.
* @param dumpFilesPrefix The dump files prefix appended to the dump files path.
* @param data Content of the input file.
* @param context To be used to load the sample file.
* @param sniffFirst Whether to sniff the data by calling {@link Extractor#sniff(ExtractorInput)}
......@@ -173,7 +191,7 @@ public final class ExtractorAsserts {
*/
public static FakeExtractorOutput assertOutput(
Extractor extractor,
String file,
String dumpFilesPrefix,
byte[] data,
Context context,
boolean sniffFirst,
......@@ -192,20 +210,20 @@ public final class ExtractorAsserts {
}
FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, 0, true);
if (simulateUnknownLength && assetExists(context, file + UNKNOWN_LENGTH_EXTENSION)) {
extractorOutput.assertOutput(context, file + UNKNOWN_LENGTH_EXTENSION);
if (simulateUnknownLength && assetExists(context, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION)) {
extractorOutput.assertOutput(context, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
} else {
extractorOutput.assertOutput(context, file + ".0" + DUMP_EXTENSION);
extractorOutput.assertOutput(context, dumpFilesPrefix + ".0" + DUMP_EXTENSION);
}
// Seeking to (timeUs=0, position=0) should always work, and cause the same data to be output.
extractorOutput.clearTrackOutputs();
input.reset();
consumeTestData(extractor, input, /* timeUs= */ 0, extractorOutput, false);
if (simulateUnknownLength && assetExists(context, file + UNKNOWN_LENGTH_EXTENSION)) {
extractorOutput.assertOutput(context, file + UNKNOWN_LENGTH_EXTENSION);
if (simulateUnknownLength && assetExists(context, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION)) {
extractorOutput.assertOutput(context, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
} else {
extractorOutput.assertOutput(context, file + ".0" + DUMP_EXTENSION);
extractorOutput.assertOutput(context, dumpFilesPrefix + ".0" + DUMP_EXTENSION);
}
// If the SeekMap is seekable, test seeking in the stream.
......@@ -219,7 +237,7 @@ public final class ExtractorAsserts {
input.reset();
input.setPosition((int) position);
consumeTestData(extractor, input, timeUs, extractorOutput, false);
extractorOutput.assertOutput(context, file + '.' + j + DUMP_EXTENSION);
extractorOutput.assertOutput(context, dumpFilesPrefix + '.' + j + DUMP_EXTENSION);
if (durationUs == C.TIME_UNSET) {
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment