jdk/test/java/awt/image/GetDataElementsTest.java
author sogoel
Fri, 05 Sep 2014 16:51:39 -0700
changeset 26529 10ec5e52bf75
parent 6815 eba82865cf06
permissions -rw-r--r--
8055079: Group 9c: golden files for tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6815
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     1
/*
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     4
 *
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     7
 * published by the Free Software Foundation.
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     8
 *
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    13
 * accompanied this code).
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    14
 *
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    18
 *
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    21
 * questions.
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    22
 */
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    23
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    24
/*
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    25
 * @test
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    26
 * @bug     6773022
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    27
 * @summary Test verifies that SampleModel.getDataElements() throws an appropriate
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    28
 *           exception if coordinates are not in bounds.
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    29
 *
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    30
 * @run     main GetDataElementsTest
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    31
 */
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    32
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    33
import java.awt.image.ComponentSampleModel;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    34
import java.awt.image.DataBuffer;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    35
import java.awt.image.SampleModel;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    36
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    37
public class GetDataElementsTest {
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    38
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    39
    public static int width = 100;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    40
    public static int height = 100;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    41
    public static int dataType = DataBuffer.TYPE_BYTE;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    42
    public static int numBands = 4;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    43
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    44
    public static void main(String[] args) {
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    45
        SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    46
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    47
        DataBuffer db = sm.createDataBuffer();
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    48
        Object o = null;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    49
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    50
        boolean testPassed = false;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    51
        try {
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    52
            o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    53
        } catch (ArrayIndexOutOfBoundsException e) {
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    54
            System.out.println(e.getMessage());
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    55
            testPassed = true;
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    56
        }
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    57
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    58
        if (!testPassed) {
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    59
            throw new RuntimeException("Excpected excprion was not thrown.");
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    60
        }
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    61
    }
eba82865cf06 6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
bae
parents:
diff changeset
    62
}