2762N/A/*
2762N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2762N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2762N/A *
2762N/A * This code is free software; you can redistribute it and/or modify it
2762N/A * under the terms of the GNU General Public License version 2 only, as
2762N/A * published by the Free Software Foundation.
2762N/A *
2762N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2762N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2762N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2762N/A * version 2 for more details (a copy is included in the LICENSE file that
2762N/A * accompanied this code).
2762N/A *
2762N/A * You should have received a copy of the GNU General Public License version
2762N/A * 2 along with this work; if not, write to the Free Software Foundation,
2762N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2762N/A *
2762N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2762N/A * or visit www.oracle.com if you need additional information or have any
2762N/A * questions.
2762N/A */
2762N/A
2762N/A/*
2762N/A * @test
3811N/A * @bug 6735275 6993561
3811N/A * @summary Test verifies that SampleModel.getSamples() SampleModel.setSamples()
3811N/A * throw an appropriate exception if coordinates are not in bounds.
2762N/A *
2762N/A * @run main GetSamplesTest
2762N/A */
2762N/A
2762N/Aimport java.awt.image.BandedSampleModel;
2762N/Aimport java.awt.image.ComponentSampleModel;
2762N/Aimport java.awt.image.DataBuffer;
2762N/Aimport java.awt.image.MultiPixelPackedSampleModel;
2762N/Aimport java.awt.image.PixelInterleavedSampleModel;
2762N/Aimport java.awt.image.SampleModel;
2762N/Aimport java.awt.image.SinglePixelPackedSampleModel;
2762N/Aimport java.util.Vector;
2762N/A
2762N/Apublic class GetSamplesTest {
2762N/A
2762N/A public static int width = 100;
2762N/A public static int height = 100;
2762N/A public static int dataType = DataBuffer.TYPE_BYTE;
2762N/A public static int numBands = 4;
2762N/A
2762N/A public static void main(String[] args) {
2762N/A Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();
2762N/A
2762N/A classes.add(ComponentSampleModel.class);
2762N/A classes.add(MultiPixelPackedSampleModel.class);
2762N/A classes.add(SinglePixelPackedSampleModel.class);
2762N/A classes.add(BandedSampleModel.class);
2762N/A classes.add(PixelInterleavedSampleModel.class);
2762N/A
2762N/A for (Class<? extends SampleModel> c : classes) {
2762N/A doTest(c);
2762N/A }
2762N/A }
2762N/A private static void doTest(Class<? extends SampleModel> c) {
2762N/A System.out.println("Test for: " + c.getName());
2762N/A SampleModel sm = createSampleModel(c);
2762N/A
2762N/A DataBuffer db = sm.createDataBuffer();
2762N/A
2762N/A int[] iArray = new int[ width * height + numBands];
2762N/A float[] fArray = new float[ width * height + numBands];
2762N/A double[] dArray = new double[ width * height + numBands];
2762N/A
2762N/A boolean iOk = false;
2762N/A boolean fOk = false;
2762N/A boolean dOk = false;
2762N/A
2762N/A try {
2762N/A sm.getSamples(Integer.MAX_VALUE, 0, 1, 1, 0, iArray, db);
3811N/A sm.setSamples(Integer.MAX_VALUE, 0, 1, 1, 0, iArray, db);
2762N/A } catch (ArrayIndexOutOfBoundsException e) {
2762N/A System.out.println(e.getMessage());
2762N/A iOk = true;
2762N/A }
2762N/A
2762N/A try {
2762N/A sm.getSamples(Integer.MAX_VALUE, 0, 1, 1, 0, fArray, db);
3811N/A sm.setSamples(Integer.MAX_VALUE, 0, 1, 1, 0, fArray, db);
2762N/A } catch (ArrayIndexOutOfBoundsException e) {
2762N/A System.out.println(e.getMessage());
2762N/A fOk = true;
2762N/A }
2762N/A
2762N/A try {
2762N/A sm.getSamples(0, Integer.MAX_VALUE, 1, 1, 0, dArray, db);
3811N/A sm.setSamples(0, Integer.MAX_VALUE, 1, 1, 0, dArray, db);
2762N/A } catch (ArrayIndexOutOfBoundsException e) {
2762N/A System.out.println(e.getMessage());
2762N/A dOk = true;
2762N/A }
2762N/A if (!iOk || !fOk || !dOk) {
2762N/A throw new RuntimeException("Test for " + c.getSimpleName() +
2762N/A " failed: iOk=" + iOk + "; fOk=" + fOk + "; dOk=" + dOk);
2762N/A }
2762N/A }
2762N/A
2762N/A private static SampleModel createSampleModel(Class<? extends SampleModel> cls) {
2762N/A SampleModel res = null;
2762N/A
2762N/A if (cls == ComponentSampleModel.class) {
2762N/A res = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );
2762N/A } else if (cls == MultiPixelPackedSampleModel.class) {
2762N/A res = new MultiPixelPackedSampleModel(dataType, width, height, 4);
2762N/A } else if (cls == SinglePixelPackedSampleModel.class) {
2762N/A res = new SinglePixelPackedSampleModel(dataType, width, height,
2762N/A new int[]{ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff });
2762N/A } else if (cls == BandedSampleModel.class) {
2762N/A res = new BandedSampleModel(dataType, width, height, numBands);
2762N/A } else if (cls == PixelInterleavedSampleModel.class) {
2762N/A res = new PixelInterleavedSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 });
2762N/A } else {
2762N/A throw new RuntimeException("Unknown class " + cls);
2762N/A }
2762N/A return res;
2762N/A }
2762N/A}