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: * @author ivstolya
019: * @version $Revision$
020: */package java.awt.image;
021:
022: import java.awt.Transparency;
023:
024: import junit.framework.TestCase;
025:
026: public class IndexColorModelRTest extends TestCase {
027: IndexColorModel icm1, icm2, icm3, icm4, icm5, icm6;
028: byte r, g, b, a;
029: byte cmap1[], cmap2[];
030:
031: public static void main(String[] args) {
032: junit.textui.TestRunner.run(IndexColorModelRTest.class);
033: }
034:
035: @Override
036: protected void setUp() throws Exception {
037: super .setUp();
038: r = (byte) 0x1f;
039: g = (byte) 0x5f;
040: b = (byte) 0xff;
041: a = (byte) 0x7f;
042:
043: cmap1 = new byte[6];
044: cmap1[3] = r;
045: cmap1[4] = g;
046: cmap1[5] = b;
047:
048: cmap2 = new byte[8];
049: cmap2[4] = r;
050: cmap2[5] = g;
051: cmap2[6] = b;
052: cmap2[7] = a;
053:
054: icm1 = new IndexColorModel(1, 2, cmap1, 0, false, -1);
055: icm2 = new IndexColorModel(1, 2, cmap1, 0, false, 0);
056: icm3 = new IndexColorModel(1, 2, cmap2, 0, true, 1);
057: icm4 = new IndexColorModel(1, 2, cmap2, 0, true, 0);
058: icm5 = new IndexColorModel(1, 2, cmap2, 0, true, -1);
059:
060: cmap2[3] = a;
061: icm6 = new IndexColorModel(1, 2, cmap2, 0, true, 1);
062: }
063:
064: public final void testIndexColorModelConstructor() {
065: int map[] = new int[2];
066: icm1.getRGBs(map);
067: assertEquals(0xff000000, map[0]);
068: assertEquals(0xff1f5fff, map[1]);
069: assertEquals(Transparency.OPAQUE, icm1.getTransparency());
070: assertEquals(-1, icm1.getTransparentPixel());
071:
072: icm2.getRGBs(map);
073: assertEquals(0x00000000, map[0]);
074: assertEquals(0xff1f5fff, map[1]);
075: assertEquals(Transparency.BITMASK, icm2.getTransparency());
076: assertEquals(0, icm2.getTransparentPixel());
077:
078: icm3.getRGBs(map);
079: assertEquals(0x00000000, map[0]);
080: assertEquals(0x001f5fff, map[1]);
081: assertEquals(Transparency.BITMASK, icm3.getTransparency());
082: assertEquals(1, icm3.getTransparentPixel());
083:
084: icm4.getRGBs(map);
085: assertEquals(0x00000000, map[0]);
086: assertEquals(0x7f1f5fff, map[1]);
087: assertEquals(Transparency.TRANSLUCENT, icm4.getTransparency());
088: assertEquals(0, icm4.getTransparentPixel());
089:
090: icm5.getRGBs(map);
091: assertEquals(0x00000000, map[0]);
092: assertEquals(0x7f1f5fff, map[1]);
093: assertEquals(Transparency.TRANSLUCENT, icm5.getTransparency());
094: assertEquals(0, icm5.getTransparentPixel());
095:
096: icm6.getRGBs(map);
097: assertEquals(0x7f000000, map[0]);
098: assertEquals(0x001f5fff, map[1]);
099: assertEquals(Transparency.TRANSLUCENT, icm6.getTransparency());
100: assertEquals(1, icm6.getTransparentPixel());
101:
102: }
103:
104: public void testGetDataElementOffset() {
105: // Regression test for harmony-2799
106: int bits = 4;
107: int size = 166;
108: IndexColorModel localIndexColorModel = new IndexColorModel(
109: bits, size, new byte[size], new byte[size],
110: new byte[size]);
111: int[] components = new int[] { 0, 0, 0, 0, 0, 0, 0 };
112: int offset = 6;
113:
114: try {
115: localIndexColorModel.getDataElement(components, offset);
116: fail("ArrayIndexOutOfBoundsException expected");
117: } catch (ArrayIndexOutOfBoundsException e) {
118: // valid
119: }
120:
121: }
122: }
|