author | aghaisas |
Thu, 24 Mar 2016 12:27:40 +0530 | |
changeset 36905 | 585c3dcca560 |
permissions | -rw-r--r-- |
36905
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
1 |
/* |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
4 |
* |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
8 |
* |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
13 |
* accompanied this code). |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
14 |
* |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
18 |
* |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
21 |
* questions. |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
22 |
*/ |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
23 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
24 |
/* |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
25 |
* @test |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
26 |
* @bug 6185114 |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
27 |
* @summary test SampleModel constructor for different combinations of |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
28 |
* width and height |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
29 |
*/ |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
30 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
31 |
import java.awt.image.DataBuffer; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
32 |
import java.awt.image.Raster; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
33 |
import java.awt.image.SampleModel; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
34 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
35 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
36 |
public class SampleModelConstructorTest { |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
37 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
38 |
public static void main(String[] a) throws RuntimeException { |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
39 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
40 |
SampleModel model = Raster.createBandedRaster(DataBuffer.TYPE_INT, |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
41 |
10, 5, 4, null).getSampleModel(); |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
42 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
43 |
final int inputWidths[] |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
44 |
= {Integer.MIN_VALUE, -1000, -1, 0, 1, 1000, Integer.MAX_VALUE}; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
45 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
46 |
final int inputHeights[] |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
47 |
= {Integer.MIN_VALUE, -1000, -1, 0, 1, 1000, Integer.MAX_VALUE}; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
48 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
49 |
// There are 49 combinations of (width, height) possible using above two |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
50 |
// arrays |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
51 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
52 |
// Only 6 valid combinations of (width, height) that do not throw |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
53 |
// exception are : |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
54 |
// (1, 1) |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
55 |
// (1, 1000) |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
56 |
// (1, Integer.MAX_VALUE) |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
57 |
// (1000, 1) |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
58 |
// (1000, 1000) |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
59 |
// (Integer.MAX_VALUE, 1) |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
60 |
final int expectedCount = 43; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
61 |
int count = 0; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
62 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
63 |
for (int i : inputWidths) { |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
64 |
for (int j : inputHeights) { |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
65 |
try { |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
66 |
SampleModel model2 = model.createCompatibleSampleModel(i, j); |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
67 |
} catch (IllegalArgumentException e) { |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
68 |
count++; |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
69 |
} |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
70 |
} |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
71 |
} |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
72 |
|
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
73 |
if (count != expectedCount) { |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
74 |
throw new RuntimeException( |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
75 |
"Test Failed. Expected IllegalArgumentException Count = " + |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
76 |
expectedCount + " Got Count = " + count); |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
77 |
} |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
78 |
} |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
79 |
} |
585c3dcca560
6185114: Undefined Exception in SampleModel, method createCompatibleSampleModel
aghaisas
parents:
diff
changeset
|
80 |