mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-27 00:00:02 -04:00
- Implemented test for explicit destination type in ImageReaderBase.
- Implemented/enabled more test cases - Fixed broken tests in various readers
This commit is contained in:
+96
-32
@@ -540,14 +540,14 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
|
||||
}
|
||||
|
||||
public void readAsRenderedImageIndexNegative() {
|
||||
public void testReadAsRenderedImageIndexNegative() {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
BufferedImage image = null;
|
||||
RenderedImage image = null;
|
||||
try {
|
||||
image = reader.read(-1, reader.getDefaultReadParam());
|
||||
image = reader.readAsRenderedImage(-1, reader.getDefaultReadParam());
|
||||
fail("Read image with illegal index");
|
||||
}
|
||||
catch (IndexOutOfBoundsException expected) {
|
||||
@@ -559,14 +559,14 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
assertNull(image);
|
||||
}
|
||||
|
||||
public void readAsRenderedImageIndexOutOfBounds() {
|
||||
public void testReadAsRenderedImageIndexOutOfBounds() {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
BufferedImage image = null;
|
||||
RenderedImage image = null;
|
||||
try {
|
||||
image = reader.read(11, reader.getDefaultReadParam());
|
||||
image = reader.readAsRenderedImage(reader.getNumImages(true), reader.getDefaultReadParam());
|
||||
fail("Read image with index out of bounds");
|
||||
}
|
||||
catch (IndexOutOfBoundsException expected) {
|
||||
@@ -578,7 +578,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
assertNull(image);
|
||||
}
|
||||
|
||||
public void readAsRenderedImageNoInput() {
|
||||
public void testReadAsRenderedImageNoInput() {
|
||||
ImageReader reader = createReader();
|
||||
// Do not set input
|
||||
|
||||
@@ -596,7 +596,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
assertNull(image);
|
||||
}
|
||||
|
||||
public void readAsRenderedImage() {
|
||||
public void testReadAsRenderedImage() {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
@@ -615,7 +615,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
data.getDimension(0).height, image.getHeight());
|
||||
}
|
||||
|
||||
public void readAsRenderedImageWithDefaultParam() {
|
||||
public void testReadAsRenderedImageWithDefaultParam() {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
@@ -1181,28 +1181,93 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
assertSame(destination, result);
|
||||
}
|
||||
|
||||
// TODO: This test is foobar..
|
||||
public void testSetDestinationIllegal() throws IOException {
|
||||
// TODO: Test that the reader throws IIOException if given an illegal destination
|
||||
final ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
|
||||
|
||||
List<ImageTypeSpecifier> illegalTypes = createIllegalTypes(reader.getImageTypes(0));
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
// TODO: Should either be a type from image type specifiers or throw IIOException in read
|
||||
BufferedImage destination = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
|
||||
param.setDestination(destination);
|
||||
for (ImageTypeSpecifier illegalType : illegalTypes) {
|
||||
BufferedImage destination = illegalType.createBufferedImage(50, 50);
|
||||
param.setDestination(destination);
|
||||
|
||||
try {
|
||||
reader.read(0, param);
|
||||
fail("Expected to throw exception with wrong type specifier");
|
||||
try {
|
||||
reader.read(0, param);
|
||||
|
||||
// NOTE: We allow the reader to read, as it's inconvenient to test all possible cases.
|
||||
// However, it may NOT fail with any other exception in that case.
|
||||
System.err.println("WARNING: Reader does not throw exception with non-declared destination: " + destination);
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
// TODO: This is thrown by ImageReader.getDestination. But are we happy with that?
|
||||
// The problem is that the checkReadParamBandSettings throws IllegalArgumentException, which seems more appropriate...
|
||||
String message = expected.getMessage();
|
||||
assertTrue("Wrong message: " + message, message.toLowerCase().contains("destination"));
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
String message = expected.getMessage();
|
||||
assertTrue("Wrong message: " + message, message.toLowerCase().contains("dest"));
|
||||
}
|
||||
}
|
||||
catch (IIOException e) {
|
||||
assertTrue(e.getMessage().toLowerCase().contains("type"));
|
||||
}
|
||||
|
||||
public void testSetDestinationTypeIllegal() throws IOException {
|
||||
final ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
List<ImageTypeSpecifier> illegalTypes = createIllegalTypes(reader.getImageTypes(0));
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
for (ImageTypeSpecifier illegalType : illegalTypes) {
|
||||
param.setDestinationType(illegalType);
|
||||
|
||||
try {
|
||||
reader.read(0, param);
|
||||
fail("Expected to throw exception with illegal type specifier");
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
// TODO: This is thrown by ImageReader.getDestination. But are we happy with that?
|
||||
String message = expected.getMessage();
|
||||
assertTrue(message.toLowerCase().contains("destination"));
|
||||
assertTrue(message.toLowerCase().contains("type"));
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
String message = expected.getMessage();
|
||||
assertTrue(message.toLowerCase().contains("destination"));
|
||||
assertTrue(message.toLowerCase().contains("type"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<ImageTypeSpecifier> createIllegalTypes(Iterator<ImageTypeSpecifier> pValidTypes) {
|
||||
List<ImageTypeSpecifier> allTypes = new ArrayList<ImageTypeSpecifier>();
|
||||
for (int i = BufferedImage.TYPE_INT_RGB; i < BufferedImage.TYPE_BYTE_INDEXED; i++) {
|
||||
allTypes.add(ImageTypeSpecifier.createFromBufferedImageType(i));
|
||||
}
|
||||
|
||||
List<ImageTypeSpecifier> illegalTypes = new ArrayList<ImageTypeSpecifier>(allTypes);
|
||||
while (pValidTypes.hasNext()) {
|
||||
ImageTypeSpecifier valid = pValidTypes.next();
|
||||
boolean removed = illegalTypes.remove(valid);
|
||||
|
||||
// TODO: 4BYTE_ABGR (6) and 4BYTE_ABGR_PRE (7) is essentially the same type...
|
||||
// !#$#§%$! ImageTypeSpecifier.equals is not well-defined
|
||||
if (!removed) {
|
||||
for (Iterator<ImageTypeSpecifier> iterator = illegalTypes.iterator(); iterator.hasNext();) {
|
||||
ImageTypeSpecifier illegalType = iterator.next();
|
||||
if (illegalType.getBufferedImageType() == valid.getBufferedImageType()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return illegalTypes;
|
||||
}
|
||||
|
||||
// TODO: Test dest offset + destination set?
|
||||
public void testSetDestinationOffset() throws IOException {
|
||||
final ImageReader reader = createReader();
|
||||
@@ -1266,18 +1331,17 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
}
|
||||
}
|
||||
|
||||
public void testSetDestinationTypeIllegal() throws IOException {
|
||||
throw new UnsupportedOperationException("Method testSetDestinationTypeIllegal not implemented"); // TODO: Implement
|
||||
}
|
||||
|
||||
public void testSetDestinationBands() throws IOException {
|
||||
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||
}
|
||||
|
||||
public void testSetSourceBands() throws IOException {
|
||||
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||
}
|
||||
|
||||
// public void testSetDestinationTypeIllegal() throws IOException {
|
||||
// throw new UnsupportedOperationException("Method testSetDestinationTypeIllegal not implemented"); // TODO: Implement
|
||||
// }
|
||||
//
|
||||
// public void testSetDestinationBands() throws IOException {
|
||||
// throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||
// }
|
||||
//
|
||||
// public void testSetSourceBands() throws IOException {
|
||||
// throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||
// }
|
||||
|
||||
protected URL getClassLoaderResource(final String pName) {
|
||||
return getClass().getResource(pName);
|
||||
|
||||
Reference in New Issue
Block a user