aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorarved <arved@unknown>2001-05-10 01:44:04 +0000
committerarved <arved@unknown>2001-05-10 01:44:04 +0000
commit96ef52e8580b3fc5f670b577445e75de020a9fdd (patch)
tree58e1dd4f2d942841120878658868cb8f811d5045 /src
parentb16c4cfa1dedd19d0c16e9cfdae8938a24ed8c03 (diff)
downloadxmlgraphics-fop-96ef52e8580b3fc5f670b577445e75de020a9fdd.tar.gz
xmlgraphics-fop-96ef52e8580b3fc5f670b577445e75de020a9fdd.zip
K. Liddle: testing support
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194237 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/org/apache/fop/tools/anttasks/RunTest.java146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/org/apache/fop/tools/anttasks/RunTest.java b/src/org/apache/fop/tools/anttasks/RunTest.java
new file mode 100644
index 000000000..e051b500f
--- /dev/null
+++ b/src/org/apache/fop/tools/anttasks/RunTest.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.tools.anttasks;
+
+// Ant
+import org.apache.tools.ant.*;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.net.URLClassLoader;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+import javax.xml.parsers.*;
+
+import org.w3c.dom.*;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ */
+public class RunTest extends Task {
+ String basedir;
+ String testsuite = "";
+ String referenceJar = "";
+ String refVersion = "";
+
+ public RunTest() {
+ }
+
+ public void setTestSuite(String str)
+ {
+ testsuite = str;
+ }
+
+ public void setBasedir(String str)
+ {
+ basedir = str;
+ }
+
+ public void setReference(String str) {
+ referenceJar = str;
+ }
+
+ public void setRefVersion(String str) {
+ refVersion = str;
+ }
+
+ /**
+ * Execute this ant task.
+ * This creates the reference output, if required, then tests
+ * the current build.
+ */
+ public void execute() throws BuildException {
+ runReference();
+ testNewBuild();
+ }
+
+ /**
+ * Test the current build.
+ * This uses the current jar file (in build/fop.jar) to run the
+ * tests with.
+ * The output is then compared with the reference output.
+ */
+ protected void testNewBuild() {
+ try {
+ ClassLoader loader = new URLClassLoader(new URL[] {new URL("file:build/fop.jar")});
+ runConverter(loader);
+ } catch(MalformedURLException mue) {
+ mue.printStackTrace();
+ }
+ }
+
+ /**
+ * Run the tests for the reference jar file.
+ * This checks that the reference output has not already been
+ * run and then checks the version of the reference jar against
+ * the version required.
+ * The reference output is then created.
+ */
+ protected void runReference() throws BuildException
+ {
+ // check not already done
+ File f = new File(basedir + "reference/output/");
+ if(f.exists()) {
+ return;
+ } else {
+ try {
+ ClassLoader loader = new URLClassLoader(new URL[] {new URL("file:" + basedir + referenceJar)});
+
+ try {
+ Class cla = Class.forName("org.apache.fop.apps.Options", true, loader);
+ Object opts = cla.newInstance();
+ cla = Class.forName("org.apache.fop.apps.Version", true, loader);
+ Method get = cla.getMethod("getVersion", new Class[] {});
+ if(!get.invoke(null, new Object[] {}).equals(refVersion)) {
+ throw new BuildException("Reference jar is not correct version");
+ }
+ } catch(IllegalAccessException iae) {
+ } catch(IllegalArgumentException are) {
+ } catch(InvocationTargetException are) {
+ } catch(ClassNotFoundException are) {
+ } catch(InstantiationException are) {
+ } catch(NoSuchMethodException are) {
+ }
+
+ runConverter(loader);
+ } catch(MalformedURLException mue) {
+ mue.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Run the Converter.
+ * Runs the test converter using the specified class loader.
+ * This loads the TestConverter using the class loader and
+ * then runs the test suite for the current test suite
+ * file in the base directory.
+ * @param loader the class loader to use to run the tests with
+ */
+ protected void runConverter(ClassLoader loader)
+ {
+ String converter = "org.apache.fop.tools.TestConverter";
+
+ try {
+ Class cla = Class.forName(converter, true, loader);
+ Object tc = cla.newInstance();
+ Method meth;
+
+ meth = cla.getMethod("setBaseDir", new Class[] {String.class});
+ meth.invoke(tc, new Object[] {basedir});
+
+ meth = cla.getMethod("runTests", new Class[] {String.class});
+ meth.invoke(tc, new Object[] {testsuite});
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}