From 4e0c1bd3e142d5f772ebc516e6f7229fc4900b26 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Sun, 8 Jan 2006 11:45:37 +0000 Subject: [PATCH] Create a new check type for the formatting results. For now only checking the pagecount property is implemented. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@367019 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/layoutengine/LayoutEngineTester.java | 12 ++- .../apache/fop/layoutengine/LayoutResult.java | 16 +++- .../apache/fop/layoutengine/ResultCheck.java | 75 +++++++++++++++++++ 3 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 test/java/org/apache/fop/layoutengine/ResultCheck.java diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java index 9fd105ab7..76e77442c 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation. + * Copyright 2005-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FormattingResults; import org.apache.fop.apps.MimeConstants; import org.apache.fop.layoutmgr.ElementListObserver; import org.apache.fop.render.xml.XMLRenderer; @@ -70,6 +71,7 @@ public class LayoutEngineTester { CHECK_CLASSES.put("true", TrueCheck.class); CHECK_CLASSES.put("eval", EvalCheck.class); CHECK_CLASSES.put("element-list", ElementListCheck.class); + CHECK_CLASSES.put("result", ResultCheck.class); } /** @@ -113,6 +115,9 @@ public class LayoutEngineTester { ElementListCollector elCollector = new ElementListCollector(); ElementListObserver.addObserver(elCollector); + + Fop fop; + try { //Setup Transformer to convert the testcase XML to XSL-FO Transformer transformer = getTestcase2FOStylesheet().newTransformer(); @@ -129,7 +134,7 @@ public class LayoutEngineTester { atrenderer.setUserAgent(ua); atrenderer.setTransformerHandler(athandler); ua.setRendererOverride(atrenderer); - Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua); + fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua); SAXResult fores = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, fores); @@ -141,7 +146,8 @@ public class LayoutEngineTester { if (this.areaTreeBackupDir != null) { saveAreaTreeXML(doc, new File(this.areaTreeBackupDir, testFile.getName() + ".at.xml")); } - LayoutResult result = new LayoutResult(doc, elCollector); + FormattingResults results = fop.getResults(); + LayoutResult result = new LayoutResult(doc, elCollector, results); checkAll(testFile, result); } diff --git a/test/java/org/apache/fop/layoutengine/LayoutResult.java b/test/java/org/apache/fop/layoutengine/LayoutResult.java index b85ecda1b..e58bbb9a0 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutResult.java +++ b/test/java/org/apache/fop/layoutengine/LayoutResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation. + * Copyright 2005-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.apache.fop.layoutengine; +import org.apache.fop.apps.FormattingResults; import org.w3c.dom.Document; /** @@ -27,15 +28,19 @@ public class LayoutResult { private Document areaTree; private ElementListCollector elCollector; + private FormattingResults results; /** * Creates a new LayoutResult instance. * @param areaTree the area tree DOM * @param elCollector the element list collector + * @param results the formatting results */ - public LayoutResult(Document areaTree, ElementListCollector elCollector) { + public LayoutResult(Document areaTree, ElementListCollector elCollector, + FormattingResults results) { this.areaTree = areaTree; this.elCollector = elCollector; + this.results = results; } /** @return the generated area tree as DOM tree */ @@ -47,5 +52,12 @@ public class LayoutResult { public ElementListCollector getElementListCollector() { return this.elCollector; } + + /** + * @return Returns the results. + */ + public FormattingResults getResults() { + return results; + } } diff --git a/test/java/org/apache/fop/layoutengine/ResultCheck.java b/test/java/org/apache/fop/layoutengine/ResultCheck.java new file mode 100644 index 000000000..f2d7a52fe --- /dev/null +++ b/test/java/org/apache/fop/layoutengine/ResultCheck.java @@ -0,0 +1,75 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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 org.apache.fop.apps.FormattingResults; +import org.w3c.dom.Node; + +/** + * Simple check that requires a result property to evaluate to the expected value + */ +public class ResultCheck implements LayoutEngineCheck { + + private String expected; + private String property; + + /** + * Creates a new instance + * @param expected expected value + * @param property property of which the value needs to be evaluated + */ + public ResultCheck(String expected, String property) { + this.expected = expected; + this.property = property; + } + + /** + * Creates a new instance from a DOM node. + * @param node DOM node that defines this check + */ + public ResultCheck(Node node) { + this.expected = node.getAttributes().getNamedItem("expected").getNodeValue(); + this.property = node.getAttributes().getNamedItem("property").getNodeValue(); + } + + /* (non-Javadoc) + * @see LayoutEngineCheck#check(LayoutResult) + */ + public void check(LayoutResult result) { + FormattingResults results = result.getResults(); + String actual; + if (property.equals("pagecount")) { + actual = Integer.toString(results.getPageCount()); + } else { + throw new RuntimeException("No such property test: " + property); + } + if (!expected.equals(actual)) { + throw new RuntimeException( + "Expected property to evaluate to '" + expected + "', but got '" + + actual + "' (" + this + ")"); + } + + } + + /** @see java.lang.Object#toString() */ + public String toString() { + return "Property: " + property; + } + +} -- 2.39.5