--- /dev/null 2017-01-11 11:24:22.974040000 +0530 +++ new/test/javax/imageio/plugins/tiff/TIFFCreateArrayForTypeTest.java 2017-01-11 18:03:51.274044571 +0530 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8152561 + * @summary Test verifies whether all boundary conditions are checked + * properly in TIFFField.createArrayForType(). + * @run main TIFFCreateArrayForTypeTest + */ + +import javax.imageio.plugins.tiff.TIFFField; +import javax.imageio.plugins.tiff.TIFFTag; + +public class TIFFCreateArrayForTypeTest { + + static int count = 0; + + private static void check(boolean pass, String msg) { + if (!pass) { + throw new RuntimeException(msg); + } + } + public static void main(String[] args) { + + // check passing unknown data type to createArrayForType() + boolean pass = false; + count = 2; + int dataType = 15; + try { + TIFFField.createArrayForType(dataType, count); + } catch (IllegalArgumentException e) { + pass = true; + } catch (Exception e) { + // just consume if it throws any other exception. + } + check(pass, "Passing unknown datatype is not throwing" + + " IllegalArgumentException"); + + // check passing negative count value for createArrayForType() + pass = false; + count = -1; + try { + TIFFField.createArrayForType(TIFFTag.TIFF_LONG, count); + } catch (IllegalArgumentException e) { + pass = true; + } catch (Exception e) { + // just consume if it throws any other exception. + } + check(pass, "Passing negative count value is not throwing" + + " IllegalArgumentException"); + + /* + * check passing zero count value for createArrayForType() with + * TIFFTag.TIFF_RATIONAL or TIFFTag.TIFF_SRATIONAL data type. + */ + pass = false; + count = 0; + try { + TIFFField.createArrayForType(TIFFTag.TIFF_RATIONAL, count); + } catch (IllegalArgumentException e) { + pass = true; + } catch (Exception e) { + // just consume if it throws any other exception. + } + check(pass, "Passing zero count value with TIFFTag.TIFF_RATIONAL" + + " is not throwing IllegalArgumentException"); + + /* + * check passing count value other than 1 for createArrayForType() with + * TIFFTag.TIFF_IFD_POINTER data type. + */ + pass = false; + count = 2; + try { + TIFFField.createArrayForType(TIFFTag.TIFF_IFD_POINTER, count); + } catch (IllegalArgumentException e) { + pass = true; + } catch (Exception e) { + // just consume if it throws any other exception. + } + check(pass, "Passing count value other than 1 with" + + " TIFFTag.TIFF_IFD_POINTER is not throwing" + + " IllegalArgumentException"); + } +} +