aboutsummaryrefslogtreecommitdiff
path: root/third_party/gif_decoder/src/androidTest/java/com/bumptech/glide/gifdecoder/test/GifBytesTestUtilTest.java
blob: 7b25c96b42b403eceb076a82b95b2bbea2cde481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.bumptech.glide.gifdecoder.test;

import org.junit.Test;

import java.nio.ByteBuffer;

import static org.junit.Assert.assertArrayEquals;

/**
 * Tests for {@link com.bumptech.glide.gifdecoder.test.GifBytesTestUtil}.
 */
public class GifBytesTestUtilTest {

    @Test
    public void testWriteHeaderAndLsdWithoutGct() {
        ByteBuffer buffer = ByteBuffer.allocate(GifBytesTestUtil.HEADER_LENGTH);
        GifBytesTestUtil.writeHeaderAndLsd(buffer, 8, 16, false, 0);

        byte[] expected = new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x00, 0x08, 0x00, 0x10, 0x20, 0x00, 0x00};

        assertArrayEquals(expected, buffer.array());
    }

    @Test
    public void testWriteHeaderAndLsdWithGct() {
        ByteBuffer buffer = ByteBuffer.allocate(GifBytesTestUtil.HEADER_LENGTH);
        GifBytesTestUtil.writeHeaderAndLsd(buffer, 8, 16, true, 4);

        byte[] expected = new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x00, 0x08, 0x00, 0x10, (byte) 0xA4, 0x00,
                0x00};

        assertArrayEquals(expected, buffer.array());
    }

    @Test
    public void testWriteImageDescriptor() {
        ByteBuffer buffer = ByteBuffer.allocate(GifBytesTestUtil.IMAGE_DESCRIPTOR_LENGTH);
        GifBytesTestUtil.writeImageDescriptor(buffer, 10, 9, 8, 7);

        byte[] expected = new byte[] { 0x2C, 0x00, 0x0A, 0x00, 0X09, 0x00, 0x08, 0x000, 0x07, 0x00 };

        assertArrayEquals(expected, buffer.array());
    }

    @Test
    public void testWriteFakeImageData() {
        ByteBuffer buffer = ByteBuffer.allocate(4);
        GifBytesTestUtil.writeFakeImageData(buffer, 2);

        byte[] expected = new byte[] { 0x02, 0x01, 0x01, 0x00 };

        assertArrayEquals(expected, buffer.array());
    }
}