mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 11:05:29 -04:00
New test cases.
Better exception handling of IMAGEERROR.
This commit is contained in:
parent
e712df3862
commit
926359d9d2
@ -59,7 +59,7 @@ public final class BufferedImageFactory {
|
|||||||
private int percentageDone;
|
private int percentageDone;
|
||||||
|
|
||||||
private ImageProducer producer;
|
private ImageProducer producer;
|
||||||
private boolean error;
|
private ImageConversionException consumerException;
|
||||||
private volatile boolean fetching;
|
private volatile boolean fetching;
|
||||||
private boolean readColorModelOnly;
|
private boolean readColorModelOnly;
|
||||||
|
|
||||||
@ -217,8 +217,8 @@ public final class BufferedImageFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (consumerException != null) {
|
||||||
throw new ImageConversionException("Image conversion failed: ImageConsumer.IMAGEERROR.");
|
throw new ImageConversionException("Image conversion failed: " + consumerException.getMessage(), consumerException);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pColorModelOnly) {
|
if (pColorModelOnly) {
|
||||||
@ -475,8 +475,7 @@ public final class BufferedImageFactory {
|
|||||||
|
|
||||||
switch (pStatus) {
|
switch (pStatus) {
|
||||||
case ImageConsumer.IMAGEERROR:
|
case ImageConsumer.IMAGEERROR:
|
||||||
Thread.dumpStack();
|
consumerException = new ImageConversionException("ImageConsumer.IMAGEERROR");
|
||||||
error = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.twelvemonkeys.image;
|
package com.twelvemonkeys.image;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -7,9 +8,11 @@ import java.awt.color.ColorSpace;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.ColorModel;
|
import java.awt.image.ColorModel;
|
||||||
import java.awt.image.ImageProducer;
|
import java.awt.image.ImageProducer;
|
||||||
|
import java.awt.image.IndexColorModel;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BufferedImageFactoryTestCase
|
* BufferedImageFactoryTestCase
|
||||||
@ -29,19 +32,24 @@ public class BufferedImageFactoryTestCase {
|
|||||||
new BufferedImageFactory((ImageProducer) null);
|
new BufferedImageFactory((ImageProducer) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null); // - NPE in Toolkit, ok
|
// NPE in Toolkit, ok
|
||||||
|
@Test(expected = RuntimeException.class)
|
||||||
|
public void testGetBufferedImageErrorSourceByteArray() {
|
||||||
|
Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null);
|
||||||
|
|
||||||
@Test(timeout = 1000, expected = IllegalArgumentException.class)
|
new BufferedImageFactory(source);
|
||||||
public void testGetBufferedImageErrorSourceIP() {
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testGetBufferedImageErrorSourceImageProducer() {
|
||||||
Image source = Toolkit.getDefaultToolkit().createImage((ImageProducer) null);
|
Image source = Toolkit.getDefaultToolkit().createImage((ImageProducer) null);
|
||||||
|
|
||||||
new BufferedImageFactory(source);
|
new BufferedImageFactory(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This is a quite serious bug, but it can be argued that the bug is in the
|
// TODO: This is a quite serious bug, however, the bug is in the Toolkit, allowing such images in the first place...
|
||||||
// Toolkit, allowing such images in the first place... In any case, there's
|
// In any case, there's not much we can do, except until someone is bored and kills the app/thread... :-P
|
||||||
// not much we can do, except until someone is bored and kills the app... :-P
|
@Ignore("Bug in Toolkit")
|
||||||
/*
|
|
||||||
@Test(timeout = 1000, expected = ImageConversionException.class)
|
@Test(timeout = 1000, expected = ImageConversionException.class)
|
||||||
public void testGetBufferedImageErrorSourceString() {
|
public void testGetBufferedImageErrorSourceString() {
|
||||||
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
||||||
@ -49,7 +57,6 @@ public class BufferedImageFactoryTestCase {
|
|||||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||||
factory.getBufferedImage();
|
factory.getBufferedImage();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// This is a little random, and it would be nicer if we could throw an IllegalArgumentException on create.
|
// This is a little random, and it would be nicer if we could throw an IllegalArgumentException on create.
|
||||||
// Unfortunately, the API doesn't allow this...
|
// Unfortunately, the API doesn't allow this...
|
||||||
@ -94,7 +101,53 @@ public class BufferedImageFactoryTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test a GIF or PNG with PLTE chunk, and make sure we get an IndexColorModel
|
@Test
|
||||||
|
public void testGetBufferedImageGIF() {
|
||||||
|
URL resource = getClass().getResource("/tux.gif");
|
||||||
|
assertNotNull(resource);
|
||||||
|
Image source = Toolkit.getDefaultToolkit().createImage(resource);
|
||||||
|
assertNotNull(source);
|
||||||
|
|
||||||
|
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||||
|
BufferedImage image = factory.getBufferedImage();
|
||||||
|
|
||||||
|
assertEquals(250, image.getWidth());
|
||||||
|
assertEquals(250, image.getHeight());
|
||||||
|
|
||||||
|
assertEquals(Transparency.BITMASK, image.getTransparency());
|
||||||
|
|
||||||
|
// All corners of image should be fully transparent
|
||||||
|
assertEquals(0, image.getRGB(0, 0) >>> 24);
|
||||||
|
assertEquals(0, image.getRGB(249, 0) >>> 24);
|
||||||
|
assertEquals(0, image.getRGB(0, 249) >>> 24);
|
||||||
|
assertEquals(0, image.getRGB(249, 249) >>> 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetColorModelGIF() {
|
||||||
|
URL resource = getClass().getResource("/tux.gif");
|
||||||
|
assertNotNull(resource);
|
||||||
|
Image source = Toolkit.getDefaultToolkit().createImage(resource);
|
||||||
|
assertNotNull(source);
|
||||||
|
|
||||||
|
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||||
|
ColorModel colorModel = factory.getColorModel();
|
||||||
|
|
||||||
|
assertNotNull(colorModel);
|
||||||
|
|
||||||
|
assertEquals(3, colorModel.getNumColorComponents());
|
||||||
|
assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colorModel.getColorSpace());
|
||||||
|
assertTrue(colorModel instanceof IndexColorModel);
|
||||||
|
|
||||||
|
assertTrue(colorModel.hasAlpha());
|
||||||
|
assertEquals(4, colorModel.getNumComponents());
|
||||||
|
assertTrue(((IndexColorModel) colorModel).getTransparentPixel() >= 0);
|
||||||
|
assertEquals(Transparency.BITMASK, colorModel.getTransparency());
|
||||||
|
|
||||||
|
for (int i = 0; i < colorModel.getNumComponents(); i++) {
|
||||||
|
assertEquals(8, colorModel.getComponentSize(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBufferedImageSubsampled() {
|
public void testGetBufferedImageSubsampled() {
|
||||||
|
BIN
common/common-image/src/test/resources/tux.gif
Normal file
BIN
common/common-image/src/test/resources/tux.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
Loading…
x
Reference in New Issue
Block a user