Path: blob/master/test/jdk/javax/imageio/spi/OrderingTest.java
41149 views
/*1* Copyright (c) 2003, 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 493644526* @summary This test verifies whether setting the order reversely between 2 spi27* objects removes the previous ordering that was set between the28* same set of spi objects. This is verified by invoking29* unsetOrdering() method twice consecutively with respect to the same30* spi objects and unsetOrdering() is supposed to return false when31* called for the second time.32* @modules java.desktop/com.sun.imageio.plugins.gif33* java.desktop/com.sun.imageio.plugins.png34*/3536import javax.imageio.spi.IIORegistry;37import javax.imageio.spi.ImageReaderSpi;38import javax.imageio.spi.ServiceRegistry;3940public class OrderingTest {4142public OrderingTest() {4344ServiceRegistry reg = IIORegistry.getDefaultInstance();45ImageReaderSpi gifSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.gif.GIFImageReaderSpi.class);46ImageReaderSpi pngSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.png.PNGImageReaderSpi.class);4748boolean ordered = reg.setOrdering(ImageReaderSpi.class, gifSpi, pngSpi);4950ordered = reg.setOrdering(ImageReaderSpi.class, pngSpi, gifSpi);5152boolean unordered = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,53pngSpi);54boolean unordered1 = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,55pngSpi);5657if (unordered1) {58throw new RuntimeException("FAIL: Ordering 2 spi objects in the "59+ "reverse direction does not remove the previous ordering "60+ "set between the spi objects and hence unsetOrdering() "61+ "returns true for the same spi objects when called consecutively");62} else {63System.out.println("PASS");64}6566}6768public static void main(String args[]) {69OrderingTest test = new OrderingTest();70}71}727374