aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/layoutengine
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2011-10-04 10:09:01 +0000
committerVincent Hennebert <vhennebert@apache.org>2011-10-04 10:09:01 +0000
commit91c66d97428aa57c844ec58e1deb07a8ab745574 (patch)
treed6062f718053ad636c8f587d5d5f199e9d158252 /test/java/org/apache/fop/layoutengine
parent7d33c81a0a079336dd1ffcac97e4ee1dfba16c36 (diff)
downloadxmlgraphics-fop-91c66d97428aa57c844ec58e1deb07a8ab745574.tar.gz
xmlgraphics-fop-91c66d97428aa57c844ec58e1deb07a8ab745574.zip
Bugzilla #51928: Upgraded all tests to JUnit 4
Patch by Mehdi Houshmand, applied with minor cosmetics and error fixes git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1178747 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop/layoutengine')
-rw-r--r--test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java194
-rw-r--r--test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java165
-rw-r--r--test/java/org/apache/fop/layoutengine/LayoutEngineTester.java57
-rw-r--r--test/java/org/apache/fop/layoutengine/ResultCheck.java6
4 files changed, 216 insertions, 206 deletions
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java
index 397374657..00a660999 100644
--- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java
@@ -19,196 +19,14 @@
package org.apache.fop.layoutengine;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.stream.StreamSource;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-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.NotFileFilter;
-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.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
/**
* JUnit test suit for running layout engine test under JUnit control.
*/
-public final class LayoutEngineTestSuite {
-
- static {
- DebugHelper.registerStandardElementListObservers();
- }
-
- private LayoutEngineTestSuite() {
- // This is a utility class
- }
-
- public static String[] readDisabledTestcases(File f) throws IOException {
- List lines = new java.util.ArrayList();
- Source stylesheet = new StreamSource(
- new File("test/layoutengine/disabled-testcase2filename.xsl"));
- Source source = new StreamSource(f);
- Result result = new SAXResult(new FilenameHandler(lines));
- try {
- Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesheet);
- transformer.transform(source, result);
- } catch (TransformerConfigurationException tce) {
- throw new RuntimeException(tce.getMessage());
- } catch (TransformerException te) {
- throw new RuntimeException(te.getMessage());
- }
- return (String[])lines.toArray(new String[lines.size()]);
- }
-
- private static class FilenameHandler extends DefaultHandler {
- private StringBuffer buffer = new StringBuffer(128);
- private boolean readingFilename = false;
- private List filenames;
-
- public FilenameHandler(List filenames) {
- this.filenames = filenames;
- }
-
- public void startElement(String namespaceURI, String localName, String qName,
- Attributes atts) throws SAXException {
- if (qName != null && qName.equals("file")) {
- buffer.setLength(0);
- readingFilename = true;
- } else {
- throw new RuntimeException(
- "Unexpected element while reading disabled testcase file names: " + qName);
- }
- }
-
- public void endElement(String namespaceURI, String localName, String qName)
- throws SAXException {
- if (qName != null && qName.equals("file")) {
- readingFilename = false;
- filenames.add(buffer.toString());
- } else {
- throw new RuntimeException(
- "Unexpected element while reading disabled testcase file names: " + qName);
- }
- }
-
- public void characters(char[] ch, int start, int length) throws SAXException {
- if (readingFilename) {
- buffer.append(ch, start, length);
- }
- }
- }
-
- public static IOFileFilter decorateWithDisabledList(IOFileFilter filter) throws IOException {
- String disabled = System.getProperty("fop.layoutengine.disabled");
- if (disabled != null && disabled.length() > 0) {
- filter = new AndFileFilter(new NotFileFilter(
- new NameFileFilter(readDisabledTestcases(new File(disabled)))),
- filter);
- }
- return filter;
- }
-
- /**
- * @return a Collection of File instances containing all the test cases set up for processing.
- * @throws IOException if there's a problem gathering the list of test files
- */
- public static Collection getTestFiles() throws IOException {
- File mainDir = new File("test/layoutengine");
- IOFileFilter filter;
- String single = System.getProperty("fop.layoutengine.single");
- String startsWith = System.getProperty("fop.layoutengine.starts-with");
- if (single != null) {
- filter = new NameFileFilter(single);
- } else if (startsWith != null) {
- filter = new PrefixFileFilter(startsWith);
- filter = new AndFileFilter(filter, new SuffixFileFilter(".xml"));
- filter = decorateWithDisabledList(filter);
- } else {
- filter = new SuffixFileFilter(".xml");
- filter = decorateWithDisabledList(filter);
- }
- String testset = System.getProperty("fop.layoutengine.testset");
- if (testset == null) {
- testset = "standard";
- }
- Collection files = FileUtils.listFiles(new File(mainDir, testset + "-testcases"),
- filter, TrueFileFilter.INSTANCE);
- String privateTests = System.getProperty("fop.layoutengine.private");
- if ("true".equalsIgnoreCase(privateTests)) {
- Collection privateFiles = FileUtils.listFiles(
- new File(mainDir, "private-testcases"),
- filter, TrueFileFilter.INSTANCE);
- files.addAll(privateFiles);
- }
- return files;
- }
-
- /**
- * @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 backupDir = new File("build/test-results/layoutengine");
- backupDir.mkdirs();
-
- Collection files = getTestFiles();
-
- final LayoutEngineTester tester = new LayoutEngineTester(backupDir);
- Iterator i = files.iterator();
- while (i.hasNext()) {
- File f = (File)i.next();
- suite.addTest(new LayoutEngineTestCase(f, tester));
- }
-
- return suite;
- }
-
- private static class LayoutEngineTestCase extends TestCase {
-
- private final File testFile;
-
- private final LayoutEngineTester tester;
-
- LayoutEngineTestCase(File testFile, LayoutEngineTester tester) {
- super(testFile.getName());
- this.testFile = testFile;
- this.tester = tester;
- }
-
- @Override
- protected void runTest() throws Throwable {
- try {
- tester.runTest(testFile);
- } catch (Exception e) {
- org.apache.commons.logging.LogFactory.getLog(
- this.getClass()).error("Error on " + getName());
- throw e;
- }
- }
- }
+@RunWith(Suite.class)
+@SuiteClasses({ LayoutEngineTester.class })
+public class LayoutEngineTestSuite {
}
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java
new file mode 100644
index 000000000..6beda1f30
--- /dev/null
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+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.NotFileFilter;
+import org.apache.commons.io.filefilter.PrefixFileFilter;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+
+/**
+ * Utility class for layout engine tests.
+ */
+public final class LayoutEngineTestUtils {
+
+ private LayoutEngineTestUtils() {
+ }
+
+ private static class FilenameHandler extends DefaultHandler {
+ private StringBuffer buffer = new StringBuffer(128);
+ private boolean readingFilename = false;
+ private List filenames;
+
+ public FilenameHandler(List filenames) {
+ this.filenames = filenames;
+ }
+
+ public void startElement(String namespaceURI, String localName, String qName,
+ Attributes atts) throws SAXException {
+ if (qName != null && qName.equals("file")) {
+ buffer.setLength(0);
+ readingFilename = true;
+ } else {
+ throw new RuntimeException(
+ "Unexpected element while reading disabled testcase file names: " + qName);
+ }
+ }
+
+ public void endElement(String namespaceURI, String localName, String qName)
+ throws SAXException {
+ if (qName != null && qName.equals("file")) {
+ readingFilename = false;
+ filenames.add(buffer.toString());
+ } else {
+ throw new RuntimeException(
+ "Unexpected element while reading disabled testcase file names: " + qName);
+ }
+ }
+
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ if (readingFilename) {
+ buffer.append(ch, start, length);
+ }
+ }
+ }
+
+ public static IOFileFilter decorateWithDisabledList(IOFileFilter filter) throws IOException {
+ String disabled = System.getProperty("fop.layoutengine.disabled");
+ if (disabled != null && disabled.length() > 0) {
+ filter = new AndFileFilter(new NotFileFilter(
+ new NameFileFilter(LayoutEngineTestUtils.readDisabledTestcases(new File(
+ disabled)))),
+ filter);
+ }
+ return filter;
+ }
+
+ public static String[] readDisabledTestcases(File f) throws IOException {
+ List lines = new java.util.ArrayList();
+ Source stylesheet = new StreamSource(
+ new File("test/layoutengine/disabled-testcase2filename.xsl"));
+ Source source = new StreamSource(f);
+ Result result = new SAXResult(new FilenameHandler(lines));
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesheet);
+ transformer.transform(source, result);
+ } catch (TransformerConfigurationException tce) {
+ throw new RuntimeException(tce.getMessage());
+ } catch (TransformerException te) {
+ throw new RuntimeException(te.getMessage());
+ }
+ return (String[]) lines.toArray(new String[lines.size()]);
+ }
+
+ /**
+ * @return a Collection of File instances containing all the test cases set up for processing.
+ * @throws IOException if there's a problem gathering the list of test files
+ */
+ public static Collection<File[]> getTestFiles() throws IOException {
+ File mainDir = new File("test/layoutengine");
+ IOFileFilter filter;
+ String single = System.getProperty("fop.layoutengine.single");
+ String startsWith = System.getProperty("fop.layoutengine.starts-with");
+ if (single != null) {
+ filter = new NameFileFilter(single);
+ } else if (startsWith != null) {
+ filter = new PrefixFileFilter(startsWith);
+ filter = new AndFileFilter(filter, new SuffixFileFilter(".xml"));
+ filter = decorateWithDisabledList(filter);
+ } else {
+ filter = new SuffixFileFilter(".xml");
+ filter = decorateWithDisabledList(filter);
+ }
+ String testset = System.getProperty("fop.layoutengine.testset");
+ if (testset == null) {
+ testset = "standard";
+ }
+ Collection<File> files = FileUtils.listFiles(new File(mainDir, testset + "-testcases"),
+ filter, TrueFileFilter.INSTANCE);
+ String privateTests = System.getProperty("fop.layoutengine.private");
+ if ("true".equalsIgnoreCase(privateTests)) {
+ Collection privateFiles = FileUtils.listFiles(
+ new File(mainDir, "private-testcases"),
+ filter, TrueFileFilter.INSTANCE);
+ files.addAll(privateFiles);
+ }
+
+ Collection<File[]> parametersForJUnit4 = new ArrayList<File[]>();
+ for (File f : files) {
+ parametersForJUnit4.add(new File[] { f });
+ }
+
+ return parametersForJUnit4;
+ }
+
+}
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
index 51c05a95f..867602cce 100644
--- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
@@ -21,6 +21,7 @@ package org.apache.fop.layoutengine;
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
@@ -33,12 +34,7 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.TransformerHandler;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
+import org.apache.fop.DebugHelper;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
@@ -57,41 +53,74 @@ import org.apache.fop.render.intermediate.IFSerializer;
import org.apache.fop.render.xml.XMLRenderer;
import org.apache.fop.util.ConsoleEventListenerForTests;
import org.apache.fop.util.DelegatingContentHandler;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
/**
* Class for testing the FOP's layout engine using testcases specified in XML
* files.
*/
+@RunWith(Parameterized.class)
public class LayoutEngineTester {
+ private static File areaTreeBackupDir;
+ /**
+ * Sets up the class, this is invoked only once.
+ */
+ @BeforeClass
+ public static void makeDirAndRegisterDebugHelper() {
+ DebugHelper.registerStandardElementListObservers();
+ areaTreeBackupDir = new File("build/test-results/layoutengine");
+ areaTreeBackupDir.mkdirs();
+ }
+
+ /**
+ * Creates the parameters for this test.
+ *
+ * @return the list of file arrays populated with test files
+ * @throws IOException if an I/O error occurs while reading the test file
+ */
+ @Parameters
+ public static Collection<File[]> getParameters() throws IOException {
+ return LayoutEngineTestUtils.getTestFiles();
+ }
private TestAssistant testAssistant = new TestAssistant();
private LayoutEngineChecksFactory layoutEngineChecksFactory = new LayoutEngineChecksFactory();
- private File areaTreeBackupDir;
+
private IFTester ifTester;
+ private File testFile;
private TransformerFactory tfactory = TransformerFactory.newInstance();
/**
* Constructs a new instance.
- * @param areaTreeBackupDir Optional directory that receives the generated
- * area tree XML files. May be null.
+ *
+ * @param testFile the test file
*/
- public LayoutEngineTester(File areaTreeBackupDir) {
- this.areaTreeBackupDir = areaTreeBackupDir;
+ public LayoutEngineTester(File testFile) {
this.ifTester = new IFTester(tfactory, areaTreeBackupDir);
+ this.testFile = testFile;
}
/**
* Runs a single layout engine test case.
- * @param testFile Test case to run
* @throws TransformerException In case of an XSLT/JAXP problem
* @throws IOException In case of an I/O problem
* @throws SAXException In case of a problem during SAX processing
* @throws ParserConfigurationException In case of a problem with the XML parser setup
*/
- public void runTest(File testFile)
- throws TransformerException, SAXException, IOException, ParserConfigurationException {
+ @Test
+ public void runTest() throws TransformerException, SAXException, IOException,
+ ParserConfigurationException {
DOMResult domres = new DOMResult();
diff --git a/test/java/org/apache/fop/layoutengine/ResultCheck.java b/test/java/org/apache/fop/layoutengine/ResultCheck.java
index ce95c5024..3b3a9cd98 100644
--- a/test/java/org/apache/fop/layoutengine/ResultCheck.java
+++ b/test/java/org/apache/fop/layoutengine/ResultCheck.java
@@ -40,9 +40,7 @@ public class ResultCheck implements LayoutEngineCheck {
this.property = node.getAttributes().getNamedItem("property").getNodeValue();
}
- /* (non-Javadoc)
- * @see LayoutEngineCheck#check(LayoutResult)
- */
+ /** {@inheritDoc} */
public void check(LayoutResult result) {
FormattingResults results = result.getResults();
String actual;
@@ -59,7 +57,7 @@ public class ResultCheck implements LayoutEngineCheck {
}
- /** @see java.lang.Object#toString() */
+ @Override
public String toString() {
return "Property: " + property;
}