Path: blob/master/test/jdk/javax/imageio/metadata/GetObjectMinValue.java
41152 views
/*1* Copyright (c) 2012, 2014, 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 GetObjectMinValue.java27* @run main GetObjectMinValue28* @summary Tests the getObject{Min,Max}Value method of29* IIOMetadataFormatImpl for an inclusive range30*/3132import javax.imageio.metadata.IIOMetadataFormatImpl;33import javax.imageio.ImageTypeSpecifier;3435public class GetObjectMinValue {3637public static void main(String argv[]) {38test(true, true);39test(true, false);40test(false, true);41test(false, false);42}4344private static void test(boolean minInclusive, boolean maxInclusive) {45Integer defValue = new Integer(1);46Integer minValue = new Integer(0);47Integer maxValue = new Integer(10);4849MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);5051fmt.addObjectValue("root", defValue.getClass(), defValue,52minValue, maxValue, minInclusive, maxInclusive);5354try {55Integer act_min = (Integer)fmt.getObjectMinValue("root");56if (! act_min.equals(minValue))57throw new RuntimeException("invalid min value: " + act_min);58} catch (Throwable e) {59throw new RuntimeException60("getObjectMinValue: unexpected exception: " + e);61}62try {63Integer act_max = (Integer)fmt.getObjectMaxValue("root");64if (! act_max.equals(maxValue))65throw new RuntimeException("invalid max value: " + act_max);66} catch (Throwable e) {67throw new RuntimeException68("getObjectMaxValue: unexpected exception: " + e);69}70}7172static class MyFormatImpl extends IIOMetadataFormatImpl {7374MyFormatImpl(String root, int minChildren, int maxChildren) {75super(root, minChildren, maxChildren);76}7778public void addObjectValue(String elementName,79Class<?> classType, Integer defaultValue,80Comparable minValue, Comparable maxValue,81boolean minInclusive, boolean maxInclusive) {82super.<Integer>addObjectValue(elementName,83(Class<Integer>)classType, defaultValue,84(Comparable<? super Integer>) minValue, (Comparable<? super Integer>) maxValue,85minInclusive, maxInclusive);86}8788public boolean canNodeAppear(String elementName,89ImageTypeSpecifier imageType) {90return true;91}92}9394}959697