Commit ccfb6beb by eguven Committed by Oliver Woodman

FakeExtractorOutput dump() and assertEquals(..., String dumpFile) methods to…

FakeExtractorOutput dump() and assertEquals(..., String dumpFile) methods to facilitate extractor test writing.

Changed OggExtractorFileTests to use dump files.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123407516
parent abc5c41f
seekMap:
isSeekable = true
duration = 2741000
getPosition(0) = 8457
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
rotationDegrees = -1
pixelWidthHeightRatio = -1.0
channelCount = 2
sampleRate = 48000
pcmEncoding = -1
encoderDelay = -1
encoderPadding = -1
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
initializationData:
data = length 42, hash 83F6895
sample count = 33
sample 0:
time = 0
flags = 1
data = length 5030, hash D2B60530
sample 1:
time = 85333
flags = 1
data = length 5066, hash 4C932A54
sample 2:
time = 170666
flags = 1
data = length 5112, hash 7E5A7B61
sample 3:
time = 256000
flags = 1
data = length 5044, hash 7EF93F13
sample 4:
time = 341333
flags = 1
data = length 4943, hash DE7E27F8
sample 5:
time = 426666
flags = 1
data = length 5121, hash 6D0D0B40
sample 6:
time = 512000
flags = 1
data = length 5068, hash 9924644F
sample 7:
time = 597333
flags = 1
data = length 5143, hash 6C34F0CE
sample 8:
time = 682666
flags = 1
data = length 5109, hash E3B7BEFB
sample 9:
time = 768000
flags = 1
data = length 5129, hash 44111D9B
sample 10:
time = 853333
flags = 1
data = length 5031, hash 9D55EA53
sample 11:
time = 938666
flags = 1
data = length 5119, hash E1CB9BA6
sample 12:
time = 1024000
flags = 1
data = length 5360, hash 17265C5D
sample 13:
time = 1109333
flags = 1
data = length 5340, hash A90FDDF1
sample 14:
time = 1194666
flags = 1
data = length 5162, hash 31F65AD5
sample 15:
time = 1280000
flags = 1
data = length 5168, hash F2394F2D
sample 16:
time = 1365333
flags = 1
data = length 5776, hash 58437AB3
sample 17:
time = 1450666
flags = 1
data = length 5394, hash EBAB20A8
sample 18:
time = 1536000
flags = 1
data = length 5168, hash BF37C7A5
sample 19:
time = 1621333
flags = 1
data = length 5324, hash 59546B7B
sample 20:
time = 1706666
flags = 1
data = length 5172, hash 6036EF0B
sample 21:
time = 1792000
flags = 1
data = length 5102, hash 5A131071
sample 22:
time = 1877333
flags = 1
data = length 5111, hash 3D9EBB3B
sample 23:
time = 1962666
flags = 1
data = length 5113, hash 61101D4F
sample 24:
time = 2048000
flags = 1
data = length 5229, hash D2E55742
sample 25:
time = 2133333
flags = 1
data = length 5162, hash 7F2E97FA
sample 26:
time = 2218666
flags = 1
data = length 5255, hash D92A782
sample 27:
time = 2304000
flags = 1
data = length 5196, hash 98FE5138
sample 28:
time = 2389333
flags = 1
data = length 5214, hash 3D35C38C
sample 29:
time = 2474666
flags = 1
data = length 5211, hash 7E25420F
sample 30:
time = 2560000
flags = 1
data = length 5230, hash 2AD96FBC
sample 31:
time = 2645333
flags = 1
data = length 3384, hash 938BCDD9
sample 32:
time = 2730666
flags = 1
data = length 445, hash A388E3D6
tracksEnded = true
seekMap:
isSeekable = true
duration = 2741000
getPosition(0) = 8457
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
rotationDegrees = -1
pixelWidthHeightRatio = -1.0
channelCount = 2
sampleRate = 48000
pcmEncoding = -1
encoderDelay = -1
encoderPadding = -1
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
initializationData:
data = length 42, hash 83F6895
sample count = 33
sample 0:
time = 0
flags = 1
data = length 5030, hash D2B60530
sample 1:
time = 85333
flags = 1
data = length 5066, hash 4C932A54
sample 2:
time = 170666
flags = 1
data = length 5112, hash 7E5A7B61
sample 3:
time = 256000
flags = 1
data = length 5044, hash 7EF93F13
sample 4:
time = 341333
flags = 1
data = length 4943, hash DE7E27F8
sample 5:
time = 426666
flags = 1
data = length 5121, hash 6D0D0B40
sample 6:
time = 512000
flags = 1
data = length 5068, hash 9924644F
sample 7:
time = 597333
flags = 1
data = length 5143, hash 6C34F0CE
sample 8:
time = 682666
flags = 1
data = length 5109, hash E3B7BEFB
sample 9:
time = 768000
flags = 1
data = length 5129, hash 44111D9B
sample 10:
time = 853333
flags = 1
data = length 5031, hash 9D55EA53
sample 11:
time = 938666
flags = 1
data = length 5119, hash E1CB9BA6
sample 12:
time = 1024000
flags = 1
data = length 5360, hash 17265C5D
sample 13:
time = 1109333
flags = 1
data = length 5340, hash A90FDDF1
sample 14:
time = 1194666
flags = 1
data = length 5162, hash 31F65AD5
sample 15:
time = 1280000
flags = 1
data = length 5168, hash F2394F2D
sample 16:
time = 1365333
flags = 1
data = length 5776, hash 58437AB3
sample 17:
time = 1450666
flags = 1
data = length 5394, hash EBAB20A8
sample 18:
time = 1536000
flags = 1
data = length 5168, hash BF37C7A5
sample 19:
time = 1621333
flags = 1
data = length 5324, hash 59546B7B
sample 20:
time = 1706666
flags = 1
data = length 5172, hash 6036EF0B
sample 21:
time = 1792000
flags = 1
data = length 5102, hash 5A131071
sample 22:
time = 1877333
flags = 1
data = length 5111, hash 3D9EBB3B
sample 23:
time = 1962666
flags = 1
data = length 5113, hash 61101D4F
sample 24:
time = 2048000
flags = 1
data = length 5229, hash D2E55742
sample 25:
time = 2133333
flags = 1
data = length 5162, hash 7F2E97FA
sample 26:
time = 2218666
flags = 1
data = length 5255, hash D92A782
sample 27:
time = 2304000
flags = 1
data = length 5196, hash 98FE5138
sample 28:
time = 2389333
flags = 1
data = length 5214, hash 3D35C38C
sample 29:
time = 2474666
flags = 1
data = length 5211, hash 7E25420F
sample 30:
time = 2560000
flags = 1
data = length 5230, hash 2AD96FBC
sample 31:
time = 2645333
flags = 1
data = length 3384, hash 938BCDD9
sample 32:
time = 2730666
flags = 1
data = length 445, hash A388E3D6
tracksEnded = true
seekMap:
isSeekable = true
duration = 2741000
getPosition(0) = 8407
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
rotationDegrees = -1
pixelWidthHeightRatio = -1.0
channelCount = 2
sampleRate = 48000
pcmEncoding = -1
encoderDelay = -1
encoderPadding = -1
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
initializationData:
data = length 42, hash 83F6895
sample count = 33
sample 0:
time = 0
flags = 1
data = length 5030, hash D2B60530
sample 1:
time = 85333
flags = 1
data = length 5066, hash 4C932A54
sample 2:
time = 170666
flags = 1
data = length 5112, hash 7E5A7B61
sample 3:
time = 256000
flags = 1
data = length 5044, hash 7EF93F13
sample 4:
time = 341333
flags = 1
data = length 4943, hash DE7E27F8
sample 5:
time = 426666
flags = 1
data = length 5121, hash 6D0D0B40
sample 6:
time = 512000
flags = 1
data = length 5068, hash 9924644F
sample 7:
time = 597333
flags = 1
data = length 5143, hash 6C34F0CE
sample 8:
time = 682666
flags = 1
data = length 5109, hash E3B7BEFB
sample 9:
time = 768000
flags = 1
data = length 5129, hash 44111D9B
sample 10:
time = 853333
flags = 1
data = length 5031, hash 9D55EA53
sample 11:
time = 938666
flags = 1
data = length 5119, hash E1CB9BA6
sample 12:
time = 1024000
flags = 1
data = length 5360, hash 17265C5D
sample 13:
time = 1109333
flags = 1
data = length 5340, hash A90FDDF1
sample 14:
time = 1194666
flags = 1
data = length 5162, hash 31F65AD5
sample 15:
time = 1280000
flags = 1
data = length 5168, hash F2394F2D
sample 16:
time = 1365333
flags = 1
data = length 5776, hash 58437AB3
sample 17:
time = 1450666
flags = 1
data = length 5394, hash EBAB20A8
sample 18:
time = 1536000
flags = 1
data = length 5168, hash BF37C7A5
sample 19:
time = 1621333
flags = 1
data = length 5324, hash 59546B7B
sample 20:
time = 1706666
flags = 1
data = length 5172, hash 6036EF0B
sample 21:
time = 1792000
flags = 1
data = length 5102, hash 5A131071
sample 22:
time = 1877333
flags = 1
data = length 5111, hash 3D9EBB3B
sample 23:
time = 1962666
flags = 1
data = length 5113, hash 61101D4F
sample 24:
time = 2048000
flags = 1
data = length 5229, hash D2E55742
sample 25:
time = 2133333
flags = 1
data = length 5162, hash 7F2E97FA
sample 26:
time = 2218666
flags = 1
data = length 5255, hash D92A782
sample 27:
time = 2304000
flags = 1
data = length 5196, hash 98FE5138
sample 28:
time = 2389333
flags = 1
data = length 5214, hash 3D35C38C
sample 29:
time = 2474666
flags = 1
data = length 5211, hash 7E25420F
sample 30:
time = 2560000
flags = 1
data = length 5230, hash 2AD96FBC
sample 31:
time = 2645333
flags = 1
data = length 3384, hash 938BCDD9
sample 32:
time = 2730666
flags = 1
data = length 445, hash A388E3D6
tracksEnded = true
seekMap:
isSeekable = false
duration = UNSET TIME
getPosition(0) = 0
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
rotationDegrees = -1
pixelWidthHeightRatio = -1.0
channelCount = 2
sampleRate = 48000
pcmEncoding = -1
encoderDelay = -1
encoderPadding = -1
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
initializationData:
data = length 42, hash 83F6895
sample count = 33
sample 0:
time = 0
flags = 1
data = length 5030, hash D2B60530
sample 1:
time = 85333
flags = 1
data = length 5066, hash 4C932A54
sample 2:
time = 170666
flags = 1
data = length 5112, hash 7E5A7B61
sample 3:
time = 256000
flags = 1
data = length 5044, hash 7EF93F13
sample 4:
time = 341333
flags = 1
data = length 4943, hash DE7E27F8
sample 5:
time = 426666
flags = 1
data = length 5121, hash 6D0D0B40
sample 6:
time = 512000
flags = 1
data = length 5068, hash 9924644F
sample 7:
time = 597333
flags = 1
data = length 5143, hash 6C34F0CE
sample 8:
time = 682666
flags = 1
data = length 5109, hash E3B7BEFB
sample 9:
time = 768000
flags = 1
data = length 5129, hash 44111D9B
sample 10:
time = 853333
flags = 1
data = length 5031, hash 9D55EA53
sample 11:
time = 938666
flags = 1
data = length 5119, hash E1CB9BA6
sample 12:
time = 1024000
flags = 1
data = length 5360, hash 17265C5D
sample 13:
time = 1109333
flags = 1
data = length 5340, hash A90FDDF1
sample 14:
time = 1194666
flags = 1
data = length 5162, hash 31F65AD5
sample 15:
time = 1280000
flags = 1
data = length 5168, hash F2394F2D
sample 16:
time = 1365333
flags = 1
data = length 5776, hash 58437AB3
sample 17:
time = 1450666
flags = 1
data = length 5394, hash EBAB20A8
sample 18:
time = 1536000
flags = 1
data = length 5168, hash BF37C7A5
sample 19:
time = 1621333
flags = 1
data = length 5324, hash 59546B7B
sample 20:
time = 1706666
flags = 1
data = length 5172, hash 6036EF0B
sample 21:
time = 1792000
flags = 1
data = length 5102, hash 5A131071
sample 22:
time = 1877333
flags = 1
data = length 5111, hash 3D9EBB3B
sample 23:
time = 1962666
flags = 1
data = length 5113, hash 61101D4F
sample 24:
time = 2048000
flags = 1
data = length 5229, hash D2E55742
sample 25:
time = 2133333
flags = 1
data = length 5162, hash 7F2E97FA
sample 26:
time = 2218666
flags = 1
data = length 5255, hash D92A782
sample 27:
time = 2304000
flags = 1
data = length 5196, hash 98FE5138
sample 28:
time = 2389333
flags = 1
data = length 5214, hash 3D35C38C
sample 29:
time = 2474666
flags = 1
data = length 5211, hash 7E25420F
sample 30:
time = 2560000
flags = 1
data = length 5230, hash 2AD96FBC
sample 31:
time = 2645333
flags = 1
data = length 3384, hash 938BCDD9
sample 32:
time = 2730666
flags = 1
data = length 445, hash A388E3D6
tracksEnded = true
...@@ -15,14 +15,10 @@ ...@@ -15,14 +15,10 @@
*/ */
package com.google.android.exoplayer.extractor.ogg; package com.google.android.exoplayer.extractor.ogg;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.Format;
import com.google.android.exoplayer.extractor.SeekMap;
import com.google.android.exoplayer.testutil.FakeExtractorInput; import com.google.android.exoplayer.testutil.FakeExtractorInput;
import com.google.android.exoplayer.testutil.FakeExtractorOutput; import com.google.android.exoplayer.testutil.FakeExtractorOutput;
import com.google.android.exoplayer.testutil.FakeTrackOutput; import com.google.android.exoplayer.testutil.FakeTrackOutput;
import com.google.android.exoplayer.testutil.TestUtil; import com.google.android.exoplayer.testutil.TestUtil;
import com.google.android.exoplayer.util.MimeTypes;
import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase;
...@@ -31,29 +27,28 @@ import android.test.InstrumentationTestCase; ...@@ -31,29 +27,28 @@ import android.test.InstrumentationTestCase;
*/ */
public final class OggExtractorFileTests extends InstrumentationTestCase { public final class OggExtractorFileTests extends InstrumentationTestCase {
public static final String OPUS_TEST_FILE = "ogg/bear.opus"; private static final String OPUS_TEST_FILE = "ogg/bear.opus";
public static final String FLAC_TEST_FILE = "ogg/bear_flac.ogg"; private static final String FLAC_TEST_FILE = "ogg/bear_flac.ogg";
public static final String FLAC_NS_TEST_FILE = "ogg/bear_flac_noseektable.ogg"; private static final String FLAC_NS_TEST_FILE = "ogg/bear_flac_noseektable.ogg";
public static final String VORBIS_TEST_FILE = "ogg/bear_vorbis.ogg"; private static final String VORBIS_TEST_FILE = "ogg/bear_vorbis.ogg";
private static final String DUMP_EXTENSION = ".dump";
private static final String UNKNOWN_LENGTH_EXTENSION = ".unklen";
public void testOpus() throws Exception { public void testOpus() throws Exception {
parseFile(OPUS_TEST_FILE, false, false, false, MimeTypes.AUDIO_OPUS, 2747500, 275); parseFile(OPUS_TEST_FILE);
parseFile(OPUS_TEST_FILE, false, true, false, MimeTypes.AUDIO_OPUS, C.UNSET_TIME_US, 275);
parseFile(OPUS_TEST_FILE, true, false, true, MimeTypes.AUDIO_OPUS, 2747500, 275);
parseFile(OPUS_TEST_FILE, true, true, true, MimeTypes.AUDIO_OPUS, C.UNSET_TIME_US, 275);
} }
public void testFlac() throws Exception { public void testFlac() throws Exception {
testFlac(false, false, false); for (int i = 0; i < 8; i++) {
testFlac(false, true, false); testFlac((i & 1) != 0, (i & 2) != 0, (i & 4) != 0);
testFlac(true, false, true); }
testFlac(true, true, true);
} }
private void testFlac(boolean simulateIOErrors, boolean simulateUnknownLength, private void testFlac(boolean simulateIOErrors, boolean simulateUnknownLength,
boolean simulatePartialReads) throws Exception { boolean simulatePartialReads) throws Exception {
FakeTrackOutput trackOutput = parseFile(FLAC_TEST_FILE, simulateIOErrors, simulateUnknownLength, FakeExtractorOutput extractorOutput = parseFile(FLAC_TEST_FILE, simulateIOErrors,
simulatePartialReads, MimeTypes.AUDIO_FLAC, 2741000, 33); simulateUnknownLength, simulatePartialReads);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
for (int i = 0; i < 33; i++) { for (int i = 0; i < 33; i++) {
byte[] sampleData = trackOutput.getSampleData(i); byte[] sampleData = trackOutput.getSampleData(i);
assertTrue(FlacReader.isAudioPacket(sampleData)); assertTrue(FlacReader.isAudioPacket(sampleData));
...@@ -61,22 +56,21 @@ public final class OggExtractorFileTests extends InstrumentationTestCase { ...@@ -61,22 +56,21 @@ public final class OggExtractorFileTests extends InstrumentationTestCase {
} }
public void testFlacNoSeektable() throws Exception { public void testFlacNoSeektable() throws Exception {
parseFile(FLAC_NS_TEST_FILE, false, false, false, MimeTypes.AUDIO_FLAC, 2741000, 33); parseFile(FLAC_NS_TEST_FILE);
parseFile(FLAC_NS_TEST_FILE, false, true, false, MimeTypes.AUDIO_FLAC, C.UNSET_TIME_US, 33);
parseFile(FLAC_NS_TEST_FILE, true, false, true, MimeTypes.AUDIO_FLAC, 2741000, 33);
parseFile(FLAC_NS_TEST_FILE, true, true, true, MimeTypes.AUDIO_FLAC, C.UNSET_TIME_US, 33);
} }
public void testVorbis() throws Exception { public void testVorbis() throws Exception {
parseFile(VORBIS_TEST_FILE, false, false, false, MimeTypes.AUDIO_VORBIS, 2741000, 180); parseFile(VORBIS_TEST_FILE);
parseFile(VORBIS_TEST_FILE, false, true, false, MimeTypes.AUDIO_VORBIS, C.UNSET_TIME_US, 180); }
parseFile(VORBIS_TEST_FILE, true, false, true, MimeTypes.AUDIO_VORBIS, 2741000, 180);
parseFile(VORBIS_TEST_FILE, true, true, true, MimeTypes.AUDIO_VORBIS, C.UNSET_TIME_US, 180); private void parseFile(String testFile) throws Exception {
for (int i = 0; i < 8; i++) {
parseFile(testFile, (i & 1) != 0, (i & 2) != 0, (i & 4) != 0);
}
} }
private FakeTrackOutput parseFile(String testFile, boolean simulateIOErrors, private FakeExtractorOutput parseFile(String testFile, boolean simulateIOErrors,
boolean simulateUnknownLength, boolean simulatePartialReads, String expectedMimeType, boolean simulateUnknownLength, boolean simulatePartialReads) throws Exception {
long expectedDuration, int expectedSampleCount) throws Exception {
byte[] fileData = TestUtil.getByteArray(getInstrumentation(), testFile); byte[] fileData = TestUtil.getByteArray(getInstrumentation(), testFile);
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData) FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData)
.setSimulateIOErrors(simulateIOErrors) .setSimulateIOErrors(simulateIOErrors)
...@@ -88,23 +82,14 @@ public final class OggExtractorFileTests extends InstrumentationTestCase { ...@@ -88,23 +82,14 @@ public final class OggExtractorFileTests extends InstrumentationTestCase {
input.resetPeekPosition(); input.resetPeekPosition();
FakeExtractorOutput extractorOutput = TestUtil.consumeTestData(extractor, input, true); FakeExtractorOutput extractorOutput = TestUtil.consumeTestData(extractor, input, true);
assertEquals(1, extractorOutput.trackOutputs.size()); String dumpFile = testFile;
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0); if (simulateUnknownLength) {
assertNotNull(trackOutput); dumpFile += UNKNOWN_LENGTH_EXTENSION;
}
Format format = trackOutput.format; dumpFile += DUMP_EXTENSION;
assertNotNull(format); extractorOutput.assertOutput(getInstrumentation(), dumpFile);
assertEquals(expectedMimeType, format.sampleMimeType);
assertEquals(48000, format.sampleRate);
assertEquals(2, format.channelCount);
SeekMap seekMap = extractorOutput.seekMap;
assertNotNull(seekMap);
assertEquals(expectedDuration, seekMap.getDurationUs());
assertEquals(expectedDuration != C.UNSET_TIME_US, seekMap.isSeekable());
trackOutput.assertSampleCount(expectedSampleCount); return extractorOutput;
return trackOutput;
} }
} }
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer.testutil;
import com.google.android.exoplayer.C;
import java.util.Arrays;
import java.util.Locale;
/**
* Helper utility to dump field values.
*/
public final class Dumper {
/**
* Provides custom dump method.
*/
public interface Dumpable {
/**
* Dumps the fields of the object using the {@code dumper}.
* @param dumper The {@link Dumper} to be used to dump fields.
*/
void dump(Dumper dumper);
}
private static final int INDENT_SIZE_IN_SPACES = 2;
private final StringBuilder sb;
private int indent;
public Dumper() {
sb = new StringBuilder();
}
public Dumper add(String field, Object value) {
return addString(field + " = " + value + '\n');
}
public Dumper add(Dumpable object) {
object.dump(this);
return this;
}
public Dumper add(String field, byte[] value) {
String string = String.format(Locale.US, "%s = length %d, hash %X\n", field, value.length,
Arrays.hashCode(value));
return addString(string);
}
public Dumper addTime(String field, long time) {
return add(field, time == C.UNSET_TIME_US ? "UNSET TIME" : time);
}
public Dumper startBlock(String name) {
addString(name + ":\n");
indent += INDENT_SIZE_IN_SPACES;
return this;
}
public Dumper endBlock() {
indent -= INDENT_SIZE_IN_SPACES;
return this;
}
@Override
public String toString() {
return sb.toString();
}
private Dumper addString(String string) {
for (int i = 0; i < indent; i++) {
sb.append(' ');
}
sb.append(string);
return this;
}
}
...@@ -18,15 +18,17 @@ package com.google.android.exoplayer.testutil; ...@@ -18,15 +18,17 @@ package com.google.android.exoplayer.testutil;
import com.google.android.exoplayer.extractor.ExtractorOutput; import com.google.android.exoplayer.extractor.ExtractorOutput;
import com.google.android.exoplayer.extractor.SeekMap; import com.google.android.exoplayer.extractor.SeekMap;
import android.app.Instrumentation;
import android.util.SparseArray; import android.util.SparseArray;
import junit.framework.Assert; import junit.framework.Assert;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.IOException;
/** /**
* A fake {@link ExtractorOutput}. * A fake {@link ExtractorOutput}.
*/ */
public final class FakeExtractorOutput implements ExtractorOutput { public final class FakeExtractorOutput implements ExtractorOutput, Dumper.Dumpable {
private final boolean allowDuplicateTrackIds; private final boolean allowDuplicateTrackIds;
...@@ -86,4 +88,27 @@ public final class FakeExtractorOutput implements ExtractorOutput { ...@@ -86,4 +88,27 @@ public final class FakeExtractorOutput implements ExtractorOutput {
} }
} }
public void assertOutput(Instrumentation instrumentation, String dumpFile) throws IOException {
String dumpExpected = TestUtil.getString(instrumentation, dumpFile);
Assert.assertEquals(dumpExpected, new Dumper().add(this).toString());
}
@Override
public void dump(Dumper dumper) {
if (seekMap != null) {
dumper.startBlock("seekMap")
.add("isSeekable", seekMap.isSeekable())
.addTime("duration", seekMap.getDurationUs())
.add("getPosition(0)", seekMap.getPosition(0))
.endBlock();
}
dumper.add("numberOfTracks", numberOfTracks);
for (int i = 0; i < numberOfTracks; i++) {
dumper.startBlock("track " + trackOutputs.keyAt(i))
.add(trackOutputs.valueAt(i))
.endBlock();
}
dumper.add("tracksEnded", tracksEnded);
}
} }
...@@ -30,7 +30,7 @@ import java.util.Arrays; ...@@ -30,7 +30,7 @@ import java.util.Arrays;
/** /**
* A fake {@link TrackOutput}. * A fake {@link TrackOutput}.
*/ */
public final class FakeTrackOutput implements TrackOutput { public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
private final ArrayList<Long> sampleTimesUs; private final ArrayList<Long> sampleTimesUs;
private final ArrayList<Integer> sampleFlags; private final ArrayList<Integer> sampleFlags;
...@@ -128,4 +128,49 @@ public final class FakeTrackOutput implements TrackOutput { ...@@ -128,4 +128,49 @@ public final class FakeTrackOutput implements TrackOutput {
} }
} }
@Override
public void dump(Dumper dumper) {
dumper.startBlock("format")
.add("bitrate", format.bitrate)
.add("id", format.id)
.add("containerMimeType", format.containerMimeType)
.add("sampleMimeType", format.sampleMimeType)
.add("maxInputSize", format.maxInputSize)
.add("requiresSecureDecryption", format.requiresSecureDecryption)
.add("width", format.width)
.add("height", format.height)
.add("frameRate", format.frameRate)
.add("rotationDegrees", format.rotationDegrees)
.add("pixelWidthHeightRatio", format.pixelWidthHeightRatio)
.add("channelCount", format.channelCount)
.add("sampleRate", format.sampleRate)
.add("pcmEncoding", format.pcmEncoding)
.add("encoderDelay", format.encoderDelay)
.add("encoderPadding", format.encoderPadding)
.add("subsampleOffsetUs", format.subsampleOffsetUs)
.add("selectionFlags", format.selectionFlags)
.add("language", format.language)
.add("drmInitData", format.drmInitData != null ? format.drmInitData.hashCode() : "-");
dumper.startBlock("initializationData");
for (int i = 0; i < format.initializationData.size(); i++) {
dumper.add("data", format.initializationData.get(i));
}
dumper.endBlock().endBlock();
dumper.add("sample count", sampleTimesUs.size());
for (int i = 0; i < sampleTimesUs.size(); i++) {
dumper.startBlock("sample " + i)
.add("time", sampleTimesUs.get(i))
.add("flags", sampleFlags.get(i))
.add("data", getSampleData(i));
byte[] key = sampleEncryptionKeys.get(i);
if (key != null) {
dumper.add("encryption key", key);
}
dumper.endBlock();
}
}
} }
...@@ -153,6 +153,11 @@ public class TestUtil { ...@@ -153,6 +153,11 @@ public class TestUtil {
return Util.toByteArray(is); return Util.toByteArray(is);
} }
public static String getString(Instrumentation instrumentation, String fileName)
throws IOException {
return new String(getByteArray(instrumentation, fileName));
}
private static FakeExtractorInput newExtractorInput(byte[] data) { private static FakeExtractorInput newExtractorInput(byte[] data) {
return new FakeExtractorInput.Builder().setData(data).build(); return new FakeExtractorInput.Builder().setData(data).build();
} }
......
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