Skip to content

Commit

Permalink
Allow equality assertions on FakeExtractorOutput.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ojw28 committed Jun 15, 2016
1 parent a1fc0a6 commit 99606f6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import android.util.SparseArray;

import junit.framework.Assert;
import junit.framework.TestCase;

/**
Expand All @@ -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);
Expand Down Expand Up @@ -74,4 +75,29 @@ public void drmInitData(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));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import android.test.MoreAsserts;

import junit.framework.TestCase;
import junit.framework.Assert;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -82,21 +82,38 @@ public void sampleMetadata(long timeUs, int flags, int size, int offset, byte[]
}

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));
}
}
}

}

0 comments on commit 99606f6

Please sign in to comment.