KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > TestPaletteRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.hssf.record;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22 import junit.framework.TestCase;
23 import org.apache.poi.hssf.util.HSSFColor;
24
25 /**
26  * Verifies that custom palette editing works correctly
27  *
28  * @author Brian Sanders (bsanders at risklabs dot com)
29  */

30 public class TestPaletteRecord extends TestCase
31 {
32     public TestPaletteRecord(String JavaDoc name)
33     {
34         super(name);
35     }
36     
37     /**
38      * Tests that the default palette matches the constants of HSSFColor
39      */

40     public void testDefaultPalette()
41     {
42         PaletteRecord palette = new PaletteRecord(PaletteRecord.sid);
43         
44         //make sure all the HSSFColor constants match
45
Map JavaDoc colors = HSSFColor.getIndexHash();
46         Iterator JavaDoc indexes = colors.keySet().iterator();
47         while (indexes.hasNext())
48         {
49             Integer JavaDoc index = (Integer JavaDoc) indexes.next();
50             HSSFColor c = (HSSFColor) colors.get(index);
51             short[] rgbTriplet = c.getTriplet();
52             byte[] paletteTriplet = palette.getColor(index.shortValue());
53             String JavaDoc msg = "Expected HSSFColor constant to match PaletteRecord at index 0x"
54                 + Integer.toHexString(c.getIndex());
55             assertEquals(msg, rgbTriplet[0], paletteTriplet[0] & 0xff);
56             assertEquals(msg, rgbTriplet[1], paletteTriplet[1] & 0xff);
57             assertEquals(msg, rgbTriplet[2], paletteTriplet[2] & 0xff);
58         }
59     }
60 }
61
Popular Tags