Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/spi/PluginSpiTest.java
38839 views
/*1* Copyright (c) 2005, 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 627511226* @summary Test verifies that imageReaders for base image formats return27* meaningful name of service provider interface (SPI) for base image28* formats29*/3031import javax.imageio.ImageIO;32import javax.imageio.ImageReader;33import javax.imageio.ImageWriter;34import javax.imageio.spi.ImageReaderSpi;3536public class PluginSpiTest {3738public static void main(String[] args) {39String format[] = { "GIF", "PNG", "JPEG", "BMP", "WBMP" };40for (int i = 0; i < format.length; i++) {41System.out.println("\nFormat " + format[i]);42testFormat(format[i]);43}44}4546public static void testFormat(String format) {47ImageReader reader =48ImageIO.getImageReadersByFormatName(format).next();49if (reader == null) {50throw new RuntimeException("Failed to get reader for " + format);51}5253ImageReaderSpi readerSpi = reader.getOriginatingProvider();54System.out.println(format + " Reader SPI: " + readerSpi);5556String writerSpiNames[] = readerSpi.getImageWriterSpiNames();57if (writerSpiNames == null || writerSpiNames.length == 0) {58throw new RuntimeException("Failed to get writer spi names for " +59format);60}6162System.out.println("Available writer spi names:");63for (int i = 0; i < writerSpiNames.length; i++) {64System.out.println(writerSpiNames[i]);65try {66Class spiClass = Class.forName(writerSpiNames[i]);67if (spiClass == null) {68throw new RuntimeException("Failed to get spi class " +69writerSpiNames[i]);70}71System.out.println("Got class " + spiClass.getName());7273Object spiObject = spiClass.newInstance();74if (spiObject == null) {75throw new RuntimeException("Failed to instantiate spi " +76writerSpiNames[i]);77}78System.out.println("Got instance " + spiObject);79} catch (Throwable e) {80throw new RuntimeException("Failed to test spi " +81writerSpiNames[i]);82}83}8485ImageWriter writer = ImageIO.getImageWriter(reader);86if (writer == null) {87throw new RuntimeException("Failed to get writer for " + format);88}89}90}919293