1 17 18 19 20 package org.apache.fop.traits; 21 22 import java.awt.Color ; 23 24 import junit.framework.TestCase; 25 26 import org.apache.fop.util.ColorUtil; 27 28 32 public class TraitColorTestCase extends TestCase { 33 34 38 public void testSerialization() throws Exception { 39 Color col = new Color (1.0f, 1.0f, 0.5f, 1.0f); 40 String s = ColorUtil.colorToString(col); 41 42 assertEquals("#ffff80", s); 45 46 col = new Color (1.0f, 0.0f, 0.0f, 0.8f); 47 s = ColorUtil.colorToString(col); 48 assertEquals("#ff0000cc", s); 49 } 50 51 55 public void testDeserialization() throws Exception { 56 Color col = ColorUtil.parseColorString(null, "#ffff7f"); 57 assertEquals(255, col.getRed()); 58 assertEquals(255, col.getGreen()); 59 assertEquals(127, col.getBlue()); 60 assertEquals(255, col.getAlpha()); 61 62 col = ColorUtil.parseColorString(null, "#ff0000cc"); 63 assertEquals(255, col.getRed()); 64 assertEquals(0, col.getGreen()); 65 assertEquals(0, col.getBlue()); 66 assertEquals(204, col.getAlpha()); 67 } 68 69 73 public void testEquals() throws Exception { 74 Color col1 = ColorUtil.parseColorString(null, "#ff0000cc"); 75 Color col2 = ColorUtil.parseColorString(null, "#ff0000cc"); 76 assertEquals(col1, col2); 77 } 78 79 } 80 | Popular Tags |