Path: blob/master/test/jdk/javax/imageio/metadata/RegisteredFormatsTest.java
51315 views
/*1* Copyright (c) 2012, 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 501799126* @summary This test verifies two things:27* a) we can get MetadataFormat classes for28* each registered metadata format.29* b) all metadata formats for standard plugins30* are registered.31* @run main RegisteredFormatsTest32*/3334import javax.imageio.spi.IIORegistry;35import javax.imageio.spi.ImageReaderSpi;36import javax.imageio.metadata.IIOMetadataFormat;37import java.util.Iterator;38import java.util.Hashtable;39import java.util.Enumeration;4041public class RegisteredFormatsTest {4243private static Hashtable fmts;4445public static void main(String[] args) {46fmts = new Hashtable();4748fmts.put("javax_imageio_jpeg_stream_1.0", Boolean.FALSE);49fmts.put("javax_imageio_jpeg_image_1.0", Boolean.FALSE);50fmts.put("javax_imageio_png_1.0", Boolean.FALSE);51fmts.put("javax_imageio_bmp_1.0", Boolean.FALSE);52fmts.put("javax_imageio_wbmp_1.0", Boolean.FALSE);53fmts.put("javax_imageio_gif_stream_1.0", Boolean.FALSE);54fmts.put("javax_imageio_gif_image_1.0", Boolean.FALSE);5556IIORegistry registry = IIORegistry.getDefaultInstance();57Iterator iter = registry.getServiceProviders(ImageReaderSpi.class,58false);59while(iter.hasNext()) {60ImageReaderSpi spi = (ImageReaderSpi)iter.next();61String fmt_name;62fmt_name = spi.getNativeStreamMetadataFormatName();63testStreamMetadataFormat(spi, fmt_name);6465fmt_name = spi.getNativeImageMetadataFormatName();66testImageMetadataFormat(spi, fmt_name);6768String[] fmt_names;69fmt_names = spi.getExtraStreamMetadataFormatNames();70for (int i=0; fmt_names != null && i < fmt_names.length; i++) {71testStreamMetadataFormat(spi, fmt_names[i]);72}7374fmt_names = spi.getExtraImageMetadataFormatNames();75for (int i=0; fmt_names != null && i < fmt_names.length; i++) {76testImageMetadataFormat(spi, fmt_names[i]);77}78}79Enumeration keys = fmts.keys();80while (keys.hasMoreElements()) {81String key = (String)keys.nextElement();82boolean val = ((Boolean)fmts.get(key)).booleanValue();83if (!val) {84throw new RuntimeException("Test failed: format " +85key + "is not registered.");86}87}88}8990private static void testStreamMetadataFormat(ImageReaderSpi spi,91String fmt_name) {92if (fmt_name == null) {93return;94}95try {96testMetadataFormat(spi.getStreamMetadataFormat(fmt_name),97fmt_name);98} catch (Exception e) {99throw new RuntimeException("Test failed for " + fmt_name,100e);101}102}103104private static void testImageMetadataFormat(ImageReaderSpi spi,105String fmt_name) {106if (fmt_name == null) {107return;108}109try {110testMetadataFormat(spi.getImageMetadataFormat(fmt_name),111fmt_name);112} catch (Exception e) {113throw new RuntimeException("Test failed for " + fmt_name,114e);115}116}117private static void testMetadataFormat(IIOMetadataFormat fmt,118String fmt_name) {119System.out.print(fmt_name + "...");120if (fmt != null) {121fmts.put(fmt_name, Boolean.TRUE);122System.out.println("Ok");123} else {124throw new RuntimeException("Test failed for " + fmt_name);125}126}127}128129130