aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/fotreetest
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-08-30 06:09:14 +0000
committerJeremias Maerki <jeremias@apache.org>2005-08-30 06:09:14 +0000
commit7f2ced44148111cc0dc2d8609b14dc30c3da7b49 (patch)
treea47b0060513388b8a720afca47cffcd104cb7854 /test/java/org/apache/fop/fotreetest
parent8ff5b13709a136cb342b3271c8d71b0c8dc31f90 (diff)
downloadxmlgraphics-fop-7f2ced44148111cc0dc2d8609b14dc30c3da7b49.tar.gz
xmlgraphics-fop-7f2ced44148111cc0dc2d8609b14dc30c3da7b49.zip
Initial commit for a FO tree testing facility.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@264709 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop/fotreetest')
-rw-r--r--test/java/org/apache/fop/fotreetest/DummyFOEventHandler.java37
-rw-r--r--test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java123
-rw-r--r--test/java/org/apache/fop/fotreetest/FOTreeTester.java73
-rw-r--r--test/java/org/apache/fop/fotreetest/ResultCollector.java64
-rw-r--r--test/java/org/apache/fop/fotreetest/ext/AssertElement.java72
-rw-r--r--test/java/org/apache/fop/fotreetest/ext/TestElementMapping.java60
-rw-r--r--test/java/org/apache/fop/fotreetest/ext/TestObj.java44
7 files changed, 473 insertions, 0 deletions
diff --git a/test/java/org/apache/fop/fotreetest/DummyFOEventHandler.java b/test/java/org/apache/fop/fotreetest/DummyFOEventHandler.java
new file mode 100644
index 000000000..d6e97dbdc
--- /dev/null
+++ b/test/java/org/apache/fop/fotreetest/DummyFOEventHandler.java
@@ -0,0 +1,37 @@
+/*
+ * 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$ */
+
+package org.apache.fop.fotreetest;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.FOEventHandler;
+
+/**
+ * Dummy FOEventHandler implementation that does nothing.
+ */
+public class DummyFOEventHandler extends FOEventHandler {
+
+ /**
+ * Main constructor.
+ * @param foUserAgent the user agent
+ */
+ public DummyFOEventHandler(FOUserAgent foUserAgent) {
+ super(foUserAgent);
+ }
+
+}
diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
new file mode 100644
index 000000000..26f89949f
--- /dev/null
+++ b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
@@ -0,0 +1,123 @@
+/*
+ * 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$ */
+
+package org.apache.fop.fotreetest;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.AndFileFilter;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NameFileFilter;
+import org.apache.commons.io.filefilter.PrefixFileFilter;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.fop.DebugHelper;
+import org.apache.fop.layoutengine.LayoutEngineTestSuite;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * JUnit test suit for running layout engine test under JUnit control.
+ */
+public final class FOTreeTestSuite {
+
+ static {
+ DebugHelper.registerStandardElementListObservers();
+ }
+
+ private FOTreeTestSuite() {
+ //don't instantiate!
+ }
+
+ /**
+ * @return the test suite with all the tests (one for each XML file)
+ * @throws IOException in case of an I/O problem
+ */
+ public static Test suite() throws IOException {
+ TestSuite suite = new TestSuite();
+
+ File mainDir = new File("test/fotree");
+
+ final FOTreeTester tester = new FOTreeTester();
+
+ IOFileFilter filter;
+ String single = System.getProperty("fop.fotree.single");
+ String startsWith = System.getProperty("fop.fotree.starts-with");
+ if (single != null) {
+ filter = new NameFileFilter(single);
+ } else if (startsWith != null) {
+ filter = new PrefixFileFilter(startsWith);
+ filter = new AndFileFilter(filter, new SuffixFileFilter(".fo"));
+ } else {
+ filter = new SuffixFileFilter(".fo");
+ filter = LayoutEngineTestSuite.decorateWithDisabledList(filter);
+ }
+ Collection files = FileUtils.listFiles(new File(mainDir, "testcases"),
+ filter, TrueFileFilter.INSTANCE);
+ String privateTests = System.getProperty("fop.fotree.private");
+ if ("true".equalsIgnoreCase(privateTests)) {
+ Collection privateFiles = FileUtils.listFiles(
+ new File(mainDir, "private-testcases"),
+ filter, TrueFileFilter.INSTANCE);
+ files.addAll(privateFiles);
+ }
+ Iterator i = files.iterator();
+ while (i.hasNext()) {
+ File f = (File)i.next();
+ addTestCase(suite, tester, f);
+ }
+
+ return suite;
+ }
+
+ private static void addTestCase(TestSuite suite,
+ final FOTreeTester tester, final File f) {
+ suite.addTest(new FOTreeTestCase(f.getName()) {
+ public void runTest() throws Exception {
+ prepare(tester, f);
+ testMain();
+ }
+ });
+ }
+
+ private static class FOTreeTestCase extends TestCase {
+
+ private FOTreeTester tester;
+ private File testFile;
+
+ public FOTreeTestCase(String name) {
+ super(name);
+ }
+
+ public void prepare(FOTreeTester tester, File testFile) {
+ //super(testFile.getName());
+ this.tester = tester;
+ this.testFile = testFile;
+ }
+
+ public void testMain() throws Exception {
+ tester.runTest(testFile);
+ }
+ }
+}
diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTester.java b/test/java/org/apache/fop/fotreetest/FOTreeTester.java
new file mode 100644
index 000000000..41931103c
--- /dev/null
+++ b/test/java/org/apache/fop/fotreetest/FOTreeTester.java
@@ -0,0 +1,73 @@
+/*
+ * 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$ */
+
+package org.apache.fop.fotreetest;
+
+import java.io.File;
+import java.util.List;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.fo.Constants;
+
+/**
+ * Test driver class for FO tree tests.
+ */
+public class FOTreeTester {
+
+ private SAXTransformerFactory tfactory
+ = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
+
+ /**
+ * Runs a test.
+ * @param testFile the test file.
+ * @throws Exception if a test or FOP itself fails
+ */
+ public void runTest(File testFile) throws Exception {
+ ResultCollector collector = ResultCollector.getInstance();
+ collector.reset();
+
+ //Setup identity Transformer
+ Transformer transformer = tfactory.newTransformer();
+ Source src = new StreamSource(testFile);
+
+ //Setup FOP for area tree rendering
+ FOUserAgent ua = new FOUserAgent();
+ ua.setBaseURL(testFile.getParentFile().toURL().toString());
+ ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua));
+ Fop fop = new Fop(Constants.RENDER_XML, ua);
+
+ SAXResult fores = new SAXResult(fop.getDefaultHandler());
+ transformer.transform(src, fores);
+
+ List results = collector.getResults();
+ if (results.size() > 0) {
+ for (int i = 0; i < results.size(); i++) {
+ System.out.println(((Exception)results.get(i)).getMessage());
+ }
+ throw (Exception)results.get(0);
+ }
+ }
+
+}
diff --git a/test/java/org/apache/fop/fotreetest/ResultCollector.java b/test/java/org/apache/fop/fotreetest/ResultCollector.java
new file mode 100644
index 000000000..9c85ec980
--- /dev/null
+++ b/test/java/org/apache/fop/fotreetest/ResultCollector.java
@@ -0,0 +1,64 @@
+/*
+ * 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$ */
+
+package org.apache.fop.fotreetest;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * This class collects the results from assertions injected into the FO stream.
+ */
+public class ResultCollector {
+
+ private static ResultCollector instance = null;
+
+ private List results = new java.util.ArrayList();
+
+ /** @return the ResultColletor singleton */
+ public static ResultCollector getInstance() {
+ if (instance == null) {
+ instance = new ResultCollector();
+ }
+ return instance;
+ }
+
+ /** Main constructor. */
+ public ResultCollector() {
+ //nop
+ }
+
+ /**
+ * This notifies the ResultCollector about an Exception.
+ * @param e the exception
+ */
+ public void notifyException(Exception e) {
+ System.out.println(e.getMessage());
+ results.add(e);
+ }
+
+ /** Resets the result list. */
+ public void reset() {
+ results.clear();
+ }
+
+ /** @return the list of results */
+ public List getResults() {
+ return Collections.unmodifiableList(results);
+ }
+}
diff --git a/test/java/org/apache/fop/fotreetest/ext/AssertElement.java b/test/java/org/apache/fop/fotreetest/ext/AssertElement.java
new file mode 100644
index 000000000..1697b8979
--- /dev/null
+++ b/test/java/org/apache/fop/fotreetest/ext/AssertElement.java
@@ -0,0 +1,72 @@
+/*
+ * 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$ */
+
+package org.apache.fop.fotreetest.ext;
+
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.FOPropertyMapping;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.properties.Property;
+import org.apache.fop.fotreetest.ResultCollector;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+
+/**
+ * Defines the assert element for the FOP Test extension.
+ */
+public class AssertElement extends TestObj {
+
+ /**
+ * @see org.apache.fop.fo.FONode#FONode(FONode)
+ */
+ public AssertElement(FONode parent) {
+ super(parent);
+ }
+
+ /**
+ * @see org.apache.fop.fo.FONode#processNode
+ */
+ public void processNode(String elementName,
+ Locator locator,
+ Attributes attlist,
+ PropertyList propertyList) throws FOPException {
+ super.processNode(elementName, locator, attlist, propertyList);
+
+ ResultCollector collector = ResultCollector.getInstance();
+ String propName = attlist.getValue("property");
+ int propID = FOPropertyMapping.getPropertyId(propName);
+ if (propID < 0) {
+ collector.notifyException(new IllegalArgumentException(
+ "Property not found: " + propName));
+ } else {
+ Property prop = propertyList.get(propID);
+ String s = String.valueOf(prop);
+ String expected = attlist.getValue("expected");
+ if (!expected.equals(s)) {
+ collector.notifyException(new IllegalStateException("Property '" + propName
+ + "' expected to evaluate to '" + expected + "' but got: " + s));
+ }
+ }
+
+ }
+
+}
+
diff --git a/test/java/org/apache/fop/fotreetest/ext/TestElementMapping.java b/test/java/org/apache/fop/fotreetest/ext/TestElementMapping.java
new file mode 100644
index 000000000..903250155
--- /dev/null
+++ b/test/java/org/apache/fop/fotreetest/ext/TestElementMapping.java
@@ -0,0 +1,60 @@
+/*
+ * 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$ */
+
+package org.apache.fop.fotreetest.ext;
+
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.ElementMapping;
+
+/**
+ * This class provides the element mapping for FOP.
+ */
+public class TestElementMapping extends ElementMapping {
+
+ /** MathML Namespace */
+ public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/test";
+
+ /**
+ * Main constructor
+ */
+ public TestElementMapping() {
+ this.namespaceURI = NAMESPACE;
+ }
+
+ /** @see org.apache.fop.fo.ElementMapping#initialize() */
+ protected void initialize() {
+ if (foObjs == null) {
+ foObjs = new java.util.HashMap();
+ foObjs.put("assert", new AssertMaker());
+ foObjs.put(DEFAULT, new TestMaker());
+ }
+ }
+
+ static class TestMaker extends ElementMapping.Maker {
+ public FONode make(FONode parent) {
+ return new TestObj(parent);
+ }
+ }
+
+ static class AssertMaker extends ElementMapping.Maker {
+ public FONode make(FONode parent) {
+ return new AssertElement(parent);
+ }
+ }
+
+}
diff --git a/test/java/org/apache/fop/fotreetest/ext/TestObj.java b/test/java/org/apache/fop/fotreetest/ext/TestObj.java
new file mode 100644
index 000000000..245f81b5d
--- /dev/null
+++ b/test/java/org/apache/fop/fotreetest/ext/TestObj.java
@@ -0,0 +1,44 @@
+/*
+ * 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$ */
+
+package org.apache.fop.fotreetest.ext;
+
+// FOP
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.FObj;
+
+/**
+ * Catch all FOP Test objects as default element.
+ */
+public class TestObj extends FObj {
+
+ /**
+ * @see org.apache.fop.fo.FONode#FONode(FONode)
+ */
+ public TestObj(FONode parent) {
+ super(parent);
+ }
+
+ /**
+ * @see org.apache.fop.fo.XMLObj#getNameSpace()
+ */
+ public String getNameSpace() {
+ return TestElementMapping.NAMESPACE;
+ }
+}
+