Path: blob/master/test/jdk/javax/imageio/ImageReaderGetDestination.java
41145 views
/*1* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 444921126* @summary Checks that ImageReader.getDestination throws correct exceptions27*/2829import java.awt.image.BufferedImage;30import java.io.IOException;31import java.util.Iterator;32import java.util.Vector;3334import javax.imageio.IIOException;35import javax.imageio.ImageReadParam;36import javax.imageio.ImageReader;37import javax.imageio.ImageTypeSpecifier;38import javax.imageio.metadata.IIOMetadata;39import javax.imageio.spi.ImageReaderSpi;4041public class ImageReaderGetDestination {4243public static void main(String argv[]) {44Vector imageTypes = new Vector();45boolean gotIAE1 = false;46boolean gotIAE2 = false;47boolean gotIAE3 = false;48boolean gotIAE4 = false;4950try {51DummyImageReaderImpl.getDestination(null, null, 5, 10);52} catch (IllegalArgumentException iae) {53gotIAE1 = true;54} catch (Throwable ee) {55System.out.println("Unexpected exception 1:");56ee.printStackTrace();57}58if (!gotIAE1) {59throw new RuntimeException("Failed to get IAE #1!");60}6162try {63DummyImageReaderImpl.getDestination(null, imageTypes.iterator(),645, 10);65} catch (IllegalArgumentException iae) {66gotIAE2 = true;67} catch (Throwable ee) {68System.out.println("Unexpected exception 2:");69ee.printStackTrace();70}71if (!gotIAE2) {72throw new RuntimeException("Failed to get IAE #2!");73}7475imageTypes.add("abc");76try {77DummyImageReaderImpl.getDestination(null, imageTypes.iterator(),785, 10);79} catch (IllegalArgumentException iae) {80gotIAE3 = true;81} catch (Throwable ee) {82System.out.println("Unexpected exception 3:");83ee.printStackTrace();84}85if (!gotIAE3) {86throw new RuntimeException("Failed to get IAE #3!");87}8889imageTypes.clear();90ImageTypeSpecifier its = ImageTypeSpecifier.createFromBufferedImageType91(BufferedImage.TYPE_INT_RGB);92imageTypes.add(its);93try {94DummyImageReaderImpl.getDestination(null,95imageTypes.iterator(),96Integer.MAX_VALUE,97Integer.MAX_VALUE);98} catch (IllegalArgumentException iae) {99gotIAE4 = true;100} catch (Throwable ee) {101System.out.println("Unexpected exception 4: ");102ee.printStackTrace();103}104if (!gotIAE4) {105throw new RuntimeException("Failed to get IAE #4!");106}107}108109public static class DummyImageReaderImpl extends ImageReader {110public DummyImageReaderImpl(ImageReaderSpi originatingProvider) {111super(originatingProvider);112}113public static BufferedImage getDestination(ImageReadParam param,114Iterator imageTypes,115int width,116int height)117throws IIOException {118return ImageReader.getDestination(param, imageTypes, width, height);119}120public int getNumImages(boolean allowSearch) throws IOException {return 1;}121public int getWidth(int imageIndex) throws IOException {return 1;}122public int getHeight(int imageIndex) throws IOException {return 1;}123public Iterator getImageTypes(int imageIndex)124throws IOException {return null;}125public IIOMetadata getStreamMetadata() throws IOException {return null;}126public IIOMetadata getImageMetadata(int imageIndex)127throws IOException {return null;}128public BufferedImage read(int imageIndex, ImageReadParam param)129throws IOException {return null;}130}131}132133134