1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4429875 7186799
  27  * @compile -source 1.4 GetObjectMinValue.java
  28  * @run main GetObjectMinValue
  29  * @summary Tests the getObject{Min,Max}Value method of
  30  * IIOMetadataFormatImpl for an inclusive range
  31  */
  32 
  33 // Compiled with -source 1.4 to work around javac bug 5041233
  34 
  35 import javax.imageio.metadata.IIOMetadataFormatImpl;
  36 import javax.imageio.ImageTypeSpecifier;
  37 
  38 public class GetObjectMinValue {
  39 
  40     public static void main(String argv[]) {
  41         test(true, true);
  42         test(true, false);
  43         test(false, true);
  44         test(false, false);
  45     }
  46 
  47     private static void test(boolean minInclusive, boolean maxInclusive) {
  48         Integer defValue = new Integer(1);
  49         Integer minValue = new Integer(0);
  50         Integer maxValue = new Integer(10);
  51 
  52         MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);
  53 
  54         fmt.addObjectValue("root", defValue.getClass(), defValue,
  55                            minValue, maxValue, minInclusive, maxInclusive);
  56 
  57         try {
  58             Integer act_min = (Integer)fmt.getObjectMinValue("root");
  59             if (! act_min.equals(minValue))
  60                 throw new RuntimeException("invalid min value: " + act_min);
  61         } catch (Throwable e) {
  62             throw new RuntimeException
  63                 ("getObjectMinValue: unexpected exception: " + e);
  64         }
  65         try {
  66             Integer act_max = (Integer)fmt.getObjectMaxValue("root");
  67             if (! act_max.equals(maxValue))
  68                 throw new RuntimeException("invalid max value: " + act_max);
  69         } catch (Throwable e) {
  70             throw new RuntimeException
  71                 ("getObjectMaxValue: unexpected exception: " + e);
  72         }
  73     }
  74 
  75     static class MyFormatImpl extends IIOMetadataFormatImpl {
  76 
  77         MyFormatImpl(String root, int minChildren, int maxChildren) {
  78             super(root, minChildren, maxChildren);
  79         }
  80 
  81         public void addObjectValue(String elementName,
  82                                    Class classType, Object defaultValue,
  83                                    Comparable minValue, Comparable maxValue,
  84                                    boolean minInclusive, boolean maxInclusive) {
  85             super.addObjectValue(elementName,
  86                                  classType, defaultValue,
  87                                  minValue, maxValue,
  88                                  minInclusive, maxInclusive);
  89         }
  90 
  91         public boolean canNodeAppear(String elementName,
  92                                      ImageTypeSpecifier imageType) {
  93             return true;
  94         }
  95     }
  96 
  97 }