|
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertEquals; |
4 | 4 | import static org.junit.Assert.assertNotNull; |
| 5 | +import static org.junit.Assert.assertTrue; |
| 6 | +import static org.robolectric.Shadows.shadowOf; |
5 | 7 |
|
6 | 8 | import android.graphics.Bitmap; |
7 | 9 | import android.support.annotation.NonNull; |
|
14 | 16 | import org.robolectric.RobolectricTestRunner; |
15 | 17 | import org.robolectric.Shadows; |
16 | 18 | import org.robolectric.annotation.Config; |
| 19 | +import org.robolectric.annotation.Implementation; |
| 20 | +import org.robolectric.annotation.Implements; |
| 21 | +import org.robolectric.shadows.ShadowBitmap; |
17 | 22 |
|
18 | 23 | import java.io.IOException; |
| 24 | +import java.util.Arrays; |
19 | 25 |
|
20 | 26 | /** |
21 | 27 | * Tests for {@link com.bumptech.glide.gifdecoder.GifDecoder}. |
@@ -94,6 +100,45 @@ public void testSettingDataResetsFramePointer() { |
94 | 100 | assertEquals(-1, decoder.getCurrentFrameIndex()); |
95 | 101 | } |
96 | 102 |
|
| 103 | + @Test |
| 104 | + @Config(shadows = { CustomShadowBitmap.class }) |
| 105 | + public void testFirstFrameMustUsingLastFrameDispose() throws IOException { |
| 106 | + byte[] data = TestUtil.resourceToBytes(getClass(), "transparent_dispose.gif"); |
| 107 | + GifHeaderParser headerParser = new GifHeaderParser(); |
| 108 | + headerParser.setData(data); |
| 109 | + GifHeader header = headerParser.parseHeader(); |
| 110 | + GifDecoder decoder = new GifDecoder(provider); |
| 111 | + decoder.setData(header, data); |
| 112 | + decoder.advance(); |
| 113 | + Bitmap firstFrame = decoder.getNextFrame(); |
| 114 | + decoder.advance(); |
| 115 | + decoder.getNextFrame(); |
| 116 | + decoder.advance(); |
| 117 | + Bitmap firstFrameTwice = decoder.getNextFrame(); |
| 118 | + assertTrue(Arrays.equals((((CustomShadowBitmap) shadowOf(firstFrame))).getPixels(), |
| 119 | + (((CustomShadowBitmap) shadowOf(firstFrameTwice))).getPixels())); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Preserve generated bitmap data for checking. |
| 124 | + */ |
| 125 | + @Implements(Bitmap.class) |
| 126 | + public static class CustomShadowBitmap extends ShadowBitmap { |
| 127 | + |
| 128 | + private int[] pixels; |
| 129 | + |
| 130 | + @Implementation |
| 131 | + public void setPixels(int[] pixels, int offset, int stride, |
| 132 | + int x, int y, int width, int height) { |
| 133 | + this.pixels = new int[pixels.length]; |
| 134 | + System.arraycopy(pixels, 0, this.pixels, 0, this.pixels.length); |
| 135 | + } |
| 136 | + |
| 137 | + public int[] getPixels() { |
| 138 | + return pixels; |
| 139 | + } |
| 140 | + } |
| 141 | + |
97 | 142 | private static class MockProvider implements GifDecoder.BitmapProvider { |
98 | 143 |
|
99 | 144 | @NonNull |
|
0 commit comments