Browse Source

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
tags/fop-1_1rc1old
Peter Hancock 12 years ago
parent
commit
9860d5a133

+ 58
- 176
build.xml View File

@@ -186,10 +186,6 @@ list of possible build targets.
<property name="build.viewer.images.dir" value="${build.classes.dir}/org/apache/fop/render/awt/viewer/images"/>
<property name="build.property.examples.mime.type" value="application/pdf"/>
<property name="build.property.tests.mime.type" value="application/pdf"/>
<!--property name="layoutengine.disabled" value="test/layoutengine/disabled-testcases.txt"/-->
<!--property name="fotree.disabled" value="test/fotree/disabled-testcases.txt"/-->
<property name="layoutengine.disabled" value="test/layoutengine/disabled-testcases.xml"/>
<property name="fotree.disabled" value="test/fotree/disabled-testcases.xml"/>
<property name="dist.bin.dir" value="${basedir}/dist-bin"/>
<property name="dist.src.dir" value="${basedir}/dist-src"/>
<property name="nightly.dir" value="${basedir}/nightly"/>
@@ -747,84 +743,34 @@ list of possible build targets.
</target>
<target name="junit-compile" depends="junit-compile-java, junit-compile-copy-resources" description="Compiles FOP's JUnit tests" if="junit.present"/>
<target name="junit-transcoder" depends="junit-compile" description="Runs FOP's JUnit transcoder tests" if="junit.present">
<echo message="Running basic functionality tests for fop-transcoder.jar"/>
<junit dir="${basedir}">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-build-classpath"/>
<fileset dir="${build.dir}">
<include name="fop-transcoder.jar"/>
</fileset>
</classpath>
<test name="org.apache.fop.BasicTranscoderTestSuite" todir="${junit.reports.dir}" outfile="TEST-transcoder"/>
</junit>
<path id="transcoder-classpath">
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-build-classpath"/>
<fileset dir="${build.dir}">
<include name="fop-transcoder.jar"/>
</fileset>
</path>
<junit-run classpath="transcoder-classpath" title="basic functionality for fop-transcoder.jar" testsuite="org.apache.fop.BasicTranscoderTestSuite" outfile="TEST-transcoder"/>
<echo message="Running basic functionality tests for fop-transcoder-allinone.jar"/>
<!-- These are the same tests as in the block above but testing the "allinone" JAR
<!-- These are the same tests as in the block above but testing the "allinone" JAR
instead. Please don't add any additional paths other than the test classes, the
allinone JAR and the any Batik JARs to the classpath. If this fails, but the
previous test block succeeded it indicates that the packaging of the allinone
JAR needs to be updated.
-->
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-build-classpath"/>
<fileset dir="build">
<include name="fop-transcoder-allinone.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="xml-apis*.jar"/>
<include name="xerces*.jar"/>
<include name="batik*.jar"/>
</fileset>
</classpath>
<test name="org.apache.fop.BasicTranscoderTestSuite" todir="${junit.reports.dir}" outfile="TEST-transcoder-allinone"/>
</junit>
</target>
<target name="junit-userconfig" depends="junit-compile" if="junit.present" description="Runs FOP's user config JUnit tests">
<echo message="Running user config tests"/>
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
<sysproperty key="fop.layoutengine.testset" value="standard"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-run-classpath"/>
</classpath>
<test name="org.apache.fop.config.UserConfigTestSuite" todir="${junit.reports.dir}" outfile="TEST-userconfig"/>
</junit>
</target>
<target name="junit-basic" depends="junit-compile" description="Runs FOP's JUnit basic tests" if="junit.present">
<echo message="Running basic functionality tests for fop.jar"/>
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-build-classpath"/>
<fileset dir="build">
<include name="fop.jar"/>
</fileset>
</classpath>
<test name="org.apache.fop.StandardTestSuite" todir="${junit.reports.dir}"/>
</junit>
<path id="transcoder-all-classpath">
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-build-classpath"/>
<fileset dir="build">
<include name="fop-transcoder-allinone.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="xml-apis*.jar"/>
<include name="xerces*.jar"/>
<include name="batik*.jar"/>
</fileset>
</path>
<junit-run classpath="transcoder-all-classpath" title="basic functionality for fop-transcoder-allinone.jar" testsuite="org.apache.fop.BasicTranscoderTestSuite" outfile="TEST-transcoder-allinone"/>
</target>
<target name="hyphenation-present" depends="junit-compile" if="junit.present">
<condition property="hyphenation.present">
@@ -844,132 +790,68 @@ list of possible build targets.
</condition>
<echo message="${hyphenation.message}"/>
</target>
<target name="junit-layout-standard" depends="junit-compile, junit-fotree" if="junit.present" description="Runs FOP's standard JUnit layout tests">
<echo message="Running standard layout engine tests"/>
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
<sysproperty key="fop.layoutengine.testset" value="standard"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-run-classpath"/>
</classpath>
<test name="org.apache.fop.layoutengine.LayoutEngineTestSuite" todir="${junit.reports.dir}" outfile="TEST-layoutengine-standard"/>
</junit>
</target>
<target name="junit-layout-hyphenation" depends="hyphenation-present, junit-compile" if="hyphenation.present" description="Runs FOP's JUnit hyphenation layout tests">
<echo message="Running hyphenation layout engine tests"/>
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
<sysproperty key="fop.layoutengine.testset" value="hyphenation"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-run-classpath"/>
</classpath>
<test name="org.apache.fop.layoutengine.LayoutEngineTestSuite" todir="${junit.reports.dir}" outfile="TEST-layoutengine-hyphenation"/>
</junit>
</target>
<target name="junit-layout" depends="junit-layout-standard, junit-layout-hyphenation" description="Runs all FOP's JUnit layout tests"/>
<target name="junit-fotree" depends="junit-compile" description="Runs FOP's FO tree JUnit tests" if="junit.present">
<echo message="Running fo tree tests"/>
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<sysproperty key="fop.layoutengine.disabled" value="${fotree.disabled}"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-build-classpath"/>
<fileset dir="build">
<include name="fop.jar"/>
</fileset>
</classpath>
<test name="org.apache.fop.fotreetest.FOTreeTestSuite" todir="${junit.reports.dir}" outfile="TEST-FO-tree"/>
</junit>
</target>
<path id="standard-junit-classpath">
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-tools-build-classpath"/>
<pathelement location="${build.dir}/fop.jar"/>
</path>
<macrodef name="junit-run">
<attribute name="title"/>
<attribute name="basedir" default=""/>
<attribute name="testsuite"/>
<attribute name="outfile"/>
<attribute name="classpath" default="standard-junit-classpath"/>
<sequential>
<echo message="Running @{title} tests..."/>
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}/@{basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
<sysproperty key="fop.layoutengine.testset" value="standard"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-tools-build-classpath"/>
<pathelement location="${build.dir}/fop.jar"/>
<path refid="@{classpath}"/>
</classpath>
<test name="@{testsuite}" todir="${junit.reports.dir}" outfile="@{outfile}"/>
</junit>
</sequential>
</macrodef>
<target name="junit-area-tree-xml-format" depends="junit-compile"
description="Runs FOP's area tree XML format JUnit tests" if="xmlunit.present">
<junit-run title="area tree XML format"
testsuite="org.apache.fop.intermediate.AreaTreeXMLFormatTestSuite"
outfile="TEST-area-tree-xml-format"/>
<target name="junit-basic" depends="junit-compile" description="Runs FOP's JUnit basic tests" if="junit.present">
<junit-run title="Standard test suite" testsuite="org.apache.fop.StandardTestSuite" outfile="TEST-standard-tests-suite"/>
</target>
<target name="junit-userconfig" depends="junit-compile" if="junit.present" description="Runs FOP's user config JUnit tests">
<junit-run title="user config" testsuite="org.apache.fop.config.UserConfigTestSuite" outfile="TEST-userconfig"/>
</target>
<target name="junit-layout-standard" depends="junit-compile, junit-fotree" if="junit.present" description="Runs FOP's standard JUnit layout tests">
<junit-run title="standard layout engine" testsuite="org.apache.fop.layoutengine.LayoutEngineTestSuite" outfile="TEST-layoutengine-standard"/>
</target>
<target name="junit-layout-hyphenation" depends="hyphenation-present, junit-compile" if="hyphenation.present" description="Runs FOP's JUnit hyphenation layout tests">
<property name="fop.layoutengine.testset" value="hyphenation"/>
<junit-run title="hyphenation layout engine" testsuite="org.apache.fop.layoutengine.LayoutEngineTestSuite" outfile="TEST-layoutengine-hyphenation"/>
</target>
<target name="junit-layout" depends="junit-layout-standard, junit-layout-hyphenation" description="Runs all FOP's JUnit layout tests"/>
<target name="junit-fotree" depends="junit-compile" description="Runs FOP's FO tree JUnit tests" if="junit.present">
<junit-run title="fo tree" testsuite="org.apache.fop.fotreetest.FOTreeTestSuite" outfile="TEST-FO-tree"/>
</target>
<target name="junit-area-tree-xml-format" depends="junit-compile" description="Runs FOP's area tree XML format JUnit tests" if="xmlunit.present">
<junit-run title="area tree XML format" testsuite="org.apache.fop.intermediate.AreaTreeXMLFormatTestSuite" outfile="TEST-area-tree-xml-format"/>
</target>
<target name="junit-intermediate-layout" depends="junit-compile" if="xmlunit.present">
<junit-run title="intermediate format from layout tests"
testsuite="org.apache.fop.intermediate.LayoutIFTestSuite"
outfile="TEST-intermediate-format-from-layout"/>
</target>
<target name="junit-intermediate-format" depends="junit-compile,junit-intermediate-layout"
description="Runs FOP's intermediate format JUnit tests" if="xmlunit.present">
<junit-run title="intermediate format"
testsuite="org.apache.fop.intermediate.IntermediateFormatTestSuite"
outfile="TEST-intermediate-format"/>
</target>
<target name="junit-events" depends="junit-compile"
description="Runs FOP's event JUnit tests" if="junit.present">
<junit-run title="event" basedir="test/events"
testsuite="org.apache.fop.events.EventProcessingTestCase"
outfile="TEST-events"/>
<junit-run title="intermediate format from layout tests" testsuite="org.apache.fop.intermediate.LayoutIFTestSuite" outfile="TEST-intermediate-format-from-layout"/>
</target>
<target name="junit-intermediate-format" depends="junit-compile,junit-intermediate-layout" description="Runs FOP's intermediate format JUnit tests" if="xmlunit.present">
<junit-run title="intermediate format" testsuite="org.apache.fop.intermediate.IntermediateFormatTestSuite" outfile="TEST-intermediate-format"/>
</target>
<target name="junit-events" depends="junit-compile" description="Runs FOP's event JUnit tests" if="junit.present">
<junit-run title="event" basedir="test/events" testsuite="org.apache.fop.events.EventProcessingTestCase" outfile="TEST-events"/>
</target>
<target name="junit-text-linebreak" depends="junit-compile" description="Runs FOP's JUnit unicode linebreak tests" if="junit.present">
<echo message="Running tests for Unicode UAX#14 support"/>
<junit dir="${basedir}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
<sysproperty key="basedir" value="${basedir}"/>
<sysproperty key="jawa.awt.headless" value="true"/>
<formatter type="brief" usefile="false"/>
<formatter type="plain" usefile="true"/>
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
<path refid="libs-build-classpath"/>
<fileset dir="build">
<include name="fop.jar"/>
</fileset>
</classpath>
<test name="org.apache.fop.text.linebreak.LineBreakStatusTest" todir="${junit.reports.dir}"/>
</junit>
<junit-run title="Unicode UAX#14 support" testsuite="org.apache.fop.text.linebreak.LineBreakStatusTest" outfile="TEST-linebreak"/>
</target>
<target name="junit-render-pdf" depends="junit-compile">
<echo message="Running tests for the render pdf package"/>
<junit-run title="render-pdf" testsuite="org.apache.fop.render.pdf.RenderPDFTestSuite"
outfile="TEST-render-pdf"/>
<junit-run title="render-pdf" testsuite="org.apache.fop.render.pdf.RenderPDFTestSuite" outfile="TEST-render-pdf"/>
</target>
<target name="junit-reduced" depends="junit-userconfig, junit-basic, junit-transcoder,
junit-text-linebreak, junit-fotree, junit-render-pdf"/>
<target name="junit-reduced" depends="junit-userconfig, junit-basic, junit-transcoder, junit-text-linebreak, junit-fotree, junit-render-pdf"/>
<target name="junit-full" depends="junit-reduced, junit-layout, junit-area-tree-xml-format, junit-intermediate-format"/>
<target name="junit" depends="junit-full" description="Runs all of FOP's JUnit tests" if="junit.present">
<fail><condition><or><isset property="fop.junit.error"/><isset property="fop.junit.failure"/><not><isset property="hyphenation.present"/></not></or></condition>

+ 2
- 3
src/java/org/apache/fop/layoutmgr/PageBreaker.java View File

@@ -277,9 +277,8 @@ public class PageBreaker extends AbstractBreaker {
separatorArea.setIPD(
pslm.getCurrentPV().getRegionReference(Constants.FO_REGION_BODY).getIPD());
// create a StaticContentLM for the footnote separator
footnoteSeparatorLM = (StaticContentLayoutManager)
pslm.getLayoutManagerMaker().makeStaticContentLayoutManager(
pslm, footnoteSeparator, separatorArea);
footnoteSeparatorLM = pslm.getLayoutManagerMaker().makeStaticContentLayoutManager(
pslm, footnoteSeparator, separatorArea);
footnoteSeparatorLM.doLayout();
}


+ 3
- 0
status.xml View File

@@ -60,6 +60,9 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
<action context="Code" dev="PH" type="add" fixes-bug="52010" due-to="Mehdi Houshmand">
Simplification of the build: Reduced code duplication and layout engine tests.
</action>
<action context="Renderers" dev="JM" type="add">
Various bugfixes to make PDFDocumentGraphics2D operational again.
</action>

+ 18
- 39
test/java/org/apache/fop/fotreetest/FOTreeTester.java View File

@@ -20,7 +20,6 @@
package org.apache.fop.fotreetest;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@@ -36,14 +35,6 @@ import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLFilterImpl;

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.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
@@ -51,6 +42,7 @@ import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryConfigurator;
import org.apache.fop.fotreetest.ext.TestElementMapping;
import org.apache.fop.layoutengine.LayoutEngineTestUtils;
import org.apache.fop.layoutengine.TestFilesConfiguration;
import org.apache.fop.util.ConsoleEventListenerForTests;

/**
@@ -64,36 +56,23 @@ public class FOTreeTester {
DebugHelper.registerStandardElementListObservers();
}

/**
* Gets the parameters to run the FO tree test cases.
* @return a collection of file arrays containing the test files
*/
@Parameters
public static Collection<File[]> testXMLTestCases() throws Exception {
File mainDir = new File("test/fotree");

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 = LayoutEngineTestUtils.decorateWithDisabledList(filter);
}
Collection<File> 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);
}
// Unfortunately JUnit forces us to return a collection of arrays.
Collection<File[]> parameters = new ArrayList<File[]>();
for (File f : files) {
parameters.add(new File[] { f });
}
return parameters;
public static Collection<File[]> getParameters() {
TestFilesConfiguration.Builder builder = new TestFilesConfiguration.Builder();
builder.testDir("test/fotree")
.singleProperty("fop.fotree.single")
.startsWithProperty("fop.fotree.starts-with")
.suffix(".fo")
.testSet("testcases")
.disabledProperty("fop.layoutengine.disabled", "test/fotree/disabled-testcases.xml")
.privateTestsProperty("fop.fotree.private");

TestFilesConfiguration testConfig = builder.build();
return LayoutEngineTestUtils.getTestFiles(testConfig);
}

private FopFactory fopFactory = FopFactory.newInstance();
@@ -153,7 +132,7 @@ public class FOTreeTester {
throw e;
}

List results = collector.getResults();
List<String> results = collector.getResults();
if (results.size() > 0) {
for (int i = 0; i < results.size(); i++) {
System.out.println((String) results.get(i));

+ 3
- 2
test/java/org/apache/fop/fotreetest/ResultCollector.java View File

@@ -19,6 +19,7 @@

package org.apache.fop.fotreetest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@@ -29,7 +30,7 @@ public class ResultCollector {

private static ResultCollector instance = null;

private List results = new java.util.ArrayList();
private List<String> results = new ArrayList<String>();

/** @return the ResultCollector singleton */
public static ResultCollector getInstance() {
@@ -70,7 +71,7 @@ public class ResultCollector {
}

/** @return the list of results */
public List getResults() {
public List<String> getResults() {
return Collections.unmodifiableList(results);
}
}

+ 1
- 1
test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java View File

@@ -63,7 +63,7 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTestCase {
*/
@Parameters
public static Collection<File[]> getParameters() throws IOException {
return LayoutEngineTestUtils.getTestFiles();
return LayoutEngineTestUtils.getLayoutTestFiles();
}
/**
* Constructor for the test suite that is used for each test file.

+ 1
- 1
test/java/org/apache/fop/intermediate/IFParserTestCase.java View File

@@ -56,7 +56,7 @@ public class IFParserTestCase extends AbstractIFTestCase {
*/
@Parameters
public static Collection<File[]> getParameters() throws IOException {
return LayoutEngineTestUtils.getTestFiles();
return LayoutEngineTestUtils.getLayoutTestFiles();
}

/**

+ 61
- 34
test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java View File

@@ -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);
}

}

+ 21
- 18
test/java/org/apache/fop/layoutengine/LayoutEngineTester.java View File

@@ -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

+ 205
- 0
test/java/org/apache/fop/layoutengine/TestFilesConfiguration.java View File

@@ -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);
}
}
}

+ 6
- 12
test/java/org/apache/fop/visual/BatchDiffer.java View File

@@ -23,7 +23,6 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.stream.StreamSource;
@@ -150,8 +149,7 @@ public class BatchDiffer {
throw new RuntimeException("source-directory does not exist: " + srcDir);
}
final File targetDir = new File(cfg.getChild("target-directory").getValue());
targetDir.mkdirs();
if (!targetDir.exists()) {
if (!targetDir.mkdirs() && !targetDir.exists()) {
throw new RuntimeException("target-directory is invalid: " + targetDir);
}
context.setTargetDir(targetDir);
@@ -164,7 +162,8 @@ public class BatchDiffer {
IOFileFilter filter = new SuffixFileFilter(new String[] {".xml", ".fo"});
//Same filtering as in layout engine tests
if (cfg.getChild("filter-disabled").getValueAsBoolean(true)) {
filter = LayoutEngineTestUtils.decorateWithDisabledList(filter);
String disabled = System.getProperty("fop.layoutengine.disabled");
filter = LayoutEngineTestUtils.decorateWithDisabledList(filter, disabled);
}
String manualFilter = cfg.getChild("manual-filter").getValue(null);
if (manualFilter != null) {
@@ -176,10 +175,8 @@ public class BatchDiffer {
}

int maxfiles = cfg.getChild("max-files").getValueAsInteger(-1);
Collection files = FileUtils.listFiles(srcDir, filter, null);
Iterator i = files.iterator();
while (i.hasNext()) {
final File f = (File)i.next();
Collection<File> files = FileUtils.listFiles(srcDir, filter, null);
for (final File f : files) {
try {
log.info("---=== " + f + " ===---");
long[] times = new long[producers.length];
@@ -228,9 +225,6 @@ public class BatchDiffer {
break;
}
}
} catch (IOException ioe) {
log.error("I/O problem while processing", ioe);
throw new RuntimeException("I/O problem: " + ioe.getMessage());
} catch (ConfigurationException e) {
log.error("Error while configuring BatchDiffer", e);
throw new RuntimeException("Error while configuring BatchDiffer: " + e.getMessage());
@@ -260,7 +254,7 @@ public class BatchDiffer {
BitmapProducer[] producers = new BitmapProducer[children.length];
for (int i = 0; i < children.length; i++) {
try {
Class clazz = Class.forName(children[i].getAttribute("classname"));
Class<?> clazz = Class.forName(children[i].getAttribute("classname"));
producers[i] = (BitmapProducer)clazz.newInstance();
ContainerUtil.configure(producers[i], children[i]);
} catch (Exception e) {

Loading…
Cancel
Save