aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-01-30 19:28:59 +0000
committerJeremias Maerki <jeremias@apache.org>2009-01-30 19:28:59 +0000
commit5a32e5468b4df6fd33c76027f8f72385f8140373 (patch)
treeef2451e54e1b094df3c0051f829b0428029d5269
parent77c49600624d70f8de7a19757342bd897c6de20f (diff)
downloadxmlgraphics-fop-5a32e5468b4df6fd33c76027f8f72385f8140373.tar.gz
xmlgraphics-fop-5a32e5468b4df6fd33c76027f8f72385f8140373.zip
Fixed test error for transcoders.
Enabled disabling strict validation from inside the test case. This enabled activating the border/padding test case for region references. Refactored layout engine and intermediate format tests a bit to increase code reuse. Fixed the way border/padding are set on the area tree. The current way had unwanted side-effects for the AreaTreeParser. Added support for border/padding on region references when parsing from area tree XML. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@739386 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--build.xml6
-rw-r--r--src/java/org/apache/fop/area/AreaTreeParser.java5
-rw-r--r--src/java/org/apache/fop/area/Page.java14
-rw-r--r--src/java/org/apache/fop/area/RegionReference.java12
-rw-r--r--test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java76
-rw-r--r--test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java22
-rw-r--r--test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java2
-rw-r--r--test/java/org/apache/fop/intermediate/IFParserTestCase.java17
-rw-r--r--test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java2
-rw-r--r--test/java/org/apache/fop/layoutengine/LayoutEngineTester.java77
-rw-r--r--test/java/org/apache/fop/layoutengine/TestEnvironment.java172
-rw-r--r--test/java/org/apache/fop/util/ConsoleEventListenerForTests.java57
-rw-r--r--test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml7
13 files changed, 293 insertions, 176 deletions
diff --git a/build.xml b/build.xml
index fb1b451b9..fca9cec52 100644
--- a/build.xml
+++ b/build.xml
@@ -593,11 +593,7 @@ list of possible build targets.
<include name="org/apache/fop/area/AreaTreeControl*"/>
<include name="org/apache/fop/svg/**"/>
<include name="org/apache/fop/fonts/**"/>
- <include name="org/apache/fop/image/FopImag*.class"/>
- <include name="org/apache/fop/image/Jpeg*"/>
- <include name="org/apache/fop/image/EPS*"/>
- <include name="org/apache/fop/image/Abstract*"/>
- <include name="org/apache/fop/image/analyser/*.class"/>
+ <include name="org/apache/fop/image/loader/batik/BatikImageFlavors*.class"/>
<include name="org/apache/fop/util/CMYKColorSpace*.class"/>
<include name="org/apache/fop/util/Color*.class"/>
<include name="org/apache/fop/util/ASCII*.class"/>
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index 65587ec3d..580ce19f4 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -498,6 +498,7 @@ public class AreaTreeParser {
transferForeignObjects(attributes, body);
body.setCTM(getAttributeAsCTM(attributes, "ctm"));
setAreaAttributes(attributes, body);
+ setTraits(attributes, body, SUBSET_BORDER_PADDING);
rv.setRegionReference(body);
currentPageViewport.getPage().setRegionViewport(
Constants.FO_REGION_BODY, rv);
@@ -939,6 +940,7 @@ public class AreaTreeParser {
transferForeignObjects(attributes, reg);
reg.setCTM(getAttributeAsCTM(attributes, "ctm"));
setAreaAttributes(attributes, reg);
+ setTraits(attributes, reg, SUBSET_BORDER_PADDING);
rv.setRegionReference(reg);
currentPageViewport.getPage().setRegionViewport(
side, rv);
@@ -993,6 +995,9 @@ public class AreaTreeParser {
Trait.PADDING_BEFORE, Trait.PADDING_AFTER, Trait.PADDING_START, Trait.PADDING_END,
Trait.START_INDENT, Trait.END_INDENT,
Trait.IS_REFERENCE_AREA, Trait.IS_VIEWPORT_AREA};
+ private static final Object[] SUBSET_BORDER_PADDING = new Object[] {
+ Trait.BORDER_BEFORE, Trait.BORDER_AFTER, Trait.BORDER_START, Trait.BORDER_END,
+ Trait.PADDING_BEFORE, Trait.PADDING_AFTER, Trait.PADDING_START, Trait.PADDING_END};
private void setTraits(Attributes attributes, Area area, Object[] traitSubset) {
for (int i = traitSubset.length; --i >= 0;) {
diff --git a/src/java/org/apache/fop/area/Page.java b/src/java/org/apache/fop/area/Page.java
index 167d28e6b..4607dfb74 100644
--- a/src/java/org/apache/fop/area/Page.java
+++ b/src/java/org/apache/fop/area/Page.java
@@ -128,8 +128,10 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
}
// set borders and padding traits
// (a little extensions wrt what prescribed by the specs at 6.4.14)
- TraitSetter.addBorders(rr, r.getCommonBorderPaddingBackground(), false, false, false, false, null);
- TraitSetter.addPadding(rr, r.getCommonBorderPaddingBackground(), false, false, false, false, null);
+ TraitSetter.addBorders(rr, r.getCommonBorderPaddingBackground(),
+ false, false, false, false, null);
+ TraitSetter.addPadding(rr, r.getCommonBorderPaddingBackground(),
+ false, false, false, false, null);
setRegionReferencePosition(rr, r, rvp.getViewArea());
rvp.setRegionReference(rr);
setRegionViewport(r.getNameId(), rvp);
@@ -182,8 +184,12 @@ public class Page extends AreaTreeObject implements Serializable, Cloneable {
FODimension reldims = new FODimension(0, 0);
rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(),
r.getWritingMode(), absRegVPRect, reldims));
- rr.setIPD(reldims.ipd);
- rr.setBPD(reldims.bpd);
+ rr.setIPD(reldims.ipd
+ - rr.getBorderAndPaddingWidthStart()
+ - rr.getBorderAndPaddingWidthEnd());
+ rr.setBPD(reldims.bpd
+ - rr.getBorderAndPaddingWidthBefore()
+ - rr.getBorderAndPaddingWidthAfter());
}
/**
diff --git a/src/java/org/apache/fop/area/RegionReference.java b/src/java/org/apache/fop/area/RegionReference.java
index bee597673..200f0bff3 100644
--- a/src/java/org/apache/fop/area/RegionReference.java
+++ b/src/java/org/apache/fop/area/RegionReference.java
@@ -73,18 +73,6 @@ public class RegionReference extends Area implements Cloneable {
blocks.add(child);
}
- /** {@inheritDoc} */
- public int getBPD() {
- // subtract bpd of borders and padding before / after
- return super.getBPD() - getBorderAndPaddingWidthBefore() - getBorderAndPaddingWidthAfter();
- }
-
- /** {@inheritDoc} */
- public int getIPD() {
- // subtract ipd of borders and padding start / end
- return super.getIPD() - getBorderAndPaddingWidthStart() - getBorderAndPaddingWidthEnd();
- }
-
/**
* Set the Coordinate Transformation Matrix which transforms content
* coordinates in this region reference area which are specified in
diff --git a/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java b/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
index 465e1405c..c246488e1 100644
--- a/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
+++ b/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
@@ -27,17 +27,11 @@ import java.io.OutputStream;
import java.net.MalformedURLException;
import javax.xml.transform.ErrorListener;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
import org.custommonkey.xmlunit.XMLTestCase;
import org.w3c.dom.Document;
@@ -45,11 +39,13 @@ import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.events.model.EventSeverity;
+import org.apache.fop.layoutengine.TestEnvironment;
import org.apache.fop.util.ConsoleEventListenerForTests;
/**
@@ -57,12 +53,11 @@ import org.apache.fop.util.ConsoleEventListenerForTests;
*/
public abstract class AbstractIntermediateTestCase extends XMLTestCase {
- /** the FOP factory */
- protected static FopFactory fopFactory = FopFactory.newInstance();
+ /** the test environment */
+ protected static TestEnvironment env = new TestEnvironment();
- /** the JAXP transformer factory */
- protected static SAXTransformerFactory tFactory
- = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
+ /** the FOP factory */
+ protected FopFactory fopFactory;
/** the main base directory for tests */
protected File mainDir = new File("test/layoutengine");
@@ -71,18 +66,20 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
/** the output directory for any files generated by the tests */
protected File outputDir;
- private static Templates stylesheet = null;
-
/** the test file */
protected File testFile;
+ /** the test document as DOM */
+ protected Document testDoc;
/** the intermediate format document as DOM */
protected Document intermediate;
/**
* Constructor for the test suite that is used for each test file.
* @param testFile the test file to run
+ * @throws IOException if an I/O error occurs while loading the test case
*/
- public AbstractIntermediateTestCase(File testFile) {
+ public AbstractIntermediateTestCase(File testFile)
+ throws IOException {
super(testFile.getName());
this.testFile = testFile;
}
@@ -91,10 +88,11 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
protected void setUp() throws Exception {
super.setUp();
setupOutputDirectory();
- intermediate = buildIntermediateDocument(
- new StreamSource(testFile), getStylesheet());
+ this.testDoc = env.loadTestCase(testFile);
+ this.fopFactory = env.getFopFactory(testDoc);
+ intermediate = buildIntermediateDocument(env.getTestcase2FOStylesheet());
if (outputDir != null) {
- saveDOM(intermediate, new File(outputDir,
+ env.saveDOM(intermediate, new File(outputDir,
getName() + ".1" + getIntermediateFileExtension()));
}
validate(intermediate);
@@ -102,7 +100,10 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
/** {@inheritDoc} */
protected void tearDown() throws Exception {
- this.intermediate = null; //Release memory
+ //Release memory
+ this.intermediate = null;
+ this.fopFactory = null;
+ this.testDoc = null;
super.tearDown();
}
@@ -132,40 +133,11 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
/**
* Builds an intermediate format document from a source file.
- * @param source the source file
* @param templates the (optional) stylesheet
* @return the intermediate format document as a DOM
* @throws Exception if an error occurs while processing the document
*/
- protected abstract Document buildIntermediateDocument(
- Source source, Templates templates) throws Exception;
-
- /**
- * Returns the stylesheet that transforms layout engine test cases into normal FO files.
- * @return the stylesheet
- * @throws TransformerConfigurationException if the stylesheet cannot be instantiated
- */
- protected Templates getStylesheet() throws TransformerConfigurationException {
- if (stylesheet == null) {
- File xsltFile = new File(mainDir, "testcase2fo.xsl");
- stylesheet = tFactory.newTemplates(new StreamSource(xsltFile));
- }
- return stylesheet;
- }
-
- /**
- * Saves a DOM to a file.
- * @param doc the DOM Document
- * @param tgtFile the target file
- * @throws Exception if an error occurs while serializing the DOM
- */
- protected void saveDOM(Document doc, File tgtFile) throws Exception {
- Transformer transformer = tFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- Source src = new DOMSource(doc);
- Result res = new StreamResult(tgtFile);
- transformer.transform(src, res);
- }
+ protected abstract Document buildIntermediateDocument(Templates templates) throws Exception;
/**
* Creates a new FOP user agent.
@@ -176,7 +148,7 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
try {
userAgent.setBaseURL(testDir.toURI().toURL().toExternalForm());
userAgent.getEventBroadcaster().addEventListener(
- new ConsoleEventListenerForTests(testFile.getName()));
+ new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.FATAL));
} catch (MalformedURLException e) {
//ignore, won't happen
}
@@ -204,7 +176,7 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
Document doc = parseAndRenderToIntermediateFormat(src);
if (outputDir != null) {
File tgtFile = new File(outputDir, getName() + ".2" + getIntermediateFileExtension());
- saveDOM(doc, tgtFile);
+ env.saveDOM(doc, tgtFile);
}
assertXMLEqual(intermediate, doc);
@@ -230,7 +202,7 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
out = new FileOutputStream(tgtFile);
out = new BufferedOutputStream(out);
} else {
- out = new ByteArrayOutputStream();
+ out = new NullOutputStream();
}
try {
Source src = new DOMSource(intermediate);
diff --git a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
index fb394b099..3d029778d 100644
--- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
+++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
@@ -20,6 +20,7 @@
package org.apache.fop.intermediate;
import java.io.File;
+import java.io.IOException;
import java.io.OutputStream;
import javax.xml.transform.Result;
@@ -27,6 +28,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.TransformerHandler;
@@ -34,6 +36,7 @@ import org.w3c.dom.Document;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.AreaTreeParser;
@@ -50,8 +53,10 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTestCase {
/**
* Constructor for the test suite that is used for each test file.
* @param testFile the test file to run
+ * @throws IOException
+ * @throws IOException if an I/O error occurs while loading the test case
*/
- public AreaTreeParserTestCase(File testFile) {
+ public AreaTreeParserTestCase(File testFile) throws IOException {
super(testFile);
}
@@ -61,18 +66,13 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTestCase {
}
/** {@inheritDoc} */
- protected Document buildIntermediateDocument(Source src, Templates templates)
+ protected Document buildIntermediateDocument(Templates templates)
throws Exception {
- Transformer transformer;
- if (templates != null) {
- transformer = templates.newTransformer();
- } else {
- transformer = tFactory.newTransformer();
- }
+ Transformer transformer = templates.newTransformer();
setErrorListener(transformer);
//Set up XMLRenderer to render to a DOM
- TransformerHandler handler = tFactory.newTransformerHandler();
+ TransformerHandler handler = env.getTransformerFactory().newTransformerHandler();
DOMResult domResult = new DOMResult();
handler.setResult(domResult);
@@ -91,7 +91,7 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTestCase {
Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AREA_TREE, userAgent);
Result res = new SAXResult(fop.getDefaultHandler());
- transformer.transform(src, res);
+ transformer.transform(new DOMSource(testDoc), res);
return (Document)domResult.getNode();
}
@@ -113,7 +113,7 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTestCase {
AreaTreeParser parser = new AreaTreeParser();
//Set up XMLRenderer to render to a DOM
- TransformerHandler handler = tFactory.newTransformerHandler();
+ TransformerHandler handler = env.getTransformerFactory().newTransformerHandler();
DOMResult domResult = new DOMResult();
handler.setResult(domResult);
XMLRenderer renderer = new XMLRenderer();
diff --git a/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java b/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java
index 2c7bd09e4..661dbadf3 100644
--- a/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java
+++ b/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java
@@ -53,7 +53,7 @@ public class AreaTreeXMLFormatTestSuite {
}
private static void addATTestCase(TestSuite suite,
- final File f) {
+ final File f) throws IOException {
suite.addTest(new AreaTreeParserTestCase(f) {
public void runTest() throws Exception {
try {
diff --git a/test/java/org/apache/fop/intermediate/IFParserTestCase.java b/test/java/org/apache/fop/intermediate/IFParserTestCase.java
index 0dff71ce6..8a0268aa6 100644
--- a/test/java/org/apache/fop/intermediate/IFParserTestCase.java
+++ b/test/java/org/apache/fop/intermediate/IFParserTestCase.java
@@ -46,6 +46,7 @@ import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.layoutengine.TestEnvironment;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFParser;
@@ -57,6 +58,7 @@ import org.apache.fop.render.intermediate.IFSerializer;
*/
public class IFParserTestCase extends AbstractIntermediateTestCase {
+ private static TestEnvironment env = new TestEnvironment();
private static Schema ifSchema;
private static Schema getIFSchema() throws SAXException {
@@ -78,8 +80,9 @@ public class IFParserTestCase extends AbstractIntermediateTestCase {
/**
* Constructor for the test suite that is used for each test file.
* @param testFile the test file to run
+ * @throws IOException if an I/O error occurs while loading the test case
*/
- public IFParserTestCase(File testFile) {
+ public IFParserTestCase(File testFile) throws IOException {
super(testFile);
}
@@ -94,15 +97,9 @@ public class IFParserTestCase extends AbstractIntermediateTestCase {
}
/** {@inheritDoc} */
- protected Document buildIntermediateDocument(Source src, Templates templates)
+ protected Document buildIntermediateDocument(Templates templates)
throws Exception {
- Transformer transformer;
- if (templates != null) {
- transformer = templates.newTransformer();
- } else {
- transformer = tFactory.newTransformer();
- }
-
+ Transformer transformer = templates.newTransformer();
setErrorListener(transformer);
//Set up XMLRenderer to render to a DOM
@@ -129,7 +126,7 @@ public class IFParserTestCase extends AbstractIntermediateTestCase {
Fop fop = fopFactory.newFop(userAgent);
Result res = new SAXResult(fop.getDefaultHandler());
- transformer.transform(src, res);
+ transformer.transform(new DOMSource(testDoc), res);
return (Document)domResult.getNode();
}
diff --git a/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java b/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java
index f8511cadc..438ff7672 100644
--- a/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java
+++ b/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java
@@ -53,7 +53,7 @@ public class IntermediateFormatTestSuite {
}
private static void addIFTestCase(TestSuite suite,
- final File f) {
+ final File f) throws IOException {
suite.addTest(new IFParserTestCase(f) {
public void runTest() throws Exception {
try {
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
index 583a41954..d938a852b 100644
--- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
@@ -26,21 +26,14 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
import javax.xml.transform.Source;
-import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
@@ -50,13 +43,11 @@ import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import org.apache.xpath.XPathAPI;
-import org.apache.xpath.objects.XObject;
-
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FormattingResults;
+import org.apache.fop.events.model.EventSeverity;
import org.apache.fop.intermediate.IFTester;
import org.apache.fop.layoutmgr.ElementListObserver;
import org.apache.fop.render.xml.XMLRenderer;
@@ -70,15 +61,7 @@ public class LayoutEngineTester {
private static final Map AT_CHECK_CLASSES = new java.util.HashMap();
- // configure fopFactory as desired
- private FopFactory fopFactory = FopFactory.newInstance();
- private FopFactory fopFactoryWithBase14Kerning = FopFactory.newInstance();
-
- private SAXTransformerFactory tfactory
- = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
-
- private Templates testcase2fo;
- private Templates testcase2checks;
+ private TestEnvironment env = new TestEnvironment();
private File areaTreeBackupDir;
private IFTester ifTester;
@@ -97,29 +80,9 @@ public class LayoutEngineTester {
*/
public LayoutEngineTester(File areaTreeBackupDir) {
this.areaTreeBackupDir = areaTreeBackupDir;
- fopFactory.getFontManager().setBase14KerningEnabled(false);
- fopFactoryWithBase14Kerning.getFontManager().setBase14KerningEnabled(true);
this.ifTester = new IFTester(areaTreeBackupDir);
}
- private Templates getTestcase2FOStylesheet() throws TransformerConfigurationException {
- if (testcase2fo == null) {
- //Load and cache stylesheet
- Source src = new StreamSource(new File("test/layoutengine/testcase2fo.xsl"));
- testcase2fo = tfactory.newTemplates(src);
- }
- return testcase2fo;
- }
-
- private Templates getTestcase2ChecksStylesheet() throws TransformerConfigurationException {
- if (testcase2checks == null) {
- //Load and cache stylesheet
- Source src = new StreamSource(new File("test/layoutengine/testcase2checks.xsl"));
- testcase2checks = tfactory.newTemplates(src);
- }
- return testcase2checks;
- }
-
/**
* Runs a single layout engine test case.
* @param testFile Test case to run
@@ -139,30 +102,23 @@ public class LayoutEngineTester {
Fop fop;
try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- dbf.setValidating(false);
- DocumentBuilder builder = dbf.newDocumentBuilder();
- Document testDoc = builder.parse(testFile);
-
- XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/base14kerning");
- String s = xo.str();
- boolean base14kerning = ("true".equalsIgnoreCase(s));
- FopFactory effFactory = (base14kerning ? fopFactoryWithBase14Kerning : fopFactory);
+ Document testDoc = env.loadTestCase(testFile);
+ FopFactory effFactory = env.getFopFactory(testDoc);
//Setup Transformer to convert the testcase XML to XSL-FO
- Transformer transformer = getTestcase2FOStylesheet().newTransformer();
+ Transformer transformer = env.getTestcase2FOStylesheet().newTransformer();
Source src = new DOMSource(testDoc);
//Setup Transformer to convert the area tree to a DOM
- TransformerHandler athandler = tfactory.newTransformerHandler();
+ TransformerHandler athandler;
+ athandler = env.getTransformerFactory().newTransformerHandler();
athandler.setResult(domres);
//Setup FOP for area tree rendering
FOUserAgent ua = effFactory.newFOUserAgent();
ua.setBaseURL(testFile.getParentFile().toURL().toString());
ua.getEventBroadcaster().addEventListener(
- new ConsoleEventListenerForTests(testFile.getName()));
+ new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN));
XMLRenderer atrenderer = new XMLRenderer();
atrenderer.setUserAgent(ua);
@@ -178,7 +134,8 @@ public class LayoutEngineTester {
Document doc = (Document)domres.getNode();
if (this.areaTreeBackupDir != null) {
- saveAreaTreeXML(doc, new File(this.areaTreeBackupDir, testFile.getName() + ".at.xml"));
+ env.saveDOM(doc,
+ new File(this.areaTreeBackupDir, testFile.getName() + ".at.xml"));
}
FormattingResults results = fop.getResults();
LayoutResult result = new LayoutResult(doc, elCollector, results);
@@ -215,7 +172,7 @@ public class LayoutEngineTester {
* @throws TransformerException if a problem occurs in XSLT/JAXP
*/
protected void checkAll(File testFile, LayoutResult result) throws TransformerException {
- Transformer transformer = getTestcase2ChecksStylesheet().newTransformer();
+ Transformer transformer = env.getTestcase2ChecksStylesheet().newTransformer();
Source src = new StreamSource(testFile);
DOMResult res = new DOMResult();
transformer.transform(src, res);
@@ -266,16 +223,4 @@ public class LayoutEngineTester {
}
}
- /**
- * Save the area tree XML for later inspection.
- * @param doc area tree as a DOM document
- * @param target target file
- * @throws TransformerException if a problem occurs during serialization
- */
- protected void saveAreaTreeXML(Document doc, File target) throws TransformerException {
- Transformer transformer = tfactory.newTransformer();
- Source src = new DOMSource(doc);
- Result res = new StreamResult(target);
- transformer.transform(src, res);
- }
}
diff --git a/test/java/org/apache/fop/layoutengine/TestEnvironment.java b/test/java/org/apache/fop/layoutengine/TestEnvironment.java
new file mode 100644
index 000000000..ad976ff8c
--- /dev/null
+++ b/test/java/org/apache/fop/layoutengine/TestEnvironment.java
@@ -0,0 +1,172 @@
+/*
+ * 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.layoutengine;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
+
+import org.apache.xpath.XPathAPI;
+import org.apache.xpath.objects.XObject;
+
+import org.apache.fop.apps.FopFactory;
+
+/**
+ * Test environment and helper code for running FOP tests.
+ */
+public class TestEnvironment {
+
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+ private FopFactory fopFactoryWithBase14Kerning = FopFactory.newInstance();
+
+ private SAXTransformerFactory tfactory
+ = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
+
+ private DocumentBuilderFactory domBuilderFactory;
+
+ private Templates testcase2fo;
+ private Templates testcase2checks;
+
+ /**
+ * Main constructor.
+ */
+ public TestEnvironment() {
+ fopFactory.getFontManager().setBase14KerningEnabled(false);
+ fopFactoryWithBase14Kerning.getFontManager().setBase14KerningEnabled(true);
+ domBuilderFactory = DocumentBuilderFactory.newInstance();
+ domBuilderFactory.setNamespaceAware(true);
+ domBuilderFactory.setValidating(false);
+ }
+
+ /**
+ * Returns the stylesheet for convert extracting the XSL-FO part from the test case.
+ * @return the stylesheet
+ * @throws TransformerConfigurationException if an error occurs loading the stylesheet
+ */
+ public Templates getTestcase2FOStylesheet() throws TransformerConfigurationException {
+ if (testcase2fo == null) {
+ //Load and cache stylesheet
+ Source src = new StreamSource(new File("test/layoutengine/testcase2fo.xsl"));
+ testcase2fo = tfactory.newTemplates(src);
+ }
+ return testcase2fo;
+ }
+
+ /**
+ * Returns the stylesheet for convert extracting the checks from the test case.
+ * @return the stylesheet
+ * @throws TransformerConfigurationException if an error occurs loading the stylesheet
+ */
+ public Templates getTestcase2ChecksStylesheet() throws TransformerConfigurationException {
+ if (testcase2checks == null) {
+ //Load and cache stylesheet
+ Source src = new StreamSource(new File("test/layoutengine/testcase2checks.xsl"));
+ testcase2checks = tfactory.newTemplates(src);
+ }
+ return testcase2checks;
+ }
+
+ public FopFactory getFopFactory(boolean base14KerningEnabled) {
+ FopFactory effFactory = (base14KerningEnabled ? fopFactoryWithBase14Kerning : fopFactory);
+ return effFactory;
+ }
+
+ public FopFactory getFopFactory(Document testDoc) {
+ boolean base14KerningEnabled = isBase14KerningEnabled(testDoc);
+ FopFactory effFactory = getFopFactory(base14KerningEnabled);
+
+ boolean strictValidation = isStrictValidation(testDoc);
+ effFactory.setStrictValidation(strictValidation);
+
+ return effFactory;
+ }
+
+ private boolean isBase14KerningEnabled(Document testDoc) {
+ try {
+ XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/base14kerning");
+ String s = xo.str();
+ return ("true".equalsIgnoreCase(s));
+ } catch (TransformerException e) {
+ throw new RuntimeException("Error while evaluating XPath expression", e);
+ }
+ }
+
+ private boolean isStrictValidation(Document testDoc) {
+ try {
+ XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/strict-validation");
+ return !("false".equalsIgnoreCase(xo.str()));
+ } catch (TransformerException e) {
+ throw new RuntimeException("Error while evaluating XPath expression", e);
+ }
+ }
+
+ /**
+ * Loads a test case into a DOM document.
+ * @param testFile the test file
+ * @return the loaded test case
+ * @throws IOException if an I/O error occurs loading the test case
+ */
+ public Document loadTestCase(File testFile)
+ throws IOException {
+ try {
+ DocumentBuilder builder = domBuilderFactory.newDocumentBuilder();
+ Document testDoc = builder.parse(testFile);
+ return testDoc;
+ } catch (Exception e) {
+ throw new IOException("Error while loading test case: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Serialize the DOM for later inspection.
+ * @param doc the DOM document
+ * @param target target file
+ * @throws TransformerException if a problem occurs during serialization
+ */
+ public void saveDOM(Document doc, File target) throws TransformerException {
+ Transformer transformer = getTransformerFactory().newTransformer();
+ Source src = new DOMSource(doc);
+ Result res = new StreamResult(target);
+ transformer.transform(src, res);
+ }
+
+ /**
+ * Returns the SAXTransformerFactory.
+ * @return the SAXTransformerFactory
+ */
+ public SAXTransformerFactory getTransformerFactory() {
+ return tfactory;
+ }
+}
diff --git a/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java b/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java
index b2bfdc99a..97546b1c3 100644
--- a/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java
+++ b/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java
@@ -28,29 +28,62 @@ import org.apache.fop.events.model.EventSeverity;
public class ConsoleEventListenerForTests implements EventListener {
private String name;
+ private EventSeverity logLevel;
+ /**
+ * Creates a new event listener with console output on severity INFO. This object will
+ * write out the name of the test before the first log message.
+ * @param name the name of the test
+ */
public ConsoleEventListenerForTests(String name) {
+ this(name, EventSeverity.INFO);
+ }
+
+ /**
+ * Creates a new event listener with console output. This object will
+ * write out the name of the test before the first log message.
+ * @param name the name of the test
+ * @param logLevel the logging level
+ */
+ public ConsoleEventListenerForTests(String name, EventSeverity logLevel) {
this.name = name;
+ this.logLevel = logLevel;
}
/** {@inheritDoc} */
public void processEvent(Event event) {
+ EventSeverity severity = event.getSeverity();
+ if (severity == EventSeverity.FATAL) {
+ log("FATAL", event);
+ return;
+ }
+ if (logLevel == EventSeverity.FATAL) {
+ return;
+ }
+ if (severity == EventSeverity.ERROR) {
+ log("ERROR", event);
+ return;
+ }
+ if (logLevel == EventSeverity.ERROR) {
+ return;
+ }
+ if (severity == EventSeverity.WARN) {
+ log("WARN ", event);
+ }
+ if (logLevel == EventSeverity.WARN) {
+ return;
+ }
+ if (severity == EventSeverity.INFO) {
+ log("INFO ", event);
+ }
+ }
+
+ private void log(String levelString, Event event) {
if (this.name != null) {
System.out.println("Test: " + this.name);
this.name = null;
}
String msg = EventFormatter.format(event);
- EventSeverity severity = event.getSeverity();
- if (severity == EventSeverity.INFO) {
- System.out.println(" [INFO ] " + msg);
- } else if (severity == EventSeverity.WARN) {
- System.out.println(" [WARN ] " + msg);
- } else if (severity == EventSeverity.ERROR) {
- System.out.println(" [ERROR] " + msg);
- } else if (severity == EventSeverity.FATAL) {
- System.out.println(" [FATAL] " + msg);
- } else {
- assert false;
- }
+ System.out.println(" [" + levelString + "] " + msg);
}
} \ No newline at end of file
diff --git a/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml b/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml
index 8ce6101a3..c36275df4 100644
--- a/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml
+++ b/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml
@@ -23,6 +23,9 @@
length evaluation using percentages is possible.
</p>
</info>
+ <cfg>
+ <strict-validation>false</strict-validation>
+ </cfg>
<fo>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
<fo:layout-master-set>
@@ -119,8 +122,8 @@
<eval expected="240000" xpath="//regionBody/@bpda"/>
<eval expected="240000" xpath="//regionBody/@ipda"/>
- <eval expected="220000" xpath="//regionBody/@bpda"/>
- <eval expected="220000" xpath="//regionBody/@ipda"/>
+ <eval expected="220000" xpath="//regionBody/@bpd"/>
+ <eval expected="220000" xpath="//regionBody/@ipd"/>
<eval expected="(solid,#808066,1000)" xpath="//regionBody/@border-before"/>
<eval expected="(solid,#808066,3000)" xpath="//regionBody/@border-after"/>
<eval expected="(solid,#808066,4000)" xpath="//regionBody/@border-start"/>