001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.awt.image;
019:
020: import java.awt.Image;
021: import java.awt.image.BufferedImage;
022:
023: import junit.framework.TestCase;
024:
025: public class BufferedImageTest extends TestCase {
026:
027: public static void main(String[] args) {
028: junit.textui.TestRunner.run(BufferedImageTest.class);
029: }
030:
031: /*
032: * @see TestCase#setUp()
033: */
034: @Override
035: protected void setUp() throws Exception {
036: super .setUp();
037: }
038:
039: /**
040: * Constructor for BufferedImageTest.
041: * @param name
042: */
043: public BufferedImageTest(String name) {
044: super (name);
045: }
046:
047: public final void testGetWritableTile() {
048: BufferedImage bi = new BufferedImage(10, 10,
049: BufferedImage.TYPE_INT_ARGB);
050: bi.getWritableTile(1, 1);
051:
052: //Regression test for HARMONY-1658
053: BufferedImage img = new BufferedImage(10, 16,
054: BufferedImage.TYPE_4BYTE_ABGR);
055: try {
056: img.isTileWritable(1, 1);
057: fail("IllegalArgumentException is expected");
058: } catch (IllegalArgumentException iae) {
059: }
060: }
061:
062: public void testGetProperty() {
063: // Regression test HARMONY-1656
064: BufferedImage img = new BufferedImage(10, 10,
065: BufferedImage.TYPE_INT_ARGB);
066: assertEquals("Image.UndefinedProperty",
067: Image.UndefinedProperty, img.getProperty("XXX"));
068: }
069:
070: //Regression tests for HARMONY-5066
071: public final void testH5066_INT_RGB() {
072: BufferedImage bi = null;
073: try {
074: bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
075: } catch (RasterFormatException e) {
076: fail("Unexpected RasterFormatException: " + e.getMessage());
077: }
078: }
079:
080: public final void testH5066_INT_ARGB() {
081: BufferedImage bi = null;
082: try {
083: bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
084: } catch (RasterFormatException e) {
085: fail("Unexpected RasterFormatException: " + e.getMessage());
086: }
087: }
088:
089: public final void testH5066_INT_ARGB_PRE() {
090: BufferedImage bi = null;
091: try {
092: bi = new BufferedImage(10, 10,
093: BufferedImage.TYPE_INT_ARGB_PRE);
094: } catch (RasterFormatException e) {
095: fail("Unexpected RasterFormatException: " + e.getMessage());
096: }
097: }
098:
099: public final void testH5066_INT_BGR() {
100: BufferedImage bi = null;
101: try {
102: bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_BGR);
103: } catch (RasterFormatException e) {
104: fail("Unexpected RasterFormatException: " + e.getMessage());
105: }
106: }
107:
108: public final void testH5066_3BYTE_BGR() {
109: BufferedImage bi = null;
110: try {
111: bi = new BufferedImage(10, 10, BufferedImage.TYPE_3BYTE_BGR);
112: } catch (RasterFormatException e) {
113: fail("Unexpected RasterFormatException: " + e.getMessage());
114: }
115: }
116:
117: public final void testH5066_4BYTE_ABGR() {
118: BufferedImage bi = null;
119: try {
120: bi = new BufferedImage(10, 10,
121: BufferedImage.TYPE_4BYTE_ABGR);
122: } catch (RasterFormatException e) {
123: fail("Unexpected RasterFormatException: " + e.getMessage());
124: }
125: }
126:
127: public final void testH5066_4BYTE_ABGR_PRE() {
128: BufferedImage bi = null;
129: try {
130: bi = new BufferedImage(10, 10,
131: BufferedImage.TYPE_4BYTE_ABGR_PRE);
132: } catch (RasterFormatException e) {
133: fail("Unexpected RasterFormatException: " + e.getMessage());
134: }
135: }
136:
137: public final void testH5066_USHORT_565_RGB() {
138: BufferedImage bi = null;
139: try {
140: bi = new BufferedImage(10, 10,
141: BufferedImage.TYPE_USHORT_565_RGB);
142: } catch (RasterFormatException e) {
143: fail("Unexpected RasterFormatException: " + e.getMessage());
144: }
145: }
146:
147: public final void testH5066_USHORT_555_RGB() {
148: BufferedImage bi = null;
149: try {
150: bi = new BufferedImage(10, 10,
151: BufferedImage.TYPE_USHORT_555_RGB);
152: } catch (RasterFormatException e) {
153: fail("Unexpected RasterFormatException: " + e.getMessage());
154: }
155: }
156:
157: public final void testH5066_BYTE_GRAY() {
158: BufferedImage bi = null;
159: try {
160: bi = new BufferedImage(10, 10, BufferedImage.TYPE_BYTE_GRAY);
161: } catch (RasterFormatException e) {
162: fail("Unexpected RasterFormatException: " + e.getMessage());
163: }
164: }
165:
166: public final void testH5066_USHORT_GRAY() {
167: BufferedImage bi = null;
168: try {
169: bi = new BufferedImage(10, 10,
170: BufferedImage.TYPE_USHORT_GRAY);
171: } catch (RasterFormatException e) {
172: fail("Unexpected RasterFormatException: " + e.getMessage());
173: }
174: }
175:
176: static byte[] cm1 = new byte[] { 0, (byte) 255 };
177: static byte[] cm2 = new byte[] { 0, (byte) 85, (byte) 170,
178: (byte) 255 };
179: static byte[] cm4 = new byte[] { 0, (byte) 17, (byte) 34,
180: (byte) 51, (byte) 68, (byte) 85, (byte) 102, (byte) 119,
181: (byte) 136, (byte) 153, (byte) 170, (byte) 187, (byte) 204,
182: (byte) 221, (byte) 238, (byte) 255 };
183:
184: public final void testH5066_BYTE_BINARY() {
185: WritableRaster wr = null;
186: IndexColorModel icm = null;
187:
188: try {
189: icm = new IndexColorModel(1, cm1.length, cm1, cm1, cm1);
190: wr = icm.createCompatibleWritableRaster(10, 10);
191: } catch (RasterFormatException e) {
192: fail("Unexpected RasterFormatException (pixel bits = 1): "
193: + e.getMessage());
194: }
195:
196: try {
197: icm = new IndexColorModel(2, cm2.length, cm2, cm2, cm2);
198: wr = icm.createCompatibleWritableRaster(10, 10);
199: } catch (RasterFormatException e) {
200: fail("Unexpected RasterFormatException (pixel bits = 2): "
201: + e.getMessage());
202: }
203:
204: try {
205: icm = new IndexColorModel(4, cm4.length, cm4, cm4, cm4);
206: wr = icm.createCompatibleWritableRaster(10, 10);
207: } catch (RasterFormatException e) {
208: fail("Unexpected RasterFormatException (pixel bits = 4): "
209: + e.getMessage());
210: }
211: }
212:
213: public final void testH5066_BYTE_INDEXED() {
214: BufferedImage bi = null;
215: try {
216: bi = new BufferedImage(10, 10,
217: BufferedImage.TYPE_BYTE_INDEXED);
218: } catch (RasterFormatException e) {
219: fail("Unexpected RasterFormatException: " + e.getMessage());
220: }
221: }
222:
223: }
|