aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/layoutengine
diff options
context:
space:
mode:
authorPeter Hancock <phancock@apache.org>2011-10-19 10:21:17 +0000
committerPeter Hancock <phancock@apache.org>2011-10-19 10:21:17 +0000
commit9860d5a1338df6ad70e269d2423e7059c9194102 (patch)
tree569a87691daa0a460954e7dea5425c1fe5d9bc7a /test/java/org/apache/fop/layoutengine
parent87f892d9d8b3e6459e19538156a70632a1bb4e6f (diff)
downloadxmlgraphics-fop-9860d5a1338df6ad70e269d2423e7059c9194102.tar.gz
xmlgraphics-fop-9860d5a1338df6ad70e269d2423e7059c9194102.zip
Bugzilla#512010: Simplification of the build.
Reduced code duplication and layout engine tests. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1186070 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop/layoutengine')
-rw-r--r--test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java95
-rw-r--r--test/java/org/apache/fop/layoutengine/LayoutEngineTester.java39
-rw-r--r--test/java/org/apache/fop/layoutengine/TestFilesConfiguration.java205
3 files changed, 287 insertions, 52 deletions
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java
index 6beda1f30..772204d28 100644
--- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java
@@ -20,7 +20,6 @@
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;
@@ -58,9 +57,9 @@ public final class LayoutEngineTestUtils {
private static class FilenameHandler extends DefaultHandler {
private StringBuffer buffer = new StringBuffer(128);
private boolean readingFilename = false;
- private List filenames;
+ private List<String> filenames;
- public FilenameHandler(List filenames) {
+ public FilenameHandler(List<String> filenames) {
this.filenames = filenames;
}
@@ -93,19 +92,24 @@ public final class LayoutEngineTestUtils {
}
}
- public static IOFileFilter decorateWithDisabledList(IOFileFilter filter) throws IOException {
- String disabled = System.getProperty("fop.layoutengine.disabled");
+ /**
+ * Removes from {@code filter} any tests that have been disabled.
+ *
+ * @param filter the filter populated with tests
+ * @param disabled name of the file containing disabled test cases. If null or empty,
+ * no file is read
+ * @return {@code filter} minus any disabled tests
+ */
+ public static IOFileFilter decorateWithDisabledList(IOFileFilter filter, String disabled) {
if (disabled != null && disabled.length() > 0) {
- filter = new AndFileFilter(new NotFileFilter(
- new NameFileFilter(LayoutEngineTestUtils.readDisabledTestcases(new File(
- disabled)))),
- filter);
+ 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();
+ private static String[] readDisabledTestcases(File f) {
+ List<String> lines = new ArrayList<String>();
Source stylesheet = new StreamSource(
new File("test/layoutengine/disabled-testcase2filename.xsl"));
Source source = new StreamSource(f);
@@ -114,43 +118,41 @@ public final class LayoutEngineTestUtils {
Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesheet);
transformer.transform(source, result);
} catch (TransformerConfigurationException tce) {
- throw new RuntimeException(tce.getMessage());
+ throw new RuntimeException(tce);
} catch (TransformerException te) {
- throw new RuntimeException(te.getMessage());
+ throw new RuntimeException(te);
}
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
+ * Returns the test files matching the given configuration.
+ *
+ * @param testConfig the test configuration
+ * @return the applicable test cases
*/
- public static Collection<File[]> getTestFiles() throws IOException {
- File mainDir = new File("test/layoutengine");
+ public static Collection<File[]> getTestFiles(TestFilesConfiguration testConfig) {
+ File mainDir = testConfig.getTestDirectory();
IOFileFilter filter;
- String single = System.getProperty("fop.layoutengine.single");
- String startsWith = System.getProperty("fop.layoutengine.starts-with");
+ String single = testConfig.getSingleTest();
+ String startsWith = testConfig.getStartsWith();
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);
+ filter = new AndFileFilter(filter, new SuffixFileFilter(testConfig.getFileSuffix()));
+ filter = decorateWithDisabledList(filter, testConfig.getDisabledTests());
} else {
- filter = new SuffixFileFilter(".xml");
- filter = decorateWithDisabledList(filter);
+ filter = new SuffixFileFilter(testConfig.getFileSuffix());
+ filter = decorateWithDisabledList(filter, testConfig.getDisabledTests());
}
- 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);
+ String testset = testConfig.getTestSet();
+
+ Collection<File> files = FileUtils.listFiles(new File(mainDir, testset), filter,
+ TrueFileFilter.INSTANCE);
+ if (testConfig.hasPrivateTests()) {
+ Collection<File> privateFiles = FileUtils.listFiles(new File(mainDir,
+ "private-testcases"), filter, TrueFileFilter.INSTANCE);
files.addAll(privateFiles);
}
@@ -162,4 +164,29 @@ public final class LayoutEngineTestUtils {
return parametersForJUnit4;
}
+ /**
+ * This is a helper method that uses the standard parameters for FOP's layout engine tests and
+ * returns a set of test files. These pull in System parameters to configure the layout tests
+ * to run.
+ *
+ * @return A collection of file arrays that contain the test files
+ */
+ public static Collection<File[]> getLayoutTestFiles() {
+ TestFilesConfiguration.Builder builder = new TestFilesConfiguration.Builder();
+ String testSet = System.getProperty("fop.layoutengine.testset");
+ testSet = (testSet != null ? testSet : "standard") + "-testcases";
+
+ builder.testDir("test/layoutengine")
+ .singleProperty("fop.layoutengine.single")
+ .startsWithProperty("fop.layoutengine.starts-with")
+ .suffix(".xml")
+ .testSet(testSet)
+ .disabledProperty("fop.layoutengine.disabled",
+ "test/layoutengine/disabled-testcases.xml")
+ .privateTestsProperty("fop.layoutengine.private");
+
+ TestFilesConfiguration testConfig = builder.build();
+ return getTestFiles(testConfig);
+ }
+
}
diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
index 867602cce..33f621f84 100644
--- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
+++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
@@ -34,6 +34,17 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.TransformerHandler;
+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;
+
import org.apache.fop.DebugHelper;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
@@ -53,16 +64,6 @@ 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
@@ -71,14 +72,15 @@ import org.xml.sax.SAXException;
@RunWith(Parameterized.class)
public class LayoutEngineTester {
private static File areaTreeBackupDir;
- /**
- * Sets up the class, this is invoked only once.
- */
+
@BeforeClass
- public static void makeDirAndRegisterDebugHelper() {
+ public static void makeDirAndRegisterDebugHelper() throws IOException {
DebugHelper.registerStandardElementListObservers();
areaTreeBackupDir = new File("build/test-results/layoutengine");
- areaTreeBackupDir.mkdirs();
+ if (!areaTreeBackupDir.mkdirs() && !areaTreeBackupDir.exists()) {
+ throw new IOException("Failed to create the layout engine directory at "
+ + "build/test-results/layoutengine");
+ }
}
/**
@@ -89,7 +91,7 @@ public class LayoutEngineTester {
*/
@Parameters
public static Collection<File[]> getParameters() throws IOException {
- return LayoutEngineTestUtils.getTestFiles();
+ return LayoutEngineTestUtils.getLayoutTestFiles();
}
private TestAssistant testAssistant = new TestAssistant();
@@ -161,9 +163,9 @@ public class LayoutEngineTester {
}
Document doc = (Document)domres.getNode();
- if (this.areaTreeBackupDir != null) {
+ if (areaTreeBackupDir != null) {
testAssistant.saveDOM(doc,
- new File(this.areaTreeBackupDir, testFile.getName() + ".at.xml"));
+ new File(areaTreeBackupDir, testFile.getName() + ".at.xml"));
}
FormattingResults results = fop.getResults();
LayoutResult result = new LayoutResult(doc, elCollector, results);
@@ -172,6 +174,7 @@ public class LayoutEngineTester {
/**
* Perform all checks on the area tree and, optionally, on the intermediate format.
+ * @param fopFactory the FOP factory
* @param testFile Test case XML file
* @param result The layout results
* @throws TransformerException if a problem occurs in XSLT/JAXP
diff --git a/test/java/org/apache/fop/layoutengine/TestFilesConfiguration.java b/test/java/org/apache/fop/layoutengine/TestFilesConfiguration.java
new file mode 100644
index 000000000..656fc5f6f
--- /dev/null
+++ b/test/java/org/apache/fop/layoutengine/TestFilesConfiguration.java
@@ -0,0 +1,205 @@
+/*
+ * 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;
+
+/**
+ * A class that contains the information needed to run a suite of layout engine and FO tree
+ * tests.
+ */
+public final class TestFilesConfiguration {
+
+ private final File testDirectory;
+ private final String singleTest;
+ private final String testStartsWith;
+ private final String testFileSuffix;
+ private final String testSet;
+ private final String disabledTests;
+ private final boolean privateTests;
+
+ private TestFilesConfiguration(Builder builder) {
+ this.testDirectory = new File(builder.testDirectory);
+ this.singleTest = builder.singleTest;
+ this.testStartsWith = builder.testStartsWith;
+ this.testFileSuffix = builder.testFileSuffix;
+ this.testSet = builder.testSet;
+ this.privateTests = builder.privateTests;
+ this.disabledTests = builder.disabledTests;
+ }
+
+ /**
+ * Returns the directory of the tests.
+ * @return the test directory
+ */
+ public File getTestDirectory() {
+ return testDirectory;
+ }
+
+ /**
+ * Returns the name of the single test file to run.
+ * @return the single test file name
+ */
+ public String getSingleTest() {
+ return singleTest;
+ }
+
+ /**
+ * Returns the string that must prefix the test file names.
+ * @return the prefixing string
+ */
+ public String getStartsWith() {
+ return testStartsWith;
+ }
+
+ /**
+ * Returns the file suffix (i.e. ".xml" for XML files and ".fo" for FOs).
+ * @return the file suffix
+ */
+ public String getFileSuffix() {
+ return testFileSuffix;
+ }
+
+ /**
+ * Returns the directory set of tests to be run.
+ * @return the directory tests
+ */
+ public String getTestSet() {
+ return testSet;
+ }
+
+ /**
+ * Returns the name of the XML file containing the disabled tests.
+ * @return a file name, may be null
+ */
+ public String getDisabledTests() {
+ return disabledTests;
+ }
+
+ /**
+ * Whether any private tests should be invoked.
+ * @return true if private tests should be tested
+ */
+ public boolean hasPrivateTests() {
+ return privateTests;
+ }
+
+ /**
+ * A builder class that configures the data for running a suite of tests designed for the
+ * layout engine and FOTree.
+ */
+ public static class Builder {
+
+ private String testDirectory;
+ private String singleTest;
+ private String testStartsWith;
+ private String testFileSuffix;
+ private String testSet;
+ private String disabledTests;
+ private boolean privateTests;
+
+ /**
+ * Configures the test directory.
+ * @param dir the test directory
+ * @return {@code this}
+ */
+ public Builder testDir(String dir) {
+ testDirectory = dir;
+ return this;
+ }
+
+ /**
+ * Configures the name of the single test to run.
+ * @param singleProperty name of the property that determines the single test case
+ * @return {@code this}
+ */
+ public Builder singleProperty(String singleProperty) {
+ singleTest = getSystemProperty(singleProperty);
+ return this;
+ }
+
+ /**
+ * Configures the prefix that all test cases must match.
+ * @param startsWithProperty name of the property that determines the common prefix
+ * @return {@code this}
+ */
+ public Builder startsWithProperty(String startsWithProperty) {
+ testStartsWith = getSystemProperty(startsWithProperty);
+ return this;
+ }
+
+ /**
+ * Configures the test file name suffix.
+ * @param suffix the suffixing string
+ * @return {@code this}
+ */
+ public Builder suffix(String suffix) {
+ testFileSuffix = suffix;
+ return this;
+ }
+
+ /**
+ * Configures the name of the directory containing the set of tests.
+ * @param testSet the directory of tests. If null, defaults to "standard-testcases"
+ * @return {@code this}
+ */
+ public Builder testSet(String testSet) {
+ this.testSet = testSet != null ? testSet : "standard-testcases";
+ return this;
+ }
+
+ /**
+ * Configures whether any tests are disabled.
+ * @param disabledProperty name of the property that determines the file of
+ * disabled test cases
+ * @param defaultValue if the property was not defined, uses this file name
+ * instead
+ * @return {@code this}
+ */
+ public Builder disabledProperty(String disabledProperty, String defaultValue) {
+ String property = getSystemProperty(disabledProperty);
+ disabledTests = property != null ? property : defaultValue;
+ return this;
+ }
+
+ /**
+ * Configures whether private tests must be run or not.
+ * @param privateTestsProperty name of the property containing the boolean switch
+ * @return {@code this}
+ */
+ public Builder privateTestsProperty(String privateTestsProperty) {
+ String property = getSystemProperty(privateTestsProperty);
+ this.privateTests = property != null && property.equalsIgnoreCase("true");
+ return this;
+ }
+
+ private String getSystemProperty(String property) {
+ return System.getProperty(property);
+ }
+
+ /**
+ * Creates the configuration instance.
+ * @return a configuration instance configured by this builder
+ */
+ public TestFilesConfiguration build() {
+ return new TestFilesConfiguration(this);
+ }
+ }
+}