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
This commit is contained in:
olly 2016-03-15 03:58:57 -07:00 committed by Oliver Woodman
parent a1fc0a6b00
commit 99606f6e2e
2 changed files with 49 additions and 6 deletions

View file

@ -21,6 +21,7 @@ import com.google.android.exoplayer.extractor.SeekMap;
import android.util.SparseArray;
import junit.framework.Assert;
import junit.framework.TestCase;
/**
@ -32,10 +33,10 @@ public final class FakeExtractorOutput implements ExtractorOutput {
public final SparseArray<FakeTrackOutput> trackOutputs;
public int numberOfTracks;
public boolean tracksEnded;
public SeekMap seekMap;
public DrmInitData drmInitData;
public int numberOfTracks;
public FakeExtractorOutput() {
this(false);
@ -74,4 +75,29 @@ public final class FakeExtractorOutput implements ExtractorOutput {
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));
}
}
}

View file

@ -22,7 +22,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
import android.test.MoreAsserts;
import junit.framework.TestCase;
import junit.framework.Assert;
import java.io.IOException;
import java.util.ArrayList;
@ -82,21 +82,38 @@ public final class FakeTrackOutput implements TrackOutput {
}
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) {
byte[] actualData = Arrays.copyOfRange(sampleData, sampleStartOffsets.get(index),
sampleEndOffsets.get(index));
MoreAsserts.assertEquals(data, actualData);
TestCase.assertEquals(timeUs, (long) sampleTimesUs.get(index));
TestCase.assertEquals(flags, (int) sampleFlags.get(index));
Assert.assertEquals(timeUs, (long) sampleTimesUs.get(index));
Assert.assertEquals(flags, (int) sampleFlags.get(index));
byte[] sampleEncryptionKey = sampleEncryptionKeys.get(index);
if (encryptionKey == null) {
TestCase.assertEquals(null, sampleEncryptionKey);
Assert.assertEquals(null, sampleEncryptionKey);
} else {
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));
}
}
}
}