Commit 4c434005 by olly Committed by Oliver Woodman

Remove/simplify some extractor tests.

We have our snazzy new file-based extractor tests now,
and the other ones have historically proven way more
hassle than they're worth (e.g. I spent a good few hours
once just trying to work out how to fix the Mp4 extractor
test, having established it was the test and not the
code that was broken!).

I think some more can go from the ogg package, but leaving
in place for now because it's a bit less clear what to
get rid of.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125330072
parent 53cc88e2
......@@ -24,7 +24,7 @@ import junit.framework.TestCase;
*/
public class ExtractorTest extends TestCase {
public static void testContants() {
public static void testConstants() {
// Sanity check that constant values match those defined by {@link C}.
assertEquals(C.RESULT_END_OF_INPUT, Extractor.RESULT_END_OF_INPUT);
// Sanity check that the other constant values don't overlap.
......
/*
* 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.extractor.ogg;
import com.google.android.exoplayer.extractor.Extractor;
import com.google.android.exoplayer.testutil.TestUtil;
import com.google.android.exoplayer.testutil.TestUtil.ExtractorFactory;
import android.test.InstrumentationTestCase;
/**
* Unit test for {@link OpusReader}.
*/
public final class OggExtractorFileTests extends InstrumentationTestCase {
private static final ExtractorFactory OGG_EXTRACTOR_FACTORY = new ExtractorFactory() {
@Override
public Extractor create() {
return new OggExtractor();
}
};
public void testOpus() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear.opus", getInstrumentation());
}
public void testFlac() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_flac.ogg", getInstrumentation());
}
public void testFlacNoSeektable() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_flac_noseektable.ogg",
getInstrumentation());
}
public void testVorbis() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_vorbis.ogg", getInstrumentation());
}
}
......@@ -15,24 +15,42 @@
*/
package com.google.android.exoplayer.extractor.ogg;
import com.google.android.exoplayer.extractor.Extractor;
import com.google.android.exoplayer.testutil.FakeExtractorInput;
import com.google.android.exoplayer.testutil.TestUtil;
import com.google.android.exoplayer.testutil.TestUtil.ExtractorFactory;
import junit.framework.TestCase;
import android.test.InstrumentationTestCase;
import java.io.IOException;
/**
* Unit test for {@link OggExtractor}.
*/
public final class OggExtractorTest extends TestCase {
public final class OggExtractorTest extends InstrumentationTestCase {
private OggExtractor extractor;
private static final ExtractorFactory OGG_EXTRACTOR_FACTORY = new ExtractorFactory() {
@Override
public Extractor create() {
return new OggExtractor();
}
};
@Override
public void setUp() throws Exception {
super.setUp();
extractor = new OggExtractor();
public void testOpus() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear.opus", getInstrumentation());
}
public void testFlac() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_flac.ogg", getInstrumentation());
}
public void testFlacNoSeektable() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_flac_noseektable.ogg",
getInstrumentation());
}
public void testVorbis() throws Exception {
TestUtil.assertOutput(OGG_EXTRACTOR_FACTORY, "ogg/bear_vorbis.ogg", getInstrumentation());
}
public void testSniffVorbis() throws Exception {
......@@ -80,7 +98,7 @@ public final class OggExtractorTest extends TestCase {
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data)
.setSimulateIOErrors(true).setSimulateUnknownLength(true).setSimulatePartialReads(true)
.build();
return TestUtil.sniffTestData(extractor, input);
return TestUtil.sniffTestData(OGG_EXTRACTOR_FACTORY.create(), input);
}
}
......@@ -15,7 +15,7 @@
*/
package com.google.android.exoplayer.extractor.ogg;
import com.google.android.exoplayer.util.ParsableBitArray;
import com.google.android.exoplayer.testutil.TestUtil;
import junit.framework.TestCase;
......@@ -25,9 +25,7 @@ import junit.framework.TestCase;
public final class VorbisBitArrayTest extends TestCase {
public void testReadBit() {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0x5c, 0x50
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0x5c, 0x50));
assertFalse(bitArray.readBit());
assertFalse(bitArray.readBit());
......@@ -56,9 +54,7 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testSkipBits() {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xF0, 0x0F
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F));
bitArray.skipBits(10);
assertEquals(10, bitArray.getPosition());
......@@ -79,9 +75,7 @@ public final class VorbisBitArrayTest extends TestCase {
public void testSkipBitsThrowsErrorIfEOB() {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xF0, 0x0F
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F));
try {
bitArray.skipBits(17);
......@@ -90,9 +84,7 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testGetPosition() throws Exception {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xF0, 0x0F
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F));
assertEquals(0, bitArray.getPosition());
bitArray.readBit();
......@@ -104,9 +96,7 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testSetPosition() throws Exception {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xF0, 0x0F
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F));
assertEquals(0, bitArray.getPosition());
bitArray.setPosition(4);
......@@ -121,9 +111,7 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testSetPositionIllegalPositions() throws Exception {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xF0, 0x0F
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F));
try {
bitArray.setPosition(16);
......@@ -141,19 +129,14 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testReadInt32() {
byte[] data = {(byte) 0xF0, 0x0F, (byte) 0xF0, 0x0F};
VorbisBitArray lsb = new VorbisBitArray(data);
assertEquals(0x0FF00FF0, lsb.readBits(32));
data = new byte[]{0x0F, (byte) 0xF0, 0x0F, (byte) 0xF0};
lsb = new VorbisBitArray(data);
assertEquals(0xF00FF00F, lsb.readBits(32));
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F, 0xF0, 0x0F));
assertEquals(0x0FF00FF0, bitArray.readBits(32));
bitArray = new VorbisBitArray(TestUtil.createByteArray(0x0F, 0xF0, 0x0F, 0xF0));
assertEquals(0xF00FF00F, bitArray.readBits(32));
}
public void testReadBits() throws Exception {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0x03, 0x22
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0x03, 0x22));
assertEquals(3, bitArray.readBits(2));
bitArray.skipBits(6);
......@@ -166,18 +149,14 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testRead4BitsBeyondBoundary() throws Exception {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
0x2e, 0x10
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0x2e, 0x10));
assertEquals(0x2e, bitArray.readBits(7));
assertEquals(7, bitArray.getPosition());
assertEquals(0x0, bitArray.readBits(4));
}
public void testReadBitsBeyondByteBoundaries() throws Exception {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xFF, (byte) 0x0F, (byte) 0xFF, (byte) 0x0F
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xFF, 0x0F, 0xFF, 0x0F));
assertEquals(0x0FFF0FFF, bitArray.readBits(32));
......@@ -202,9 +181,7 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testReadBitsIllegalLengths() throws Exception {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0x03, 0x22, 0x30
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0x03, 0x22, 0x30));
// reading zero bits gets 0 without advancing position
// (like a zero-bit read is defined to yield zer0)
......@@ -222,9 +199,7 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testLimit() {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xc0, 0x02
}, 1);
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xc0, 0x02), 1);
try {
bitArray.skipBits(9);
......@@ -240,7 +215,8 @@ public final class VorbisBitArrayTest extends TestCase {
assertEquals(0, bitArray.getPosition());
}
bitArray.readBits(8);
int byteValue = bitArray.readBits(8);
assertEquals(0xc0, byteValue);
assertEquals(8, bitArray.getPosition());
try {
bitArray.readBit();
......@@ -251,9 +227,8 @@ public final class VorbisBitArrayTest extends TestCase {
}
public void testBitsLeft() {
VorbisBitArray bitArray = new VorbisBitArray(new byte[]{
(byte) 0xc0, 0x02
});
VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xc0, 0x02));
assertEquals(16, bitArray.bitsLeft());
assertEquals(bitArray.limit(), bitArray.getPosition() + bitArray.bitsLeft());
......@@ -293,44 +268,4 @@ public final class VorbisBitArrayTest extends TestCase {
}
}
public void testReadBitCompareWithMSb() {
byte[] data = {0x0F};
VorbisBitArray lsb = new VorbisBitArray(data);
ParsableBitArray msb = new ParsableBitArray(data);
assertEquals(lsb.readBit(), !msb.readBit());
assertEquals(lsb.readBit(), !msb.readBit());
assertEquals(lsb.readBit(), !msb.readBit());
assertEquals(lsb.readBit(), !msb.readBit());
assertEquals(lsb.readBit(), !msb.readBit());
assertEquals(lsb.readBit(), !msb.readBit());
assertEquals(lsb.readBit(), !msb.readBit());
assertEquals(lsb.readBit(), !msb.readBit());
}
public void testReadBitsCompareWithMSb() {
byte[] data = {0x0F};
VorbisBitArray lsb = new VorbisBitArray(data);
ParsableBitArray msb = new ParsableBitArray(data);
assertEquals(15, lsb.readBits(4));
assertEquals(lsb.readBits(4), msb.readBits(4));
assertEquals(15, msb.readBits(4));
}
public void testReadBitsCompareWithMSbBeyondByteBoundary() {
byte[] data = {(byte) 0xF0, 0x0F};
VorbisBitArray lsb = new VorbisBitArray(data);
ParsableBitArray msb = new ParsableBitArray(data);
assertEquals(0x00, lsb.readBits(4));
assertEquals(0x0F, msb.readBits(4));
assertEquals(0xFF, lsb.readBits(8));
assertEquals(0x00, msb.readBits(8));
assertEquals(0x00, lsb.readBits(4));
assertEquals(0x0F, msb.readBits(4));
}
}
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer.extractor.ogg;
import com.google.android.exoplayer.extractor.ExtractorInput;
import com.google.android.exoplayer.extractor.ogg.VorbisReader.VorbisSetup;
import com.google.android.exoplayer.testutil.FakeExtractorInput;
import com.google.android.exoplayer.testutil.FakeExtractorInput.SimulatedIOException;
......@@ -29,14 +30,6 @@ import java.io.IOException;
*/
public final class VorbisReaderTest extends TestCase {
private VorbisReader extractor;
@Override
public void setUp() throws Exception {
super.setUp();
extractor = new VorbisReader();
}
public void testReadBits() throws Exception {
assertEquals(0, VorbisReader.readBits((byte) 0x00, 2, 2));
assertEquals(1, VorbisReader.readBits((byte) 0x02, 1, 1));
......@@ -57,7 +50,11 @@ public final class VorbisReaderTest extends TestCase {
public void testReadSetupHeadersWithIOExceptions() throws IOException, InterruptedException {
byte[] data = TestData.getVorbisHeaderPages();
VorbisReader.VorbisSetup vorbisSetup = readSetupHeaders(createInput(data));
ExtractorInput input = new FakeExtractorInput.Builder().setData(data).setSimulateIOErrors(true)
.setSimulateUnknownLength(true).setSimulatePartialReads(true).build();
VorbisReader reader = new VorbisReader();
VorbisReader.VorbisSetup vorbisSetup = readSetupHeaders(reader, input);
assertNotNull(vorbisSetup.idHeader);
assertNotNull(vorbisSetup.commentHeader);
......@@ -88,12 +85,7 @@ public final class VorbisReaderTest extends TestCase {
assertTrue(vorbisSetup.modes[1].blockFlag);
}
private static FakeExtractorInput createInput(byte[] data) {
return new FakeExtractorInput.Builder().setData(data).setSimulateIOErrors(true)
.setSimulateUnknownLength(true).setSimulatePartialReads(true).build();
}
private VorbisSetup readSetupHeaders(FakeExtractorInput input)
private static VorbisSetup readSetupHeaders(VorbisReader reader, ExtractorInput input)
throws IOException, InterruptedException {
OggPacket oggPacket = new OggPacket();
while (true) {
......@@ -101,7 +93,7 @@ public final class VorbisReaderTest extends TestCase {
if (!oggPacket.populate(input)) {
fail();
}
VorbisSetup vorbisSetup = extractor.readSetupHeaders(oggPacket.getPayload());
VorbisSetup vorbisSetup = reader.readSetupHeaders(oggPacket.getPayload());
if (vorbisSetup != null) {
return vorbisSetup;
}
......
......@@ -90,13 +90,13 @@ public final class VorbisUtilTest extends TestCase {
public void testVerifyVorbisHeaderCapturePattern() throws ParserException {
ParsableByteArray header = new ParsableByteArray(
new byte[]{0x01, 'v', 'o', 'r', 'b', 'i', 's'});
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
assertEquals(true, VorbisUtil.verifyVorbisHeaderCapturePattern(0x01, header, false));
}
public void testVerifyVorbisHeaderCapturePatternInvalidHeader() {
ParsableByteArray header = new ParsableByteArray(
new byte[]{0x01, 'v', 'o', 'r', 'b', 'i', 's'});
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
try {
VorbisUtil.verifyVorbisHeaderCapturePattern(0x99, header, false);
fail();
......@@ -107,13 +107,13 @@ public final class VorbisUtilTest extends TestCase {
public void testVerifyVorbisHeaderCapturePatternInvalidHeaderQuite() throws ParserException {
ParsableByteArray header = new ParsableByteArray(
new byte[]{0x01, 'v', 'o', 'r', 'b', 'i', 's'});
new byte[] {0x01, 'v', 'o', 'r', 'b', 'i', 's'});
assertFalse(VorbisUtil.verifyVorbisHeaderCapturePattern(0x99, header, true));
}
public void testVerifyVorbisHeaderCapturePatternInvalidPattern() {
ParsableByteArray header = new ParsableByteArray(
new byte[]{0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's'});
new byte[] {0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's'});
try {
VorbisUtil.verifyVorbisHeaderCapturePattern(0x01, header, false);
fail();
......@@ -125,7 +125,7 @@ public final class VorbisUtilTest extends TestCase {
public void testVerifyVorbisHeaderCapturePatternQuiteInvalidPatternQuite()
throws ParserException {
ParsableByteArray header = new ParsableByteArray(
new byte[]{0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's'});
new byte[] {0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's'});
assertFalse(VorbisUtil.verifyVorbisHeaderCapturePattern(0x01, header, true));
}
......
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