1/* 2 * Copyright (c) 2016, 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 6185114 27 * @summary test SampleModel constructor for different combinations of 28 * width and height 29 */ 30 31import java.awt.image.DataBuffer; 32import java.awt.image.Raster; 33import java.awt.image.SampleModel; 34 35 36public class SampleModelConstructorTest { 37 38 public static void main(String[] a) throws RuntimeException { 39 40 SampleModel model = Raster.createBandedRaster(DataBuffer.TYPE_INT, 41 10, 5, 4, null).getSampleModel(); 42 43 final int inputWidths[] 44 = {Integer.MIN_VALUE, -1000, -1, 0, 1, 1000, Integer.MAX_VALUE}; 45 46 final int inputHeights[] 47 = {Integer.MIN_VALUE, -1000, -1, 0, 1, 1000, Integer.MAX_VALUE}; 48 49 // There are 49 combinations of (width, height) possible using above two 50 // arrays 51 52 // Only 6 valid combinations of (width, height) that do not throw 53 // exception are : 54 // (1, 1) 55 // (1, 1000) 56 // (1, Integer.MAX_VALUE) 57 // (1000, 1) 58 // (1000, 1000) 59 // (Integer.MAX_VALUE, 1) 60 final int expectedCount = 43; 61 int count = 0; 62 63 for (int i : inputWidths) { 64 for (int j : inputHeights) { 65 try { 66 SampleModel model2 = model.createCompatibleSampleModel(i, j); 67 } catch (IllegalArgumentException e) { 68 count++; 69 } 70 } 71 } 72 73 if (count != expectedCount) { 74 throw new RuntimeException( 75 "Test Failed. Expected IllegalArgumentException Count = " + 76 expectedCount + " Got Count = " + count); 77 } 78 } 79} 80 81