1 /*
   2  * Copyright (c) 2012, 2014, 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 8031651
  27  * @compile 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 import javax.imageio.metadata.IIOMetadataFormatImpl;
  34 import javax.imageio.ImageTypeSpecifier;
  35 
  36 public class GetObjectMinValue {
  37 
  38     public static void main(String argv[]) {
  39         test(true, true);
  40         test(true, false);
  41         test(false, true);
  42         test(false, false);
  43     }
  44 
  45     private static void test(boolean minInclusive, boolean maxInclusive) {
  46         Integer defValue = new Integer(1);
  47         Integer minValue = new Integer(0);
  48         Integer maxValue = new Integer(10);
  49 
  50         MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);
  51 
  52         fmt.addObjectValue("root", defValue.getClass(), defValue,
  53                            minValue, maxValue, minInclusive, maxInclusive);
  54 
  55         try {
  56             Integer act_min = (Integer)fmt.getObjectMinValue("root");
  57             if (! act_min.equals(minValue))
  58                 throw new RuntimeException("invalid min value: " + act_min);
  59         } catch (Throwable e) {
  60             throw new RuntimeException
  61                 ("getObjectMinValue: unexpected exception: " + e);
  62         }
  63         try {
  64             Integer act_max = (Integer)fmt.getObjectMaxValue("root");
  65             if (! act_max.equals(maxValue))
  66                 throw new RuntimeException("invalid max value: " + act_max);
  67         } catch (Throwable e) {
  68             throw new RuntimeException
  69                 ("getObjectMaxValue: unexpected exception: " + e);
  70         }
  71     }
  72 
  73     static class MyFormatImpl extends IIOMetadataFormatImpl {
  74 
  75         MyFormatImpl(String root, int minChildren, int maxChildren) {
  76             super(root, minChildren, maxChildren);
  77         }
  78 
  79         public void addObjectValue(String elementName,
  80                                    Class classType, Object defaultValue,
  81                                    Comparable minValue, Comparable maxValue,
  82                                    boolean minInclusive, boolean maxInclusive) {
  83             super.addObjectValue(elementName,
  84                                  classType, defaultValue,
  85                                  minValue, maxValue,
  86                                  minInclusive, maxInclusive);
  87         }
  88 
  89         public boolean canNodeAppear(String elementName,
  90                                      ImageTypeSpecifier imageType) {
  91             return true;
  92         }
  93     }
  94 
  95 }