aboutsummaryrefslogtreecommitdiff
path: root/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test')
-rw-r--r--third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java25
-rw-r--r--third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java44
2 files changed, 62 insertions, 7 deletions
diff --git a/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java b/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java
index e389deed..b6f3140e 100644
--- a/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java
+++ b/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtil.java
@@ -10,6 +10,8 @@ public class GifBytesTestUtil {
public static final int HEADER_LENGTH = 13;
// Length in bytes.
public static final int IMAGE_DESCRIPTOR_LENGTH = 10;
+ // Length in bytes.
+ public static final int GRAPHICS_CONTROL_EXTENSION_LENGTH = 8;
public static int getColorTableLength(int numColors) {
return 3 * numColors;
@@ -104,6 +106,29 @@ public class GifBytesTestUtil {
out.put((byte) 0);
}
+ public static void writeGraphicsControlExtension(ByteBuffer out, int delayTime) {
+ verifyRemaining(out, GRAPHICS_CONTROL_EXTENSION_LENGTH);
+ verifyShortValues(delayTime);
+
+ // Extension inducer (constant).
+ out.put((byte) 0x21);
+ // Graphic control label (constant).
+ out.put((byte) 0xF9);
+ // Block size (constant).
+ out.put((byte) 0x04);
+ // Packed (disposal method, user input, transparent color flag)
+ out.put((byte) 0x00);
+
+ // Frame delay in 100ths of a second.
+ out.putShort((short) delayTime);
+
+ // Transparent color index.
+ out.put((byte) 0x00);
+
+ // Block terminator (constant).
+ out.put((byte) 0x00);
+ }
+
private static void verifyRemaining(ByteBuffer buffer, int expected) {
if (buffer.remaining() < expected) {
throw new IllegalArgumentException("Must have at least " + expected + " bytes to write");
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 88106ea6..b393265f 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
@@ -19,7 +19,7 @@ public class GifBytesTestUtilTest {
byte[] expected = new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x00, 0x08, 0x00, 0x10, 0x20, 0x00, 0x00};
- assertArrayEquals(expected, buffer.array());
+ assertEquals(expected, buffer);
}
@Test
@@ -30,7 +30,7 @@ public class GifBytesTestUtilTest {
byte[] expected = new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x00, 0x08, 0x00, 0x10, (byte) 0xA4, 0x00,
0x00};
- assertArrayEquals(expected, buffer.array());
+ assertEquals(expected, buffer);
}
@Test
@@ -53,7 +53,7 @@ public class GifBytesTestUtilTest {
0x00
};
- assertArrayEquals(expected, buffer.array());
+ assertEquals(expected, buffer);
}
@Test
@@ -81,7 +81,7 @@ public class GifBytesTestUtilTest {
packedField
};
- assertArrayEquals(expected, buffer.array());
+ assertEquals(expected, buffer);
}
@Test
@@ -102,8 +102,7 @@ public class GifBytesTestUtilTest {
};
- assertArrayEquals("expected=" + Arrays.toString(expected) + " received=" + Arrays.toString(buffer.array()),
- expected, buffer.array());
+ assertEquals(expected, buffer);
}
@Test
@@ -113,6 +112,37 @@ public class GifBytesTestUtilTest {
byte[] expected = new byte[] { 0x02, 0x01, 0x01, 0x00 };
- assertArrayEquals(expected, buffer.array());
+ assertEquals(expected, buffer);
+ }
+
+ @Test
+ public void testWritesGraphicsControlExtension() {
+ short delay = 20;
+ ByteBuffer buffer = ByteBuffer.allocate(GifBytesTestUtil.GRAPHICS_CONTROL_EXTENSION_LENGTH);
+ byte[] expected = new byte[] {
+ // Extension inducer.
+ 0x21,
+ // Graphic control label.
+ (byte) 0xF9,
+ // Block size.
+ 0x04,
+ // Packed byte.
+ 0x00,
+ // Frame delay.
+ 0x00,
+ 0x14,
+ // Transparent color index.
+ 0x00,
+ // block terminator.
+ 0x00
+ };
+
+ GifBytesTestUtil.writeGraphicsControlExtension(buffer, delay);
+ assertEquals(expected, buffer);
+ }
+
+ private static void assertEquals(byte[] expected, ByteBuffer buffer) {
+ assertArrayEquals("expected=" + Arrays.toString(expected) + " received=" + Arrays.toString(buffer.array()),
+ expected, buffer.array());
}
}