Path: blob/master/test/jdk/javax/imageio/GetReaderWriterInfoNullTest.java
41145 views
/*1* Copyright (c) 2016, 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 816325826* @summary Test verifies that when we create our own ImageReaderSpi27* implementaion with MIMEType or FileSuffix as null, it should28* not throw NullPointerException when we call29* ImageIO.getReaderMIMETypes() or ImageIO.getReaderFileSuffixes().30* @run main GetReaderWriterInfoNullTest31*/3233import java.awt.image.BufferedImage;34import java.io.IOException;35import java.util.Iterator;36import java.util.Locale;37import javax.imageio.IIOException;38import javax.imageio.ImageReadParam;39import javax.imageio.ImageReader;40import javax.imageio.ImageTypeSpecifier;41import javax.imageio.metadata.IIOMetadata;42import javax.imageio.spi.ImageReaderSpi;43import javax.imageio.stream.ImageInputStream;44import javax.imageio.ImageIO;45import javax.imageio.spi.IIORegistry;4647class TestImageReaderSpi extends ImageReaderSpi {4849public TestImageReaderSpi(String[] FORMATNAMES, String[] SUFFIXES,50String[] MIMETYPES) {51super("J Duke", // vendor52"1.0", // version53FORMATNAMES, // format names54SUFFIXES, // file suffixes55MIMETYPES, // mimetypes56"readTest.TestImageReader", // reader class name57new Class<?>[] { ImageInputStream.class }, // input types58null, // writer class names.59true, // supports native metadata,60null, // [no] native stream metadata format61null, // [no] native stream metadata class62null, // [no] native extra stream metadata format63null, // [no] native extra stream metadata class64true, // supports standard metadata,65null, // metadata format name,66null, // metadata format class name67null, // [no] extra image metadata format68null // [no] extra image metadata format class69);70}7172@Override73public boolean canDecodeInput(Object source) throws IOException {74throw new UnsupportedOperationException("Not supported yet.");75}7677@Override78public String getDescription(Locale locale) {79throw new UnsupportedOperationException("Not supported yet.");80}8182@Override83public ImageReader createReaderInstance(Object extension)84throws IOException {85throw new UnsupportedOperationException("Not supported yet.");86}8788}8990class TestImageReader extends ImageReader {9192public TestImageReader(ImageReaderSpi originatingProvider) {93super(originatingProvider);94}9596@Override97public int getNumImages(boolean allowSearch) throws IOException {98throw new UnsupportedOperationException("Not supported yet.");99}100101@Override102public int getWidth(int imageIndex) throws IOException {103throw new UnsupportedOperationException("Not supported yet.");104}105106@Override107public int getHeight(int imageIndex) throws IOException {108throw new UnsupportedOperationException("Not supported yet.");109}110111@Override112public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)113throws IOException {114throw new UnsupportedOperationException("Not supported yet.");115}116117@Override118public IIOMetadata getStreamMetadata() throws IOException {119throw new UnsupportedOperationException("Not supported yet.");120}121122@Override123public IIOMetadata getImageMetadata(int imageIndex) throws IOException {124throw new UnsupportedOperationException("Not supported yet.");125}126127@Override128public BufferedImage read(int imageIndex, ImageReadParam param)129throws IOException {130throw new UnsupportedOperationException("Not supported yet.");131}132}133public class GetReaderWriterInfoNullTest {134static final String[] FORMATNAMES = {"readTest"};135static final String[] SUFFIXES = {"readTest"};136static final String[] MIMETYPES = {"readTest"};137public static void main (String[] args) throws IIOException {138// Verify getReaderMIMETypes() behavior by keeping MIMEType as null.139TestImageReaderSpi mimeNullReadSpi =140new TestImageReaderSpi(FORMATNAMES, SUFFIXES, null);141IIORegistry.getDefaultInstance().142registerServiceProvider(mimeNullReadSpi);143ImageIO.getReaderMIMETypes();144IIORegistry.getDefaultInstance().145deregisterServiceProvider(mimeNullReadSpi);146147/*148* Verify getReaderFileSuffixes() behavior by keeping149* file suffix as null.150*/151TestImageReaderSpi suffixNullReadSpi =152new TestImageReaderSpi(FORMATNAMES, null, MIMETYPES);153IIORegistry.getDefaultInstance().154registerServiceProvider(suffixNullReadSpi);155ImageIO.getReaderFileSuffixes();156IIORegistry.getDefaultInstance().157deregisterServiceProvider(suffixNullReadSpi);158}159}160161162163