Commit 96998895 by ibaker Committed by Oliver Woodman

Assert that a negative extractor sniff never advances the read position

Extractor#sniff() javadoc says:
"If true is returned, the input's reading position may have been
modified. Otherwise, only its peek position may have been modified."
https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/extractor/Extractor.html#sniff-com.google.android.exoplayer2.extractor.ExtractorInput-

PiperOrigin-RevId: 314296922
parent 1f80cf15
......@@ -54,7 +54,8 @@ import java.io.IOException;
public void init(
DataReader dataReader, Uri uri, long position, long length, ExtractorOutput output)
throws IOException {
extractorInput = new DefaultExtractorInput(dataReader, position, length);
ExtractorInput extractorInput = new DefaultExtractorInput(dataReader, position, length);
this.extractorInput = extractorInput;
if (extractor != null) {
return;
}
......@@ -70,6 +71,7 @@ import java.io.IOException;
} catch (EOFException e) {
// Do nothing.
} finally {
Assertions.checkState(this.extractor != null || extractorInput.getPosition() == position);
extractorInput.resetPeekPosition();
}
}
......
......@@ -155,9 +155,13 @@ public final class ExtractorAsserts {
*/
public static void assertSniff(
Extractor extractor, FakeExtractorInput input, boolean expectedResult) throws IOException {
long originalPosition = input.getPosition();
while (true) {
try {
assertThat(extractor.sniff(input)).isEqualTo(expectedResult);
if (!expectedResult) {
assertThat(input.getPosition()).isEqualTo(originalPosition);
}
return;
} catch (SimulatedIOException e) {
// Ignore.
......
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