Path: blob/master/test/jdk/javax/imageio/metadata/IIOMetadataFormatImplTest.java
41149 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 4403350 4403352 4436995 443897726* @run main IIOMetadataFormatImplTest27* @summary Tests various methods of IIOMetadataFormatImpl:28*29* getElement{Min,Max}Children and getAttribute{Min,Max}Value30* getAttributeDescription31* getAttributeEnumerations32*/3334import javax.imageio.ImageTypeSpecifier;35import javax.imageio.metadata.IIOMetadataFormat;36import javax.imageio.metadata.IIOMetadataFormatImpl;3738public class IIOMetadataFormatImplTest {3940public static void main(String[] args) {41test440335x();42test4436995();43test4438977();44}4546static class IIOMetadataFormatImpl440335x extends IIOMetadataFormatImpl {4748public IIOMetadataFormatImpl440335x() {49super("rootNode", 0, 1);50addElement("anElement", "rootNode", 20, 200);51addAttribute("anElement", "exclusiveAttr",52IIOMetadataFormat.DATATYPE_INTEGER,53true, null,54"50", "500",55false, false);56addAttribute("anElement", "minAttr",57IIOMetadataFormat.DATATYPE_INTEGER,58true, null,59"60", "600",60true, false);61addAttribute("anElement", "maxAttr",62IIOMetadataFormat.DATATYPE_INTEGER,63true, null,64"70", "700",65false, true);66addAttribute("anElement", "minMaxAttr",67IIOMetadataFormat.DATATYPE_INTEGER,68true, null,69"80", "800",70true, true);71}7273public boolean canNodeAppear(String nodeName,74ImageTypeSpecifier imageType) {75return true;76}77}7879private static void test440335x() {80IIOMetadataFormat format = new IIOMetadataFormatImpl440335x();8182// Check that correct value is returned83if (format.getElementMinChildren("anElement") != 20) {84throw new RuntimeException("Error on getElementMinChildren!");85}86if (format.getElementMaxChildren("anElement") != 200) {87throw new RuntimeException("Error on getElementMaxChildren!");88}8990// Check that correct value is returned and no exception is thrown91try {92if (!format.getAttributeMinValue("anElement",93"exclusiveAttr").equals("50")) {94throw new RuntimeException("Error on exclusiveAttr min!");95}96if (!format.getAttributeMaxValue("anElement",97"exclusiveAttr").equals("500")) {98throw new RuntimeException("Error on exclusiveAttr max!");99}100if (!format.getAttributeMinValue("anElement",101"minAttr").equals("60")) {102throw new RuntimeException("Error on minAttr min!");103}104if (!format.getAttributeMaxValue("anElement",105"minAttr").equals("600")) {106throw new RuntimeException("Error on minAttr max!");107}108if (!format.getAttributeMinValue("anElement",109"maxAttr").equals("70")) {110throw new RuntimeException("Error on maxAttr min!");111}112if (!format.getAttributeMaxValue("anElement",113"maxAttr").equals("700")) {114throw new RuntimeException("Error on maxAttr max!");115}116if (!format.getAttributeMinValue("anElement",117"minMaxAttr").equals("80")) {118throw new RuntimeException("Error on minMaxAttr min!");119}120if (!format.getAttributeMaxValue("anElement",121"minMaxAttr").equals("800")) {122throw new RuntimeException("Error on minMaxAttr max!");123}124} catch (IllegalStateException e) {125throw new RuntimeException("Got IllegalStateException!");126}127}128129static class IIOMetadataFormatImpl4436995 extends IIOMetadataFormatImpl {130131public IIOMetadataFormatImpl4436995(String root,132int minChildren, int maxChildren) {133super(root, minChildren, maxChildren);134}135136public void addAttribute(String elementName,137String attrName,138int dataType,139boolean required,140int listMinLength, int listMaxLength) {141super.addAttribute(elementName,142attrName,143dataType,144required, listMinLength,145listMaxLength);146}147148public boolean canNodeAppear(String elementName,149ImageTypeSpecifier imageType) {150return true;151}152}153154private static void test4436995() {155String result;156157IIOMetadataFormatImpl4436995 fmt =158new IIOMetadataFormatImpl4436995("root", 1, 10);159fmt.addAttribute("root", "attr", fmt.DATATYPE_INTEGER, true, 2, 5);160try {161result = fmt.getAttributeDescription("root", "non-existent", null);162throw new RuntimeException("Failed to get IAE!");163} catch(IllegalArgumentException e) {164}165}166167static class IIOMetadataFormatImpl4438977 extends IIOMetadataFormatImpl {168169public IIOMetadataFormatImpl4438977(String root,170int minChildren, int maxChildren) {171super(root, minChildren, maxChildren);172}173174public void addAttribute(String elementName,175String attrName,176int dataType,177boolean required,178int listMinLength, int listMaxLength) {179super.addAttribute(elementName,180attrName,181dataType,182required, listMinLength,183listMaxLength);184}185186public boolean canNodeAppear(String elementName,187ImageTypeSpecifier imageType) {188return true;189}190}191192private static void test4438977() {193String[] result;194195IIOMetadataFormatImpl4438977 fmt =196new IIOMetadataFormatImpl4438977("root", 1, 10);197fmt.addAttribute("root", "attr", fmt.DATATYPE_INTEGER, true, 2, 5);198try {199result = fmt.getAttributeEnumerations("root", "attr");200throw new RuntimeException("Failed to get IAE!");201} catch(IllegalArgumentException e) {202}203}204205}206207208