Improve extractor tests based on ExtractorAsserts
- Test seeking to (timeUs=0, position=0), which should always work and produce the same output as initially reading from the start of the stream. - Reset the input when testing seeking, to ensure IO errors are simulated for this case. PiperOrigin-RevId: 261317898
This commit is contained in:
parent
91c62ea26f
commit
5e98d76e8b
@ -175,17 +175,26 @@ public final class ExtractorAsserts {
|
||||
extractorOutput.assertOutput(context, file + ".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);
|
||||
} else {
|
||||
extractorOutput.assertOutput(context, file + ".0" + DUMP_EXTENSION);
|
||||
}
|
||||
|
||||
// If the SeekMap is seekable, test seeking to 4 positions in the stream.
|
||||
SeekMap seekMap = extractorOutput.seekMap;
|
||||
if (seekMap.isSeekable()) {
|
||||
long durationUs = seekMap.getDurationUs();
|
||||
for (int j = 0; j < 4; j++) {
|
||||
extractorOutput.clearTrackOutputs();
|
||||
long timeUs = (durationUs * j) / 3;
|
||||
long position = seekMap.getSeekPoints(timeUs).first.position;
|
||||
input.reset();
|
||||
input.setPosition((int) position);
|
||||
for (int i = 0; i < extractorOutput.numberOfTracks; i++) {
|
||||
extractorOutput.trackOutputs.valueAt(i).clear();
|
||||
}
|
||||
|
||||
consumeTestData(extractor, input, timeUs, extractorOutput, false);
|
||||
extractorOutput.assertOutput(context, file + '.' + j + DUMP_EXTENSION);
|
||||
}
|
||||
|
@ -80,6 +80,15 @@ public final class FakeExtractorInput implements ExtractorInput {
|
||||
failedPeekPositions = new SparseBooleanArray();
|
||||
}
|
||||
|
||||
/** Resets the input to its initial state. */
|
||||
public void reset() {
|
||||
readPosition = 0;
|
||||
peekPosition = 0;
|
||||
partiallySatisfiedTargetPositions.clear();
|
||||
failedReadPositions.clear();
|
||||
failedPeekPositions.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the read and peek positions.
|
||||
*
|
||||
|
@ -70,6 +70,12 @@ public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpab
|
||||
this.seekMap = seekMap;
|
||||
}
|
||||
|
||||
public void clearTrackOutputs() {
|
||||
for (int i = 0; i < numberOfTracks; i++) {
|
||||
trackOutputs.valueAt(i).clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void assertEquals(FakeExtractorOutput expected) {
|
||||
assertThat(numberOfTracks).isEqualTo(expected.numberOfTracks);
|
||||
assertThat(tracksEnded).isEqualTo(expected.tracksEnded);
|
||||
|
Loading…
x
Reference in New Issue
Block a user