Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/metadata/GetObjectMinValue.java
38840 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 4429875 718679926* @compile -source 1.4 GetObjectMinValue.java27* @run main GetObjectMinValue28* @summary Tests the getObject{Min,Max}Value method of29* IIOMetadataFormatImpl for an inclusive range30*/3132// Compiled with -source 1.4 to work around javac bug 50412333334import javax.imageio.metadata.IIOMetadataFormatImpl;35import javax.imageio.ImageTypeSpecifier;3637public class GetObjectMinValue {3839public static void main(String argv[]) {40test(true, true);41test(true, false);42test(false, true);43test(false, false);44}4546private static void test(boolean minInclusive, boolean maxInclusive) {47Integer defValue = new Integer(1);48Integer minValue = new Integer(0);49Integer maxValue = new Integer(10);5051MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);5253fmt.addObjectValue("root", defValue.getClass(), defValue,54minValue, maxValue, minInclusive, maxInclusive);5556try {57Integer act_min = (Integer)fmt.getObjectMinValue("root");58if (! act_min.equals(minValue))59throw new RuntimeException("invalid min value: " + act_min);60} catch (Throwable e) {61throw new RuntimeException62("getObjectMinValue: unexpected exception: " + e);63}64try {65Integer act_max = (Integer)fmt.getObjectMaxValue("root");66if (! act_max.equals(maxValue))67throw new RuntimeException("invalid max value: " + act_max);68} catch (Throwable e) {69throw new RuntimeException70("getObjectMaxValue: unexpected exception: " + e);71}72}7374static class MyFormatImpl extends IIOMetadataFormatImpl {7576MyFormatImpl(String root, int minChildren, int maxChildren) {77super(root, minChildren, maxChildren);78}7980public void addObjectValue(String elementName,81Class classType, Object defaultValue,82Comparable minValue, Comparable maxValue,83boolean minInclusive, boolean maxInclusive) {84super.addObjectValue(elementName,85classType, defaultValue,86minValue, maxValue,87minInclusive, maxInclusive);88}8990public boolean canNodeAppear(String elementName,91ImageTypeSpecifier imageType) {92return true;93}94}9596}979899