Path: blob/master/test/jdk/javax/imageio/metadata/RemoveElement.java
41152 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 4432628 718679926* @run main RemoveElement27* @summary Checks if ImageMetadataFormatImpl.removeElement properly28* removes the element from its parent's child list.29*/3031import javax.imageio.metadata.IIOMetadataFormatImpl;32import javax.imageio.metadata.IIOMetadataFormat;33import javax.imageio.ImageTypeSpecifier;3435public class RemoveElement {3637public static void main(String[] args) {38String elem = "elem2";39int policy = IIOMetadataFormat.CHILD_POLICY_SOME;40MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);41fmt.addElement("elem1", "root", policy);42fmt.addElement(elem, "root", policy);43fmt.removeElement("elem1");4445boolean gotIAE = false;46try {47fmt.getChildPolicy("elem1");48} catch (IllegalArgumentException e) {49gotIAE = true;50}51if (!gotIAE) {52throw new RuntimeException("Element is still present!");53}54String[] chNames = fmt.getChildNames("root");55if (chNames.length != 1) {56throw new RuntimeException("Root still has more than 1 child!");57}58if (!elem.equals(chNames[0])) {59throw new RuntimeException("Root's remaining child is incorrect!");60}61}6263static class MyFormatImpl extends IIOMetadataFormatImpl {6465MyFormatImpl(String root, int minChildren, int maxChildren) {66super(root, minChildren, maxChildren);67}6869public void addElement(String elementName,70String parentName,71int childPolicy) {72super.addElement(elementName, parentName, childPolicy);73}7475public void removeElement(String elementName) {76super.removeElement(elementName);77}7879public boolean canNodeAppear(String elementName,80ImageTypeSpecifier imageType) {81return true;82}83}8485}868788