aboutsummaryrefslogtreecommitdiff
path: root/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java')
-rw-r--r--third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java70
1 files changed, 67 insertions, 3 deletions
diff --git a/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java b/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
index 7b25c96b..88106ea6 100644
--- a/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
+++ b/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
@@ -3,6 +3,7 @@ package com.bumptech.glide.gifdecoder.test;
import org.junit.Test;
import java.nio.ByteBuffer;
+import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
@@ -33,16 +34,79 @@ public class GifBytesTestUtilTest {
}
@Test
- public void testWriteImageDescriptor() {
+ public void testWriteImageDescriptorWithoutColorTable() {
ByteBuffer buffer = ByteBuffer.allocate(GifBytesTestUtil.IMAGE_DESCRIPTOR_LENGTH);
- GifBytesTestUtil.writeImageDescriptor(buffer, 10, 9, 8, 7);
+ GifBytesTestUtil.writeImageDescriptor(buffer, 10, 9, 8, 7, false, 0);
+
+ byte[] expected = new byte[] {
+ // Image separator.
+ 0x2C,
+ // Image left.
+ 0x00, 0x0A,
+ // Image right.
+ 0x00, 0X09,
+ // Image width.
+ 0x00, 0x08,
+ // Image height.
+ 0x00, 0x07,
+ // Packed field.
+ 0x00
+ };
- byte[] expected = new byte[] { 0x2C, 0x00, 0x0A, 0x00, 0X09, 0x00, 0x08, 0x000, 0x07, 0x00 };
+ assertArrayEquals(expected, buffer.array());
+ }
+
+ @Test
+ public void testWriteImageDescriptorWithColorTable() {
+ ByteBuffer buffer = ByteBuffer.allocate(GifBytesTestUtil.IMAGE_DESCRIPTOR_LENGTH);
+ GifBytesTestUtil.writeImageDescriptor(buffer, 10, 9, 8, 7, true, 4);
+
+ byte packedField =
+ // Set LCT flag
+ (byte) 0x80
+ // Size of color table (2^(N + 1) == 4)
+ | 0x01;
+
+ byte[] expected = new byte[] {
+ // Image separator.
+ 0x2C,
+ // Image left.
+ 0x00, 0x0A,
+ // Image right.
+ 0x00, 0X09,
+ // Image width.
+ 0x00, 0x08,
+ // Image height.
+ 0x00, 0x07,
+ packedField
+ };
assertArrayEquals(expected, buffer.array());
}
@Test
+ public void testWriteColorTable() {
+ final int numColors = 4;
+ ByteBuffer buffer = ByteBuffer.allocate(GifBytesTestUtil.getColorTableLength(numColors));
+ GifBytesTestUtil.writeColorTable(buffer, numColors);
+
+ byte[] expected = new byte[] {
+ // First color.
+ 0x00, 0x00, 0x00,
+ // Second color.
+ 0x00, 0x00, 0x01,
+ // Third color.
+ 0x00, 0x00, 0x02,
+ // Fourth color.
+ 0x00, 0x00, 0x03,
+ };
+
+
+ assertArrayEquals("expected=" + Arrays.toString(expected) + " received=" + Arrays.toString(buffer.array()),
+ expected, buffer.array());
+ }
+
+ @Test
public void testWriteFakeImageData() {
ByteBuffer buffer = ByteBuffer.allocate(4);
GifBytesTestUtil.writeFakeImageData(buffer, 2);