You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/01/06 09:39:19 UTC
cvs commit: xml-fop/test/java/org/apache/fop/layoutengine EvalCheck.java LayoutEngineTester.java
jeremias 2005/01/06 00:39:19
Modified: test/java/org/apache/fop/layoutengine
LayoutEngineTester.java
Added: test/java/org/apache/fop/layoutengine EvalCheck.java
Log:
Adding new eval check for simpler checks and more informative error messages.
Revision Changes Path
1.2 +2 -1 xml-fop/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
Index: LayoutEngineTester.java
===================================================================
RCS file: /home/cvs/xml-fop/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LayoutEngineTester.java 5 Jan 2005 21:11:34 -0000 1.1
+++ LayoutEngineTester.java 6 Jan 2005 08:39:19 -0000 1.2
@@ -65,6 +65,7 @@
static {
CHECK_CLASSES.put("true", TrueCheck.class);
+ CHECK_CLASSES.put("eval", EvalCheck.class);
}
/**
1.1 xml-fop/test/java/org/apache/fop/layoutengine/EvalCheck.java
Index: EvalCheck.java
===================================================================
/*
* Copyright 2005 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: EvalCheck.java,v 1.1 2005/01/06 08:39:19 jeremias Exp $ */
package org.apache.fop.layoutengine;
import javax.xml.transform.TransformerException;
import org.apache.xpath.XPathAPI;
import org.apache.xpath.objects.XBoolean;
import org.apache.xpath.objects.XObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
/**
* Simple check that requires an XPath expression to evaluate to true.
*/
public class EvalCheck implements LayoutEngineCheck {
private String expected;
private String xpath;
/**
* Creates a new instance
* @param expected expected value
* @param xpath XPath statement that needs to be evaluated
*/
public EvalCheck(String expected, String xpath) {
this.expected = expected;
this.xpath = xpath;
}
/**
* Creates a new instance from a DOM node.
* @param node DOM node that defines this check
*/
public EvalCheck(Node node) {
this.expected = node.getAttributes().getNamedItem("expected").getNodeValue();
this.xpath = node.getAttributes().getNamedItem("xpath").getNodeValue();
}
/**
* @see org.apache.fop.layoutengine.LayoutEngineCheck#check(org.w3c.dom.Document)
*/
public void check(Document doc) {
XObject res;
try {
res = XPathAPI.eval(doc, xpath);
} catch (TransformerException e) {
throw new RuntimeException("XPath evaluation failed: " + e.getMessage());
}
if (!expected.equals(res.str())) {
throw new RuntimeException(
"Expected XPath expression to evaluate to '" + expected + "', but got '"
+ res + "' (" + this + ")");
}
}
/** @see java.lang.Object#toString() */
public String toString() {
return "XPath: " + xpath;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org