xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r739386 - in /xmlgraphics/fop/branches/Temp_AreaTreeNewDesign: ./ src/java/org/apache/fop/area/ test/java/org/apache/fop/intermediate/ test/java/org/apache/fop/layoutengine/ test/java/org/apache/fop/util/ test/layoutengine/standard-testcases/
Date Fri, 30 Jan 2009 19:29:00 GMT
Author: jeremias
Date: Fri Jan 30 19:28:59 2009
New Revision: 739386

URL: http://svn.apache.org/viewvc?rev=739386&view=rev
Log:
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.

Added:
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/TestEnvironment.java
  (with props)
Modified:
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/build.xml
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/AreaTreeParser.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/Page.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/RegionReference.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java
    xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/build.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/build.xml?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/build.xml (original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/build.xml Fri Jan 30 19:28:59 2009
@@ -593,11 +593,7 @@
       <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"/>

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/AreaTreeParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/AreaTreeParser.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/AreaTreeParser.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/AreaTreeParser.java
Fri Jan 30 19:28:59 2009
@@ -498,6 +498,7 @@
                 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 @@
             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 @@
             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;) {

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/Page.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/Page.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/Page.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/Page.java
Fri Jan 30 19:28:59 2009
@@ -128,8 +128,10 @@
             }
             // 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 @@
         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());
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/RegionReference.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/RegionReference.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/RegionReference.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/area/RegionReference.java
Fri Jan 30 19:28:59 2009
@@ -73,18 +73,6 @@
         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

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
Fri Jan 30 19:28:59 2009
@@ -27,17 +27,11 @@
 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.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 @@
  */
 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 @@
     /** 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 @@
     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 @@
 
     /** {@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 @@
 
     /**
      * 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 @@
         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 @@
         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 @@
             out = new FileOutputStream(tgtFile);
             out = new BufferedOutputStream(out);
         } else {
-            out = new ByteArrayOutputStream();
+            out = new NullOutputStream();
         }
         try {
             Source src = new DOMSource(intermediate);

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
Fri Jan 30 19:28:59 2009
@@ -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.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.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 @@
     /**
      * 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 @@
     }
 
     /** {@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 @@
 
         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 @@
         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();

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AreaTreeXMLFormatTestSuite.java
Fri Jan 30 19:28:59 2009
@@ -53,7 +53,7 @@
     }
 
     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 {

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
Fri Jan 30 19:28:59 2009
@@ -46,6 +46,7 @@
 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 @@
  */
 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 @@
     /**
      * 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 @@
     }
 
     /** {@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 @@
 
         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();
     }

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IntermediateFormatTestSuite.java
Fri Jan 30 19:28:59 2009
@@ -53,7 +53,7 @@
     }
 
     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 {

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
Fri Jan 30 19:28:59 2009
@@ -26,21 +26,14 @@
 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.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 @@
 
     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 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 @@
         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 @@
 
         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 @@
      * @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 @@
         }
     }
 
-    /**
-     * 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);
-    }
 }

Added: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/TestEnvironment.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/TestEnvironment.java?rev=739386&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/TestEnvironment.java
(added)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/TestEnvironment.java
Fri Jan 30 19:28:59 2009
@@ -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;
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/TestEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/layoutengine/TestEnvironment.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/util/ConsoleEventListenerForTests.java
Fri Jan 30 19:28:59 2009
@@ -28,29 +28,62 @@
 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

Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml?rev=739386&r1=739385&r2=739386&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml
(original)
+++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/simple-page-master_borders_padding.xml
Fri Jan 30 19:28:59 2009
@@ -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"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message