Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/spi/OrderingTest.java
38838 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*/3334import javax.imageio.spi.IIORegistry;35import javax.imageio.spi.ImageReaderSpi;36import javax.imageio.spi.ServiceRegistry;3738public class OrderingTest {3940public OrderingTest() {4142ServiceRegistry reg = IIORegistry.getDefaultInstance();43ImageReaderSpi gifSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.gif.GIFImageReaderSpi.class);44ImageReaderSpi pngSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.png.PNGImageReaderSpi.class);4546boolean ordered = reg.setOrdering(ImageReaderSpi.class, gifSpi, pngSpi);4748ordered = reg.setOrdering(ImageReaderSpi.class, pngSpi, gifSpi);4950boolean unordered = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,51pngSpi);52boolean unordered1 = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,53pngSpi);5455if (unordered1) {56throw new RuntimeException("FAIL: Ordering 2 spi objects in the "57+ "reverse direction does not remove the previous ordering "58+ "set between the spi objects and hence unsetOrdering() "59+ "returns true for the same spi objects when called consecutively");60} else {61System.out.println("PASS");62}6364}6566public static void main(String args[]) {67OrderingTest test = new OrderingTest();68}69}707172