/*
- * 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.
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;
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);
}
/**
ElementListCollector elCollector = new ElementListCollector();
ElementListObserver.addObserver(elCollector);
+
+ Fop fop;
+
try {
//Setup Transformer to convert the testcase XML to XSL-FO
Transformer transformer = getTestcase2FOStylesheet().newTransformer();
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);
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);
}
/*
- * 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.
package org.apache.fop.layoutengine;
+import org.apache.fop.apps.FormattingResults;
import org.w3c.dom.Document;
/**
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 */
public ElementListCollector getElementListCollector() {
return this.elCollector;
}
+
+ /**
+ * @return Returns the results.
+ */
+ public FormattingResults getResults() {
+ return results;
+ }
}
--- /dev/null
+/*
+ * 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;
+ }
+
+}