diff options
author | Jeremias Maerki <jeremias@apache.org> | 2008-02-18 15:02:39 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2008-02-18 15:02:39 +0000 |
commit | 76ebc1fa40782c2e6e8e91e51a5440cbc15198f2 (patch) | |
tree | 3ffe455f4d7965af42a94faa7914b7e7b611ffa6 /test/java/org/apache | |
parent | 263b70846b06d2a119d5d253633e5678a9f908bb (diff) | |
download | xmlgraphics-fop-76ebc1fa40782c2e6e8e91e51a5440cbc15198f2.tar.gz xmlgraphics-fop-76ebc1fa40782c2e6e8e91e51a5440cbc15198f2.zip |
fop-rgb-icc() function did not make the round-trip which caused an error in the color_1.xml test case (intermediate format tests). Added a unit test to test the parsing and round-trip.
Documented the cmyk() function.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@628775 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache')
-rw-r--r-- | test/java/org/apache/fop/UtilityCodeTestSuite.java | 4 | ||||
-rw-r--r-- | test/java/org/apache/fop/traits/TraitColorTestCase.java | 79 | ||||
-rw-r--r-- | test/java/org/apache/fop/util/ColorUtilTestCase.java | 173 |
3 files changed, 175 insertions, 81 deletions
diff --git a/test/java/org/apache/fop/UtilityCodeTestSuite.java b/test/java/org/apache/fop/UtilityCodeTestSuite.java index 19d7d0266..86a3469ce 100644 --- a/test/java/org/apache/fop/UtilityCodeTestSuite.java +++ b/test/java/org/apache/fop/UtilityCodeTestSuite.java @@ -24,10 +24,10 @@ import junit.framework.TestSuite; import org.apache.fop.pdf.PDFObjectTestCase; import org.apache.fop.traits.BorderPropsTestCase; -import org.apache.fop.traits.TraitColorTestCase; import org.apache.fop.util.DataURIResolverTestCase; import org.apache.fop.util.ElementListUtilsTestCase; import org.apache.fop.util.PDFNumberTestCase; +import org.apache.fop.util.ColorUtilTestCase; import org.apache.fop.util.UnitConvTestCase; /** @@ -46,7 +46,7 @@ public class UtilityCodeTestSuite { suite.addTest(new TestSuite(PDFNumberTestCase.class)); suite.addTest(new TestSuite(PDFObjectTestCase.class)); suite.addTest(new TestSuite(UnitConvTestCase.class)); - suite.addTest(new TestSuite(TraitColorTestCase.class)); + suite.addTest(new TestSuite(ColorUtilTestCase.class)); suite.addTest(new TestSuite(BorderPropsTestCase.class)); suite.addTest(new TestSuite(ElementListUtilsTestCase.class)); suite.addTest(new TestSuite(DataURIResolverTestCase.class)); diff --git a/test/java/org/apache/fop/traits/TraitColorTestCase.java b/test/java/org/apache/fop/traits/TraitColorTestCase.java deleted file mode 100644 index 90f73dcc3..000000000 --- a/test/java/org/apache/fop/traits/TraitColorTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.traits; - -import java.awt.Color; - -import junit.framework.TestCase; - -import org.apache.fop.util.ColorUtil; - -/** - * Tests the Trait.Color class. - * TODO: This actually tests the ColorUtil class now. - */ -public class TraitColorTestCase extends TestCase { - - /** - * Test serialization to String. - * @throws Exception if an error occurs - */ - public void testSerialization() throws Exception { - Color col = new Color(1.0f, 1.0f, 0.5f, 1.0f); - String s = ColorUtil.colorToString(col); - - //This is what the old color spit out. Now it is 80 due to rounding - //assertEquals("#ffff7f", s); - assertEquals("#ffff80", s); - - col = new Color(1.0f, 0.0f, 0.0f, 0.8f); - s = ColorUtil.colorToString(col); - assertEquals("#ff0000cc", s); - } - - /** - * Test deserialization from String. - * @throws Exception if an error occurs - */ - public void testDeserialization() throws Exception { - Color col = ColorUtil.parseColorString(null, "#ffff7f"); - assertEquals(255, col.getRed()); - assertEquals(255, col.getGreen()); - assertEquals(127, col.getBlue()); - assertEquals(255, col.getAlpha()); - - col = ColorUtil.parseColorString(null, "#ff0000cc"); - assertEquals(255, col.getRed()); - assertEquals(0, col.getGreen()); - assertEquals(0, col.getBlue()); - assertEquals(204, col.getAlpha()); - } - - /** - * Test equals(). - * @throws Exception if an error occurs - */ - public void testEquals() throws Exception { - Color col1 = ColorUtil.parseColorString(null, "#ff0000cc"); - Color col2 = ColorUtil.parseColorString(null, "#ff0000cc"); - assertEquals(col1, col2); - } - -} diff --git a/test/java/org/apache/fop/util/ColorUtilTestCase.java b/test/java/org/apache/fop/util/ColorUtilTestCase.java new file mode 100644 index 000000000..bdeca4379 --- /dev/null +++ b/test/java/org/apache/fop/util/ColorUtilTestCase.java @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.util; + +import java.awt.Color; +import java.awt.color.ColorSpace; + +import junit.framework.TestCase; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; + +/** + * Tests the ColorUtil class. + */ +public class ColorUtilTestCase extends TestCase { + + /** + * Test serialization to String. + * @throws Exception if an error occurs + */ + public void testSerialization() throws Exception { + Color col = new Color(1.0f, 1.0f, 0.5f, 1.0f); + String s = ColorUtil.colorToString(col); + + //This is what the old color spit out. Now it is 80 due to rounding + //assertEquals("#ffff7f", s); + assertEquals("#ffff80", s); + + col = new Color(1.0f, 0.0f, 0.0f, 0.8f); + s = ColorUtil.colorToString(col); + assertEquals("#ff0000cc", s); + } + + /** + * Test deserialization from String. + * @throws Exception if an error occurs + */ + public void testDeserialization() throws Exception { + Color col = ColorUtil.parseColorString(null, "#ffff7f"); + assertEquals(255, col.getRed()); + assertEquals(255, col.getGreen()); + assertEquals(127, col.getBlue()); + assertEquals(255, col.getAlpha()); + + col = ColorUtil.parseColorString(null, "#ff0000cc"); + assertEquals(255, col.getRed()); + assertEquals(0, col.getGreen()); + assertEquals(0, col.getBlue()); + assertEquals(204, col.getAlpha()); + } + + /** + * Test equals(). + * @throws Exception if an error occurs + */ + public void testEquals() throws Exception { + Color col1 = ColorUtil.parseColorString(null, "#ff0000cc"); + Color col2 = ColorUtil.parseColorString(null, "#ff0000cc"); + assertEquals(col1, col2); + } + + /** + * Tests the rgb() function. + * @throws Exception if an error occurs + */ + public void testRGB() throws Exception { + FopFactory fopFactory = FopFactory.newInstance(); + FOUserAgent ua = fopFactory.newFOUserAgent(); + Color colActual; + + colActual = ColorUtil.parseColorString(ua, "rgb(255, 40, 0)"); + assertEquals(255, colActual.getRed()); + assertEquals(40, colActual.getGreen()); + assertEquals(0, colActual.getBlue()); + assertEquals(255, colActual.getAlpha()); + assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colActual.getColorSpace()); + } + + /** + * Tests the fop-rgb-icc() function. + * @throws Exception if an error occurs + */ + public void testRGBICC() throws Exception { + FopFactory fopFactory = FopFactory.newInstance(); + ColorSpace cs = fopFactory.getColorSpace(null, + "src/java/org/apache/fop/pdf/sRGB Color Space Profile.icm"); + assertNotNull(cs); + + + FOUserAgent ua = fopFactory.newFOUserAgent(); + ColorExt colActual; + + //fop-rgb-icc() is used instead of rgb-icc() inside FOP! + String colSpec = "fop-rgb-icc(1.0,0.0,0.0,sRGBAlt," + + "\"src/java/org/apache/fop/pdf/sRGB Color Space Profile.icm\",1.0,0.0,0.0)"; + colActual = (ColorExt)ColorUtil.parseColorString(ua, colSpec); + //assertEquals(255, colActual.getRed()); //253 is returned + //assertEquals(24, colActual.getGreen()); //24 is returned + //I don't understand the difference. Maybe Java's sRGB and HP's sRGB are somehow not + //equivalent. This is only going to be a problem if anyone actually makes use of the + //RGB fallback in any renderer. + //TODO Anyone know what's going on here? + assertEquals(0, colActual.getBlue()); + assertEquals(cs, colActual.getColorSpace()); + float[] comps = colActual.getOriginalColorComponents(); + assertEquals(3, comps.length); + assertEquals(1f, comps[0], 0); + assertEquals(0f, comps[1], 0); + assertEquals(0f, comps[2], 0); + + assertEquals(colSpec, ColorUtil.colorToString(colActual)); + + colSpec = "fop-rgb-icc(1.0,0.5,0.0,blah," + + "\"invalid.icm\",1.0,0.5,0.0,0.15)"; + Color colFallback = ColorUtil.parseColorString(ua, colSpec); + assertEquals(new Color(1.0f, 0.5f, 0.0f), colFallback); + } + + /** + * Tests the cmyk() function. + * @throws Exception if an error occurs + */ + public void testCMYK() throws Exception { + ColorExt colActual; + String colSpec; + + colSpec = "cmyk(0.0, 0.0, 1.0, 0.0)"; + colActual = (ColorExt)ColorUtil.parseColorString(null, colSpec); + assertEquals(255, colActual.getRed()); + assertEquals(255, colActual.getGreen()); + assertEquals(0, colActual.getBlue()); + assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace()); + float[] comps = colActual.getOriginalColorComponents(); + assertEquals(4, comps.length); + assertEquals(0f, comps[0], 0); + assertEquals(0f, comps[1], 0); + assertEquals(1f, comps[2], 0); + assertEquals(0f, comps[3], 0); + assertEquals("cmyk(0.0,0.0,1.0,0.0)", ColorUtil.colorToString(colActual)); + + colSpec = "cmyk(0.0274, 0.2196, 0.3216, 0.0)"; + colActual = (ColorExt)ColorUtil.parseColorString(null, colSpec); + assertEquals(248, colActual.getRed()); + assertEquals(199, colActual.getGreen()); + assertEquals(172, colActual.getBlue()); + assertEquals(CMYKColorSpace.getInstance(), colActual.getColorSpace()); + comps = colActual.getOriginalColorComponents(); + assertEquals(0.0274f, comps[0], 0.001); + assertEquals(0.2196f, comps[1], 0.001); + assertEquals(0.3216f, comps[2], 0.001); + assertEquals(0f, comps[3], 0); + assertEquals("cmyk(0.0274,0.2196,0.3216,0.0)", ColorUtil.colorToString(colActual)); + } + +} |