modules/graphics/src/test/java/com/sun/javafx/iio/ImageStorageTest.java

Print this page
rev 8116 : RT-23180: Allow animated GIF to be loaded partially if it has errors in the data stream

@@ -24,18 +24,22 @@
  */
 
 package com.sun.javafx.iio;
 
 import com.sun.javafx.iio.common.ImageTools;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
 import org.junit.ComparisonFailure;
 import org.junit.Test;
 
 public class ImageStorageTest {
+    private String getResourcePath(String path) {
+        return this.getClass().getResource(path).toString();
+    }
+
     @Test
     public void createImageFromNoExtensionURL() throws ImageStorageException {
-        String path = this.getClass().getResource("testpngnoextension").toString();
+        String path = getResourcePath("testpngnoextension");
         assertNotNull(ImageStorage.loadAll(path, null, 0, 0, true, 2.0f, true));
     }
 
     @Test
     public void testImageNames() {

@@ -55,6 +59,26 @@
             String name2x = ImageTools.getScaledImageName(names[0]);
             if (name2x.equals(names[1])) continue;
             throw new ComparisonFailure("Scaled image names don't match", names[1], name2x);
         }
     }
+
+    @Test
+    public void testCompleteAnimation() throws ImageStorageException {
+        String path = getResourcePath("gif/animation/test3Frames.gif");
+        ImageFrame[] frames = ImageStorage.loadAll(path, null, 0, 0, true, 1.0f, true);
+        assertEquals(frames.length, 3);
+    }
+
+    @Test
+    public void testIncompleteAnimation() throws ImageStorageException {
+        String path = getResourcePath("gif/animation/test3rdFrameIncomplete.gif");
+        ImageFrame[] frames = ImageStorage.loadAll(path, null, 0, 0, true, 1.0f, true);
+        assertEquals(frames.length, 2);
+    }
+
+    @Test(expected = ImageStorageException.class)
+    public void testCorruptFirstFrame() throws ImageStorageException  {
+        String path = getResourcePath("gif/animation/testBad.gif");
+        ImageStorage.loadAll(path, null, 0, 0, false, 1.0f, false);
+    }
 }