@Test public void testReadWithSourceRegionParamEqualImage() throws IOException { // Default invocation assertReadWithSourceRegionParamEqualImage(new Rectangle(3, 3, 9, 9), getTestData().get(0), 0); }
@Test public void testDisposeAfterRead() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); reader.dispose(); // Just pass with no exceptions }
@Test public void testNotBadCaching() throws IOException { T reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage one = reader.read(0); BufferedImage two = reader.read(0); assertNotSame("Multiple reads return same (mutable) image", one, two); one.setRGB(0, 0, Color.BLUE.getRGB()); two.setRGB(0, 0, Color.RED.getRGB()); assertTrue(one.getRGB(0, 0) != two.getRGB(0, 0)); reader.dispose(); }
@Test 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()); reader.dispose(); }
@SuppressWarnings("ConstantConditions") @Test 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")); } reader.dispose(); }
@Test public void testSetInput() { // Should just pass with no exceptions ImageReader reader = createReader(); assertNotNull(reader); for (TestData data : getTestData()) { reader.setInput(data.getInputStream()); } reader.dispose(); }
@Test 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); reader.dispose(); }
@Test public void testGetAspectRatio() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); float aspectRatio = 0f; try { aspectRatio = reader.getAspectRatio(0); } catch (IOException e) { fail("Could not read image aspect ratio" + e); } Dimension d = data.getDimension(0); assertEquals("Wrong aspect aspect ratio", d.getWidth() / d.getHeight(), aspectRatio, 0.001); reader.dispose(); }
@Test 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); reader.dispose(); }
@Test public void testRemoveAllIIOReadProgressListeners() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); IIOReadProgressListener listener = mock(IIOReadProgressListener.class); reader.addIIOReadProgressListener(listener); reader.removeAllIIOReadProgressListeners(); try { reader.read(0); } catch (IOException e) { fail("Could not read image"); } // Should not have called any methods... verifyZeroInteractions(listener); reader.dispose(); }
@Test 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) { failBecause("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()); reader.dispose(); }
@Test 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()); reader.dispose(); }
@Test 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) { failBecause("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()); reader.dispose(); }
@Test 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) { failBecause("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()); reader.dispose(); }
@Test 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); reader.dispose(); }
@Test 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); reader.dispose(); }
@Test public void testReadIndexOutOfBounds() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(Integer.MAX_VALUE); // TODO: This might actually not throw exception... fail("Read image with index out of bounds"); } catch (IndexOutOfBoundsException ignore) { } catch (IOException e) { failBecause("Image could not be read", e); } assertNull(image); reader.dispose(); }
@Test 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)); } }
@Test public void testReadIndexOutOfBoundsWithParam() { ImageReader reader = createReader(); TestData data = getTestData().get(0); reader.setInput(data.getInputStream()); BufferedImage image = null; try { image = reader.read(Short.MAX_VALUE, reader.getDefaultReadParam()); fail("Read image with index out of bounds"); } catch (IndexOutOfBoundsException ignore) { } catch (IOException e) { failBecause("Image could not be read", e); } assertNull(image); reader.dispose(); }
@Test 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()); } reader.dispose(); }