test/javax/imageio/metadata/GetObjectMinValue.java

Print this page


   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,


  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 }
   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
  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,


  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, Integer defaultValue,
  81                                    Comparable minValue, Comparable maxValue,
  82                                    boolean minInclusive, boolean maxInclusive) {
  83             super.<Integer>addObjectValue(elementName,
  84                                           (Class<Integer>)classType, defaultValue,
  85                                           (Comparable<? super Integer>) minValue, (Comparable<? super Integer>) maxValue,
  86                                           minInclusive, maxInclusive);
  87         }
  88 
  89         public boolean canNodeAppear(String elementName,
  90                                      ImageTypeSpecifier imageType) {
  91             return true;
  92         }
  93     }
  94 
  95 }