Commit 99606f6e by olly Committed by Oliver Woodman

Allow equality assertions on FakeExtractorOutput.

The idea here is that you'll be able to feed data through an extractor
to a FakeExtractorOutput, then do the same again with some or all of the
simulated flakiness settings toggled on FakeExtractorInput, and then
assert that the output was the same in both cases.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117224019
parent a1fc0a6b
...@@ -21,6 +21,7 @@ import com.google.android.exoplayer.extractor.SeekMap; ...@@ -21,6 +21,7 @@ import com.google.android.exoplayer.extractor.SeekMap;
import android.util.SparseArray; import android.util.SparseArray;
import junit.framework.Assert;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
...@@ -32,10 +33,10 @@ public final class FakeExtractorOutput implements ExtractorOutput { ...@@ -32,10 +33,10 @@ public final class FakeExtractorOutput implements ExtractorOutput {
public final SparseArray<FakeTrackOutput> trackOutputs; public final SparseArray<FakeTrackOutput> trackOutputs;
public int numberOfTracks;
public boolean tracksEnded; public boolean tracksEnded;
public SeekMap seekMap; public SeekMap seekMap;
public DrmInitData drmInitData; public DrmInitData drmInitData;
public int numberOfTracks;
public FakeExtractorOutput() { public FakeExtractorOutput() {
this(false); this(false);
...@@ -74,4 +75,29 @@ public final class FakeExtractorOutput implements ExtractorOutput { ...@@ -74,4 +75,29 @@ public final class FakeExtractorOutput implements ExtractorOutput {
this.drmInitData = drmInitData; this.drmInitData = drmInitData;
} }
public void assertEquals(FakeExtractorOutput expected) {
Assert.assertEquals(expected.numberOfTracks, numberOfTracks);
Assert.assertEquals(expected.tracksEnded, tracksEnded);
if (expected.seekMap == null) {
Assert.assertNull(seekMap);
} else {
// TODO: Bulk up this check if possible.
Assert.assertNotNull(seekMap);
Assert.assertEquals(expected.seekMap.getClass(), seekMap.getClass());
Assert.assertEquals(expected.seekMap.isSeekable(), seekMap.isSeekable());
Assert.assertEquals(expected.seekMap.getPosition(0), seekMap.getPosition(0));
}
if (expected.drmInitData == null) {
Assert.assertNull(drmInitData);
} else {
// TODO: Bulk up this check if possible.
Assert.assertNotNull(drmInitData);
Assert.assertEquals(expected.drmInitData.getClass(), drmInitData.getClass());
}
for (int i = 0; i < numberOfTracks; i++) {
Assert.assertEquals(expected.trackOutputs.keyAt(i), trackOutputs.keyAt(i));
trackOutputs.valueAt(i).assertEquals(expected.trackOutputs.valueAt(i));
}
}
} }
...@@ -22,7 +22,7 @@ import com.google.android.exoplayer.util.ParsableByteArray; ...@@ -22,7 +22,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
import android.test.MoreAsserts; import android.test.MoreAsserts;
import junit.framework.TestCase; import junit.framework.Assert;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -82,21 +82,38 @@ public final class FakeTrackOutput implements TrackOutput { ...@@ -82,21 +82,38 @@ public final class FakeTrackOutput implements TrackOutput {
} }
public void assertSampleCount(int count) { public void assertSampleCount(int count) {
TestCase.assertEquals(count, sampleTimesUs.size()); Assert.assertEquals(count, sampleTimesUs.size());
} }
public void assertSample(int index, byte[] data, long timeUs, int flags, byte[] encryptionKey) { public void assertSample(int index, byte[] data, long timeUs, int flags, byte[] encryptionKey) {
byte[] actualData = Arrays.copyOfRange(sampleData, sampleStartOffsets.get(index), byte[] actualData = Arrays.copyOfRange(sampleData, sampleStartOffsets.get(index),
sampleEndOffsets.get(index)); sampleEndOffsets.get(index));
MoreAsserts.assertEquals(data, actualData); MoreAsserts.assertEquals(data, actualData);
TestCase.assertEquals(timeUs, (long) sampleTimesUs.get(index)); Assert.assertEquals(timeUs, (long) sampleTimesUs.get(index));
TestCase.assertEquals(flags, (int) sampleFlags.get(index)); Assert.assertEquals(flags, (int) sampleFlags.get(index));
byte[] sampleEncryptionKey = sampleEncryptionKeys.get(index); byte[] sampleEncryptionKey = sampleEncryptionKeys.get(index);
if (encryptionKey == null) { if (encryptionKey == null) {
TestCase.assertEquals(null, sampleEncryptionKey); Assert.assertEquals(null, sampleEncryptionKey);
} else { } else {
MoreAsserts.assertEquals(encryptionKey, sampleEncryptionKey); MoreAsserts.assertEquals(encryptionKey, sampleEncryptionKey);
} }
} }
public void assertEquals(FakeTrackOutput expected) {
Assert.assertEquals(expected.format, format);
Assert.assertEquals(expected.sampleTimesUs.size(), sampleTimesUs.size());
MoreAsserts.assertEquals(expected.sampleData, sampleData);
for (int i = 0; i < sampleTimesUs.size(); i++) {
Assert.assertEquals(expected.sampleTimesUs.get(i), sampleTimesUs.get(i));
Assert.assertEquals(expected.sampleFlags.get(i), sampleFlags.get(i));
Assert.assertEquals(expected.sampleStartOffsets.get(i), sampleStartOffsets.get(i));
Assert.assertEquals(expected.sampleEndOffsets.get(i), sampleEndOffsets.get(i));
if (expected.sampleEncryptionKeys.get(i) == null) {
Assert.assertNull(sampleEncryptionKeys.get(i));
} else {
MoreAsserts.assertEquals(expected.sampleEncryptionKeys.get(i), sampleEncryptionKeys.get(i));
}
}
}
} }
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