diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2009-09-18 17:10:42 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2009-09-18 17:10:42 +0000 |
commit | 0e5a789b6b0604bb9c6cc9b782c22f490917e9f9 (patch) | |
tree | 70af78b83ebd8d83f4576c8b9329113ee34aae0f /test/java | |
parent | c5d9b312e01efc7f96a30043d73945594504c7d0 (diff) | |
parent | 9b49126cd645f4377d1bb56d5078a8d4a0cd491e (diff) | |
download | xmlgraphics-fop-0e5a789b6b0604bb9c6cc9b782c22f490917e9f9.tar.gz xmlgraphics-fop-0e5a789b6b0604bb9c6cc9b782c22f490917e9f9.zip |
Merged changes from Trunk up to revision 816269
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@816718 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java')
9 files changed, 325 insertions, 22 deletions
diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index e6a718643..b8bb541cd 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -26,6 +26,8 @@ import org.apache.fop.fonts.TrueTypeAnsiTestCase; import org.apache.fop.image.loader.batik.ImageLoaderTestCase; import org.apache.fop.image.loader.batik.ImagePreloaderTestCase; import org.apache.fop.intermediate.IFMimickingTestCase; +import org.apache.fop.render.extensions.prepress.PageBoundariesTest; +import org.apache.fop.render.extensions.prepress.PageScaleTest; import org.apache.fop.render.pdf.PDFAConformanceTestCase; import org.apache.fop.render.pdf.PDFCMapTestCase; import org.apache.fop.render.pdf.PDFEncodingTestCase; @@ -56,6 +58,8 @@ public class StandardTestSuite { suite.addTest(new TestSuite(ImageLoaderTestCase.class)); suite.addTest(new TestSuite(ImagePreloaderTestCase.class)); suite.addTest(new TestSuite(IFMimickingTestCase.class)); + suite.addTest(new TestSuite(PageBoundariesTest.class)); + suite.addTest(new TestSuite(PageScaleTest.class)); //$JUnit-END$ return suite; } diff --git a/test/java/org/apache/fop/config/FOURIResolverTestCase.java b/test/java/org/apache/fop/config/FOURIResolverTestCase.java index e6f8db712..e0f6d7f81 100644 --- a/test/java/org/apache/fop/config/FOURIResolverTestCase.java +++ b/test/java/org/apache/fop/config/FOURIResolverTestCase.java @@ -39,6 +39,7 @@ public class FOURIResolverTestCase extends TestCase { System.out.println(resolver.checkBaseURL("./test/config")); System.out.println(resolver.checkBaseURL("file:test/config")); System.out.println(resolver.checkBaseURL("fantasy:myconfig")); + System.out.println(resolver.checkBaseURL("file:test\\config\\")); try { resolver.checkBaseURL("./doesnotexist"); fail("Expected an exception for a inexistent base directory"); diff --git a/test/java/org/apache/fop/config/UserConfigTestSuite.java b/test/java/org/apache/fop/config/UserConfigTestSuite.java index f933a0342..168d87d51 100644 --- a/test/java/org/apache/fop/config/UserConfigTestSuite.java +++ b/test/java/org/apache/fop/config/UserConfigTestSuite.java @@ -45,6 +45,7 @@ public class UserConfigTestSuite { suite.addTest(new TestSuite(FontsDirectoryRecursiveTestCase.class)); suite.addTest(new TestSuite(FontsAutoDetectTestCase.class)); suite.addTest(new TestSuite(FontsSubstitutionTestCase.class)); + suite.addTest(new TestSuite(FOURIResolverTestCase.class)); //$JUnit-END$ return suite; } diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTester.java b/test/java/org/apache/fop/fotreetest/FOTreeTester.java index fe44e3e23..ba9fde4f9 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTester.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTester.java @@ -32,6 +32,7 @@ import org.xml.sax.helpers.XMLFilterImpl; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; +import org.apache.fop.apps.FopFactoryConfigurator; import org.apache.fop.fotreetest.ext.TestElementMapping; import org.apache.fop.util.ConsoleEventListenerForTests; @@ -64,8 +65,13 @@ public class FOTreeTester { SAXParser parser = spf.newSAXParser(); XMLReader reader = parser.getXMLReader(); + //Resetting values modified by processing instructions + fopFactory.setBreakIndentInheritanceOnReferenceAreaBoundary( + FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE); + fopFactory.setSourceResolution(FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION); + FOUserAgent ua = fopFactory.newFOUserAgent(); - ua.setBaseURL(testFile.getParentFile().toURL().toString()); + ua.setBaseURL(testFile.getParentFile().toURI().toURL().toString()); ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua)); ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName())); @@ -79,14 +85,19 @@ public class FOTreeTester { reader.setDTDHandler(fop.getDefaultHandler()); reader.setErrorHandler(fop.getDefaultHandler()); reader.setEntityResolver(fop.getDefaultHandler()); - reader.parse(testFile.toURL().toExternalForm()); + try { + reader.parse(testFile.toURI().toURL().toExternalForm()); + } catch (Exception e) { + collector.notifyError(e.getLocalizedMessage()); + throw e; + } List results = collector.getResults(); if (results.size() > 0) { for (int i = 0; i < results.size(); i++) { - System.out.println(((Exception)results.get(i)).getMessage()); + System.out.println((String)results.get(i)); } - throw (Exception)results.get(0); + throw new IllegalStateException((String)results.get(0)); } } @@ -104,6 +115,8 @@ public class FOTreeTester { if ("fop-useragent-break-indent-inheritance".equals(target)) { userAgent.getFactory().setBreakIndentInheritanceOnReferenceAreaBoundary( Boolean.valueOf(data).booleanValue()); + } else if ("fop-source-resolution".equals(target)) { + userAgent.getFactory().setSourceResolution(Float.parseFloat(data)); } super.processingInstruction(target, data); } diff --git a/test/java/org/apache/fop/fotreetest/ResultCollector.java b/test/java/org/apache/fop/fotreetest/ResultCollector.java index 36d111c7f..3f6502803 100644 --- a/test/java/org/apache/fop/fotreetest/ResultCollector.java +++ b/test/java/org/apache/fop/fotreetest/ResultCollector.java @@ -23,7 +23,7 @@ import java.util.Collections; import java.util.List; /** - * This class collects the results from assertions injected into the FO stream. + * This class collects failures for assertions injected into the FO stream. */ public class ResultCollector { @@ -31,7 +31,7 @@ public class ResultCollector { private List results = new java.util.ArrayList(); - /** @return the ResultColletor singleton */ + /** @return the ResultCollector singleton */ public static ResultCollector getInstance() { if (instance == null) { instance = new ResultCollector(); @@ -45,12 +45,23 @@ public class ResultCollector { } /** - * This notifies the ResultCollector about an Exception. - * @param e the exception + * This notifies the ResultCollector about an assertion failure. + * + * @param message the message containing the details */ - public void notifyException(Exception e) { - System.out.println(e.getMessage()); - results.add(e); + public void notifyAssertionFailure(String message) { + System.out.println(message); + results.add(message); + } + + /** + * This notifies the ResultCollector about a testcase that ended + * with a fatal error + * + * @param message the message containing the details + */ + public void notifyError(String message) { + results.add(message); } /** Resets the result list. */ diff --git a/test/java/org/apache/fop/fotreetest/ext/AssertElement.java b/test/java/org/apache/fop/fotreetest/ext/AssertElement.java index 97b73947c..f4a76d7ed 100644 --- a/test/java/org/apache/fop/fotreetest/ext/AssertElement.java +++ b/test/java/org/apache/fop/fotreetest/ext/AssertElement.java @@ -41,7 +41,10 @@ import org.xml.sax.Locator; public class AssertElement extends TestObj { /** - * @see org.apache.fop.fo.FONode#FONode(FONode) + * Creates a new AssertElement instance that is a child + * of the given {@link FONode} + * + * @param parent the parent {@link FONode} */ public AssertElement(FONode parent) { super(parent); @@ -58,6 +61,7 @@ public class AssertElement extends TestObj { ResultCollector collector = ResultCollector.getInstance(); String propName = attlist.getValue("property"); + String expected = attlist.getValue("expected"); String component = null; int dotIndex = propName.indexOf('.'); if (dotIndex >= 0) { @@ -66,8 +70,7 @@ public class AssertElement extends TestObj { } int propID = FOPropertyMapping.getPropertyId(propName); if (propID < 0) { - collector.notifyException(new IllegalArgumentException( - "Property not found: " + propName)); + collector.notifyAssertionFailure("Property not found: " + propName); } else { Property prop; prop = propertyList.getParentPropertyList().get(propID); @@ -94,21 +97,20 @@ public class AssertElement extends TestObj { } String s; if (prop instanceof PercentLength) { - s = ((PercentLength)prop).getString(); + s = prop.getString(); } else { s = String.valueOf(prop); } - String expected = attlist.getValue("expected"); if (!expected.equals(s)) { - collector.notifyException( - new IllegalStateException(locator.getSystemId() + collector.notifyAssertionFailure( + locator.getSystemId() + "\nProperty '" + propName + "' expected to evaluate to '" + expected + "' but got '" + s + "'\n(test:assert in " + propertyList.getParentFObj().getName() + " at line #" + locator.getLineNumber() - + ", column #" + locator.getColumnNumber() + ")\n")); + + ", column #" + locator.getColumnNumber() + ")\n"); } } @@ -120,4 +122,3 @@ public class AssertElement extends TestObj { } } - diff --git a/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java b/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java new file mode 100644 index 000000000..5cd23c17e --- /dev/null +++ b/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java @@ -0,0 +1,176 @@ +/* + * 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.render.extensions.prepress; + +import java.awt.Dimension; +import java.awt.Rectangle; + +import junit.framework.TestCase; + +/** + * Tests for the fox:bleed, fox:crop-offset, fox:crop-box extension properties. + */ +public class PageBoundariesTest extends TestCase { + + private static final Dimension TEST_AREA_SIZE = new Dimension(20000, 15000); + + private static final Rectangle TEST_AREA = new Rectangle(TEST_AREA_SIZE); + + private static final String BLEED = "5pt"; + + private static final String CROP_OFFSET = "8pt"; + + /** + * Default constructor. + */ + public PageBoundariesTest() { + } + + /** + * Creates a test case with the given name. + * + * @param name name for the test case + */ + public PageBoundariesTest(String name) { + super(name); + } + + /** Test for page boundaries. */ + public void testBoundaries1() { + PageBoundaries boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, null); + assertEquals(TEST_AREA, boundaries.getTrimBox()); + + Rectangle bleedBox = boundaries.getBleedBox(); + assertNotNull("Expected not null object", bleedBox); + assertEquals(-5000, bleedBox.x); + assertEquals(-5000, bleedBox.y); + assertEquals(30000, bleedBox.width); + assertEquals(25000, bleedBox.height); + + Rectangle mediaBox = boundaries.getMediaBox(); + assertNotNull("Expected not null object", mediaBox); + assertEquals(-8000, mediaBox.x); + assertEquals(-8000, mediaBox.y); + assertEquals(36000, mediaBox.width); + assertEquals(31000, mediaBox.height); + } + + /** Test for page boundaries. */ + public void testBoundaries2() { + PageBoundaries boundaries = new PageBoundaries( + TEST_AREA_SIZE, BLEED, null, null); + Rectangle bleedBox = boundaries.getBleedBox(); + assertNotNull("Expected not null object", bleedBox); + assertEquals(-5000, bleedBox.x); + assertEquals(-5000, bleedBox.y); + assertEquals(30000, bleedBox.width); + assertEquals(25000, bleedBox.height); + assertEquals(bleedBox, boundaries.getMediaBox()); + } + + /** Two values for the properties. */ + public void testBoundaries2Values() { + PageBoundaries boundaries = new PageBoundaries( + TEST_AREA_SIZE, "5pt 10pt", "6pt \t 12pt", null); + Rectangle bleedBox = boundaries.getBleedBox(); + assertEquals(-10000, bleedBox.x); + assertEquals(-5000, bleedBox.y); + assertEquals(40000, bleedBox.width); + assertEquals(25000, bleedBox.height); + + Rectangle mediaBox = boundaries.getMediaBox(); + assertEquals(-12000, mediaBox.x); + assertEquals(-6000, mediaBox.y); + assertEquals(44000, mediaBox.width); + assertEquals(27000, mediaBox.height); + } + + /** Three values for the properties. */ + public void testBoundaries3Values() { + PageBoundaries boundaries = new PageBoundaries( + TEST_AREA_SIZE, "5pt 10pt 7pt", "6pt \t 12pt 14pt", null); + Rectangle bleedBox = boundaries.getBleedBox(); + assertEquals(-10000, bleedBox.x); + assertEquals(-5000, bleedBox.y); + assertEquals(40000, bleedBox.width); + assertEquals(27000, bleedBox.height); + + Rectangle mediaBox = boundaries.getMediaBox(); + assertEquals(-12000, mediaBox.x); + assertEquals(-6000, mediaBox.y); + assertEquals(44000, mediaBox.width); + assertEquals(35000, mediaBox.height); + } + + /** Four values for the properties. */ + public void testBoundaries4Values() { + PageBoundaries boundaries = new PageBoundaries( + TEST_AREA_SIZE, "5pt 6pt 7pt 8pt", "9pt 10pt 11pt 12pt", null); + Rectangle bleedBox = boundaries.getBleedBox(); + assertEquals(-8000, bleedBox.x); + assertEquals(-5000, bleedBox.y); + assertEquals(34000, bleedBox.width); + assertEquals(27000, bleedBox.height); + + Rectangle mediaBox = boundaries.getMediaBox(); + assertEquals(-12000, mediaBox.x); + assertEquals(-9000, mediaBox.y); + assertEquals(42000, mediaBox.width); + assertEquals(35000, mediaBox.height); + } + + /** Test for the different values of crop-box. */ + public void testCropBox() { + PageBoundaries boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, null); + assertEquals(boundaries.getMediaBox(), boundaries.getCropBox()); + + boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, ""); + assertEquals(boundaries.getMediaBox(), boundaries.getCropBox()); + + boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, "trim-box"); + assertEquals(TEST_AREA, boundaries.getCropBox()); + + boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, "bleed-box"); + assertEquals(boundaries.getBleedBox(), boundaries.getCropBox()); + + boundaries = new PageBoundaries(TEST_AREA_SIZE, BLEED, CROP_OFFSET, "media-box"); + assertEquals(boundaries.getMediaBox(), boundaries.getCropBox()); + } + + /** Test for default values returned when properties are null. */ + public void testBoundariesNull() { + PageBoundaries b = new PageBoundaries(TEST_AREA_SIZE, null, null, null); + + assertEquals("Result should be the same as TEST_AREA object", b.getTrimBox(), TEST_AREA); + assertEquals("Result should be the same as TEST_AREA object", b.getBleedBox(), TEST_AREA); + assertEquals("Result should be the same as TEST_AREA object", b.getMediaBox(), TEST_AREA); + assertEquals("Result should be the same as TEST_AREA object", b.getCropBox(), TEST_AREA); + } + + /** Units must be specified. */ + public void testBoundariesFail() { + try { + new PageBoundaries(TEST_AREA_SIZE, "0", null, null); + fail("Expected IllegalArgumentException. Box should have units"); + } catch (IllegalArgumentException iae) { + // Good! + } + } +} diff --git a/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java b/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java new file mode 100644 index 000000000..cbf6f5226 --- /dev/null +++ b/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java @@ -0,0 +1,79 @@ +/* + * 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.render.extensions.prepress; + +import java.awt.geom.Point2D; + +import junit.framework.TestCase; + +/** + * Tests for the fox:scale extension property. + */ +public class PageScaleTest extends TestCase { + + /** + * Default constructor. + */ + public PageScaleTest() { + super(); + } + + /** + * Creates a test case with the given name. + * + * @param name name for the test case + */ + public PageScaleTest(String name) { + super(name); + } + + /** 1 value is used for both x and y. */ + public void testScale1() { + Point2D res = PageScale.getScale(".5"); + assertEquals(0.5, res.getX(), 0.0); + assertEquals(0.5, res.getY(), 0.0); + } + + /** Two values, used resp. for x and y. */ + public void testScale2() { + Point2D res = PageScale.getScale("1. \t \n 1.2"); + assertEquals(1.0, res.getX(), 0.0); + assertEquals(1.2, res.getY(), 0.0); + } + + /** Scale must not contain units. */ + public void testScaleFail() { + try { + PageScale.getScale("0.5mm 0.5cm"); + fail("Expected IllegalArgumentException. Scale shouldn't contain units"); + } catch (IllegalArgumentException iae) { + // Good! + } + } + + /** @{code null} is returned when scale is unspecified. */ + public void testScaleNull() { + Point2D res = PageScale.getScale(null); + assertNull("Result should be null", res); + res = PageScale.getScale(""); + assertNull("Result should be null", res); + } + +} diff --git a/test/java/org/apache/fop/util/ColorUtilTestCase.java b/test/java/org/apache/fop/util/ColorUtilTestCase.java index bdc57f86a..9b905dd42 100644 --- a/test/java/org/apache/fop/util/ColorUtilTestCase.java +++ b/test/java/org/apache/fop/util/ColorUtilTestCase.java @@ -154,7 +154,8 @@ public class ColorUtilTestCase extends TestCase { 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)); + assertEquals("fop-rgb-icc(1.0,1.0,0.0,#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); @@ -167,7 +168,23 @@ public class ColorUtilTestCase extends TestCase { 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)); + assertEquals("fop-rgb-icc(0.9726,0.7804,0.67840004,#CMYK,,0.0274,0.2196,0.3216,0.0)", + ColorUtil.colorToString(colActual)); + + colSpec = "fop-rgb-icc(1.0,1.0,0.0,#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()); + 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("fop-rgb-icc(1.0,1.0,0.0,#CMYK,,0.0,0.0,1.0,0.0)", + ColorUtil.colorToString(colActual)); } } |