public void testSetInput() { // Should just pass with no exceptions ImageReader reader = createReader(); assertNotNull(reader); for (TestData data : getTestData()) { reader.setInput(data.getInputStream()); } }
public void testSetDestinationOffsetNull() throws IOException { final ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); try { param.setDestinationOffset(null); fail("Null offset not allowed"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().toLowerCase().contains("offset")); } }
public void testGetMinIndex() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int num = 0; try { num = reader.getMinIndex(); } catch (IllegalStateException ignore) { } assertEquals(0, num); }
public void testGetFormatName() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); String name = null; try { name = reader.getFormatName(); } catch (IOException e) { fail(e.getMessage()); } assertNotNull(name); }
public void testGetAspectratio() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); float aspect = 0f; try { aspect = reader.getAspectRatio(0); } catch (IOException e) { fail("Could not read image aspectratio" + e); } Dimension d = data.getDimension(0); assertEquals("Wrong aspect aspectratio", d.getWidth() / d.getHeight(), aspect, 0.001); }
public void testReRead() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream(), false); // Explicitly allow repositioning, even though it's the default BufferedImage first = reader.read(0); assertNotNull(first); BufferedImage second = reader.read(0); assertNotNull(second); // TODO: These images should be exactly the same, but there's no equals for images assertEquals(first.getType(), second.getType()); assertEquals(first.getWidth(), second.getWidth()); assertEquals(first.getHeight(), second.getHeight()); }
public void testReadWithSourceRegionParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); param.setSourceRegion(new Rectangle(0, 0, 10, 10)); BufferedImage image = null; try { image = reader.read(0, param); } catch (IOException e) { fail("Image could not be read: " + e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), 10, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), 10, image.getHeight()); }
public void testReadWithNullParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, null); } catch (IOException e) { fail("Image could not be read: " + e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
public void testSetDestinationOffset() throws IOException { final ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); Point point = new Point(37, 42); param.setDestinationOffset(point); BufferedImage image = reader.read(0, param); assertNotNull(image); assertEquals(reader.getWidth(0) + point.x, image.getWidth()); assertEquals(reader.getHeight(0) + point.y, image.getHeight()); }
public void testGetHeight() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int height = 0; try { height = reader.getHeight(0); } catch (IOException e) { fail("Could not read image height: " + e); } assertEquals("Wrong height reported", data.getDimension(0).height, height); }
public void testReadWithNewParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, new ImageReadParam()); } catch (IOException e) { fail("Image could not be read: " + e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
public void testGetWidth() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); int width = 0; try { width = reader.getWidth(0); } catch (IOException e) { fail("Could not read image width: " + e); } assertEquals("Wrong width reported", data.getDimension(0).width, width); }
public void testReadAsRenderedImage() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); RenderedImage image = null; try { image = reader.readAsRenderedImage(0, null); } catch (IOException e) { fail("Image could not be read: " + e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
public void testSetDestination() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0); while (types.hasNext()) { ImageTypeSpecifier type = types.next(); BufferedImage destination = type.createBufferedImage(50, 50); param.setDestination(destination); BufferedImage result = reader.read(0, param); assertSame(destination, result); } }
public void testReadWithDefaultParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(0, reader.getDefaultReadParam()); } catch (IOException e) { fail("Image could not be read: " + e); } assertNotNull("Image was null!", image); assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth()); assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight()); }
public void testReadIndexOutOfBoundsWithParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(99, reader.getDefaultReadParam()); fail("Read image with index out of bounds"); } catch (IndexOutOfBoundsException ignore) { } catch (IOException e) { fail("Image could not be read: " + e); } assertNull(image); }
public void testReadAsRenderedImageIndexNegative() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); RenderedImage image = null; try { image = reader.readAsRenderedImage(-1, reader.getDefaultReadParam()); fail("Read image with illegal index"); } catch (IndexOutOfBoundsException expected) { // Ignore } catch (IOException e) { fail("Image could not be read: " + e); } assertNull(image); }
public void testProviderCanRead() throws IOException { List<TestData> testData = getTestData(); ImageReaderSpi provider = createProvider(); for (TestData data : testData) { ImageInputStream stream = data.getInputStream(); assertNotNull(stream); assertTrue("Provider is expected to be able to decode data: " + data, provider.canDecodeInput(stream)); } }
public void testSetDestinationRaw() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); ImageTypeSpecifier type = reader.getRawImageType(0); BufferedImage destination = type.createBufferedImage(reader.getWidth(0), reader.getHeight(0)); param.setDestination(destination); BufferedImage result = reader.read(0, param); assertSame(destination, result); }
public void testProviderAndMetadataFormatNamesMatch() throws IOException { ImageReaderSpi provider = createProvider(); ImageReader reader = createReader(); reader.setInput(getTestData().get(0).getInputStream()); IIOMetadata imageMetadata = reader.getImageMetadata(0); if (imageMetadata != null) { assertEquals(provider.getNativeImageMetadataFormatName(), imageMetadata.getNativeMetadataFormatName()); } IIOMetadata streamMetadata = reader.getStreamMetadata(); if (streamMetadata != null) { assertEquals(provider.getNativeStreamMetadataFormatName(), streamMetadata.getNativeMetadataFormatName()); } }