01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package java.awt.image;
21:
22: import junit.framework.TestCase;
23:
24: public class ComponentSampleModelTest extends TestCase {
25:
26: public ComponentSampleModelTest(String name) {
27: super (name);
28: }
29:
30: public final void testSetDataElements() {
31: // Checking ArrayIndexOutOfBoundsException when passes wrong x or y
32: int[] offsets = new int[4];
33: ComponentSampleModel csm = new ComponentSampleModel(
34: DataBuffer.TYPE_USHORT, 238, 4, 7, 14, offsets);
35: ComponentSampleModel obj = new ComponentSampleModel(
36: DataBuffer.TYPE_USHORT, 1, 2, 3, 15, offsets);
37:
38: DataBufferFloat db = new DataBufferFloat(4);
39: try {
40: csm.setDataElements(-1399, 2, obj, db);
41: fail("Expected ArrayIndexOutOfBoundsException didn't throw");
42: } catch (ClassCastException e) {
43: fail("Unexpected ClassCastException was thrown");
44: } catch (ArrayIndexOutOfBoundsException e) {
45: assertTrue(true);
46: }
47: }
48:
49: public final void testGetDataElements() {
50: // Checking ArrayIndexOutOfBoundsException when passes wrong x or y
51: int[] offsets = new int[4];
52: ComponentSampleModel csm = new ComponentSampleModel(
53: DataBuffer.TYPE_USHORT, 238, 4, 7, 14, offsets);
54: ComponentSampleModel obj = new ComponentSampleModel(
55: DataBuffer.TYPE_USHORT, 1, 2, 3, 15, offsets);
56:
57: DataBufferFloat db = new DataBufferFloat(4);
58: try {
59: csm.getDataElements(-1399, 2, obj, db);
60: fail("Expected ArrayIndexOutOfBoundsException didn't throw");
61: } catch (ClassCastException e) {
62: fail("Unexpected ClassCastException was thrown");
63: } catch (ArrayIndexOutOfBoundsException e) {
64: assertTrue(true);
65: }
66: }
67:
68: public void testGetPixelsMaxValue() throws Exception {
69: ComponentSampleModel csm = new ComponentSampleModel(0, 10, 10,
70: 1, 10, new int[] { 0 });
71: DataBufferInt dbi = new DataBufferInt(100);
72:
73: try {
74: csm
75: .getPixels(8, Integer.MAX_VALUE, 1, 1,
76: (int[]) null, dbi);
77: fail("Exception expected");
78: } catch (ArrayIndexOutOfBoundsException expectedException) {
79: // expected
80: }
81: }
82:
83: public void testGetSamples() {
84: // regression for HARMONY-2801
85: ComponentSampleModel csm = new ComponentSampleModel(3, 10, 10,
86: 1, 10, new int[] { 0 });
87:
88: try {
89: int[] returnValue = csm.getSamples(Integer.MAX_VALUE, 4, 1,
90: 1, 0, new int[] { 0 }, (DataBuffer) null);
91: fail("No exception");
92: } catch (NullPointerException expectedException) {
93: // expected
94: }
95: }
96: }
|