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 2006/06/08 14:36:24 UTC

svn commit: r412732 - in /xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine: EvalCheck.java TrueCheck.java

Author: jeremias
Date: Thu Jun  8 05:36:23 2006
New Revision: 412732

URL: http://svn.apache.org/viewvc?rev=412732&view=rev
Log:
Set a PrefixResolver for the "true" check, too, not only for "eval".
Added optional "tolerance" value for number comparisons using the "eval" check. Simplifies certain checks.

Modified:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/TrueCheck.java

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java?rev=412732&r1=412731&r2=412732&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/EvalCheck.java Thu Jun  8 05:36:23 2006
@@ -33,6 +33,7 @@
 
     private String expected;
     private String xpath;
+    private double tolerance;
     private PrefixResolver prefixResolver;
     
     /**
@@ -52,6 +53,10 @@
     public EvalCheck(Node node) {
         this.expected = node.getAttributes().getNamedItem("expected").getNodeValue();
         this.xpath = node.getAttributes().getNamedItem("xpath").getNodeValue();
+        Node nd = node.getAttributes().getNamedItem("tolerance");
+        if (nd != null) {
+            this.tolerance = Double.parseDouble(nd.getNodeValue());
+        }
         this.prefixResolver = new PrefixResolverDefault(node);
     }
     
@@ -64,12 +69,21 @@
             throw new RuntimeException("XPath evaluation failed: " + e.getMessage());
         }
         String actual = res.str(); //Second str() seems to fail. D'oh!
-        if (!expected.equals(actual)) {
-            throw new RuntimeException(
-                    "Expected XPath expression to evaluate to '" + expected + "', but got '" 
-                    + actual + "' (" + this + ")");
+        if (tolerance != 0) {
+            double v1 = Double.parseDouble(expected);
+            double v2 = Double.parseDouble(actual);
+            if (Math.abs(v1 - v2) > tolerance) {
+                throw new RuntimeException(
+                        "Expected XPath expression to evaluate to '" + expected + "', but got '" 
+                        + actual + "' (" + this + ", outside tolerance)");
+            }
+        } else {
+            if (!expected.equals(actual)) {
+                throw new RuntimeException(
+                        "Expected XPath expression to evaluate to '" + expected + "', but got '" 
+                        + actual + "' (" + this + ")");
+            }
         }
-
     }
 
     /** @see java.lang.Object#toString() */
@@ -77,12 +91,4 @@
         return "XPath: " + xpath;
     }
 
-    private class MyPrefixResolver extends PrefixResolverDefault {
-        
-        public MyPrefixResolver(Node xpathExpressionContext) {
-            super(xpathExpressionContext);
-        }
-        
-    }
-    
 }

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/TrueCheck.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/TrueCheck.java?rev=412732&r1=412731&r2=412732&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/TrueCheck.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/TrueCheck.java Thu Jun  8 05:36:23 2006
@@ -20,6 +20,8 @@
 
 import javax.xml.transform.TransformerException;
 
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xml.utils.PrefixResolverDefault;
 import org.apache.xpath.XPathAPI;
 import org.apache.xpath.objects.XBoolean;
 import org.apache.xpath.objects.XObject;
@@ -32,6 +34,7 @@
 
     private String xpath;
     private String failureMessage;
+    private PrefixResolver prefixResolver;
     
     /**
      * Creates a new instance
@@ -51,13 +54,14 @@
         if (nd != null) {
             this.failureMessage = nd.getNodeValue();
         }
+        this.prefixResolver = new PrefixResolverDefault(node);
     }
     
     /** @see org.apache.fop.layoutengine.LayoutEngineCheck */
     public void check(LayoutResult result) {
         XObject res;
         try {
-            res = XPathAPI.eval(result.getAreaTree(), xpath);
+            res = XPathAPI.eval(result.getAreaTree(), xpath, prefixResolver);
         } catch (TransformerException e) {
             throw new RuntimeException("XPath evaluation failed: " + e.getMessage());
         }



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