Commit 99e699a3 by Dustin

Clean up tests

parent bec8b44b
package com.google.android.exoplayer2.extractor.avi;
import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.util.MimeTypes;
import java.nio.ByteBuffer;
import java.util.HashMap;
......@@ -55,4 +56,20 @@ public class VideoFormat {
public String getMimeType() {
return STREAM_MAP.get(getCompression());
}
@VisibleForTesting
public void setWidth(final int width) {
byteBuffer.putInt(4, width);
}
@VisibleForTesting
public void setHeight(final int height) {
byteBuffer.putInt(8, height);
}
@VisibleForTesting
public void setCompression(final int compression) {
byteBuffer.putInt(16, compression);
}
}
......@@ -20,14 +20,14 @@ import org.junit.runner.RunWith;
public class AviExtractorRoboTest {
@Test
public void parseStream_givenH264StreamList() throws IOException {
public void parseStream_givenXvidStreamList() throws IOException {
final AviExtractor aviExtractor = new AviExtractor();
final FakeExtractorOutput fakeExtractorOutput = new FakeExtractorOutput();
aviExtractor.init(fakeExtractorOutput);
final ListBox streamList = DataHelper.getVideoStreamList();
aviExtractor.parseStream(streamList, 0);
FakeTrackOutput trackOutput = fakeExtractorOutput.track(0, C.TRACK_TYPE_VIDEO);
Assert.assertEquals(MimeTypes.VIDEO_H264, trackOutput.lastFormat.sampleMimeType);
Assert.assertEquals(MimeTypes.VIDEO_MP4V, trackOutput.lastFormat.sampleMimeType);
}
@Test
......
package com.google.android.exoplayer2.extractor.avi;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import java.io.File;
import java.io.FileInputStream;
import com.google.android.exoplayer2.testutil.TestUtil;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
......@@ -19,22 +19,6 @@ public class DataHelper {
static final int AUDIO_SIZE = 256;
static final int AUDIO_ID = 1;
static final int MOVI_OFFSET = 4096;
private static final long AUDIO_US = VIDEO_US / AUDIO_PER_VIDEO;
//Base path "\ExoPlayer\library\extractor\."
private static final File RELATIVE_PATH = new File("../../testdata/src/test/assets/extractordumps/avi/");
public static FakeExtractorInput getInput(final String fileName) throws IOException {
return new FakeExtractorInput.Builder().setData(getBytes(fileName)).build();
}
public static byte[] getBytes(final String fileName) throws IOException {
final File file = new File(RELATIVE_PATH, fileName);
try (FileInputStream in = new FileInputStream(file)) {
final byte[] buffer = new byte[in.available()];
in.read(buffer);
return buffer;
}
}
public static StreamHeaderBox getStreamHeader(int type, int scale, int rate, int length) {
final ByteBuffer byteBuffer = AviExtractor.allocate(0x40);
......@@ -55,20 +39,23 @@ public class DataHelper {
}
public static StreamFormatBox getAacStreamFormat() throws IOException {
final byte[] buffer = getBytes("aac_stream_format.dump");
final Context context = ApplicationProvider.getApplicationContext();
final byte[] buffer = TestUtil.getByteArray(context,"extractordumps/avi/aac_stream_format.dump");
final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
return new StreamFormatBox(StreamFormatBox.STRF, buffer.length, byteBuffer);
}
public static StreamFormatBox getVideoStreamFormat() throws IOException {
final byte[] buffer = getBytes("h264_stream_format.dump");
final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
return new StreamFormatBox(StreamFormatBox.STRF, buffer.length, byteBuffer);
public static StreamFormatBox getVideoStreamFormat() {
final ByteBuffer byteBuffer = AviExtractor.allocate(40);
final VideoFormat videoFormat = new VideoFormat(byteBuffer);
videoFormat.setWidth(720);
videoFormat.setHeight(480);
videoFormat.setCompression(VideoFormat.XVID);
return new StreamFormatBox(StreamFormatBox.STRF, byteBuffer.capacity(), byteBuffer);
}
public static ListBox getVideoStreamList() throws IOException {
public static ListBox getVideoStreamList() {
final StreamHeaderBox streamHeaderBox = getVidsStreamHeader();
final StreamFormatBox streamFormatBox = getVideoStreamFormat();
final ArrayList<Box> list = new ArrayList<>(2);
......@@ -162,8 +149,6 @@ public class DataHelper {
/**
* Get the RIFF header up to AVI Header
* @param bufferSize
* @return
*/
public static ByteBuffer getRiffHeader(int bufferSize, int headerListSize) {
ByteBuffer byteBuffer = AviExtractor.allocate(bufferSize);
......
package com.google.android.exoplayer2.extractor.avi;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import com.google.android.exoplayer2.testutil.TestUtil;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class Mp4vChunkPeekerTest {
private ByteBuffer makeSequence() {
......@@ -30,8 +36,10 @@ public class Mp4vChunkPeekerTest {
public void peek_givenAspectRatio() throws IOException {
final FakeTrackOutput fakeTrackOutput = new FakeTrackOutput(false);
final Format.Builder formatBuilder = new Format.Builder();
final Context context = ApplicationProvider.getApplicationContext();
final byte[] bytes = TestUtil.getByteArray(context, "extractordumps/avi/mp4v_sequence.dump");
final FakeExtractorInput input = new FakeExtractorInput.Builder().setData(bytes).build();
final Mp4vChunkPeeker mp4vChunkPeeker = new Mp4vChunkPeeker(formatBuilder, fakeTrackOutput);
final FakeExtractorInput input = DataHelper.getInput("mp4v_sequence.dump");
mp4vChunkPeeker.peek(input, (int) input.getLength());
Assert.assertEquals(1.2121212, mp4vChunkPeeker.pixelWidthHeightRatio, 0.01);
......
package com.google.android.exoplayer2.extractor.avi;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
......@@ -9,7 +10,8 @@ public class VideoFormatTest {
public void getters_givenVideoStreamFormat() throws IOException {
final StreamFormatBox streamFormatBox = DataHelper.getVideoStreamFormat();
final VideoFormat videoFormat = streamFormatBox.getVideoFormat();
Assert.assertEquals(712, videoFormat.getWidth());
Assert.assertEquals(464, videoFormat.getHeight());
Assert.assertEquals(720, videoFormat.getWidth());
Assert.assertEquals(480, videoFormat.getHeight());
Assert.assertEquals(MimeTypes.VIDEO_MP4V, videoFormat.getMimeType());
}
}
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