diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2010-04-09 15:21:00 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2010-04-09 15:21:00 +0000 |
commit | 83f36b614c3f1f1a866ff70fe9363cd5be31e986 (patch) | |
tree | 6e96940806b3600d3bd964eb24611a43fa7e7505 | |
parent | fad33d93cca6ce80d6291b7b36f8ed5f01f6b6d7 (diff) | |
download | xmlgraphics-fop-83f36b614c3f1f1a866ff70fe9363cd5be31e986.tar.gz xmlgraphics-fop-83f36b614c3f1f1a866ff70fe9363cd5be31e986.zip |
Added test cases to ensure that the event notification system runs smoothly
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@932461 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | build.xml | 72 | ||||
-rw-r--r-- | test/events/area.fo | 15 | ||||
-rw-r--r-- | test/events/block-level.fo | 19 | ||||
-rw-r--r-- | test/events/inline-level.fo | 17 | ||||
-rw-r--r-- | test/events/resource.fo | 15 | ||||
-rw-r--r-- | test/events/table.fo | 34 | ||||
-rw-r--r-- | test/events/validation.fo | 15 | ||||
-rw-r--r-- | test/java/org/apache/fop/events/EventChecker.java | 52 | ||||
-rw-r--r-- | test/java/org/apache/fop/events/EventProcessingTestCase.java | 117 |
9 files changed, 328 insertions, 28 deletions
@@ -360,7 +360,8 @@ list of possible build targets. <pathelement location="${build.codegen-classes.dir}"/> </classpath> </taskdef> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/events/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/events/EventFormatter.xml"> + <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/events/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/events/EventFormatter.xml"> <fileset dir="${src.java.dir}"> <include name="**/*.java"/> <exclude name="org/apache/fop/render/*/**/*.java"/> @@ -369,43 +370,55 @@ list of possible build targets. </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/events/EventFormatter.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/accessibility/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/accessibility/AccessibilityEventProducer.xml"> + <eventResourceGenerator + modelfile="${build.gensrc.dir}/org/apache/fop/accessibility/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/accessibility/AccessibilityEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/accessibility/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/afp/AFPEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/afp/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/afp/AFPEventProducer.xml"> + <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/afp/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/afp/AFPEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/afp/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/afp/AFPEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/bitmap/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/render/bitmap/BitmapRendererEventProducer.xml"> + <eventResourceGenerator + modelfile="${build.gensrc.dir}/org/apache/fop/render/bitmap/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/render/bitmap/BitmapRendererEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/bitmap/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/bitmap/BitmapRendererEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/pcl/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/render/pcl/PCLEventProducer.xml"> + <eventResourceGenerator + modelfile="${build.gensrc.dir}/org/apache/fop/render/pcl/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/render/pcl/PCLEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/pcl/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/pcl/PCLEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/pdf/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/render/pdf/PDFEventProducer.xml"> + <eventResourceGenerator + modelfile="${build.gensrc.dir}/org/apache/fop/render/pdf/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/render/pdf/PDFEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/pdf/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/pdf/PDFEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/ps/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/render/ps/PSEventProducer.xml"> + <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/ps/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/render/ps/PSEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/ps/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/ps/PSEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/rtf/event-model.xml" translationfile="${src.java.dir}/org/apache/fop/render/rtf/RTFEventProducer.xml"> + <eventResourceGenerator + modelfile="${build.gensrc.dir}/org/apache/fop/render/rtf/event-model.xml" + translationfile="${src.java.dir}/org/apache/fop/render/rtf/RTFEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/rtf/**/*.java"/> </fileset> @@ -947,42 +960,45 @@ list of possible build targets. </target> <macrodef name="junit-run"> <attribute name="title"/> - <element name="tests"/> + <attribute name="basedir" default=""/> + <attribute name="testsuite"/> + <attribute name="outfile"/> <sequential> <echo message="Running @{title} tests..."/> <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure"> - <sysproperty key="basedir" value="${basedir}"/> + <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-build-tools-classpath"/> - <fileset dir="build"> - <include name="fop.jar"/> - </fileset> + <pathelement location="${build.dir}/fop.jar"/> </classpath> - <tests/> + <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"> - <tests> - <sysproperty key="fop.layoutengine.testset" value="standard"/> - <test name="org.apache.fop.intermediate.AreaTreeXMLFormatTestSuite" todir="${junit.reports.dir}" outfile="TEST-area-tree-xml-format"/> - </tests> - </junit-run> + <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-format" depends="junit-compile" description="Runs FOP's intermediate format JUnit tests" if="xmlunit.present"> - <junit-run title="intermediate format"> - <tests> - <sysproperty key="fop.layoutengine.testset" value="standard"/> - <test name="org.apache.fop.intermediate.IntermediateFormatTestSuite" todir="${junit.reports.dir}" outfile="TEST-intermediate-format"/> - </tests> - </junit-run> + <target name="junit-intermediate-format" depends="junit-compile" + 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"/> diff --git a/test/events/area.fo b/test/events/area.fo new file mode 100644 index 000000000..d10beccb0 --- /dev/null +++ b/test/events/area.fo @@ -0,0 +1,15 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="page" + page-height="420pt" page-width="320pt" margin="10pt"> + <fo:region-body background-color="#F0F0F0"/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="page"> + <fo:flow flow-name="xsl-region-body"> + <fo:block>This text contains an <fo:basic-link internal-destination="unresolved" + color="blue">unresolved reference</fo:basic-link>.</fo:block> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/events/block-level.fo b/test/events/block-level.fo new file mode 100644 index 000000000..df224260f --- /dev/null +++ b/test/events/block-level.fo @@ -0,0 +1,19 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="page" + page-height="420pt" page-width="320pt" margin="10pt"> + <fo:region-body background-color="#F0F0F0"/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="page"> + <fo:flow flow-name="xsl-region-body"> + <fo:block>The content of the following block-container is too wide:</fo:block> + <fo:block-container width="100pt" height="100pt" border="1pt solid black"> + <fo:block-container width="150pt" height="50pt" background-color="yellow"> + <fo:block/> + </fo:block-container> + </fo:block-container> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/events/inline-level.fo b/test/events/inline-level.fo new file mode 100644 index 000000000..26a00acff --- /dev/null +++ b/test/events/inline-level.fo @@ -0,0 +1,17 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="page" + page-height="420pt" page-width="320pt" margin="10pt"> + <fo:region-body background-color="#F0F0F0"/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="page"> + <fo:flow flow-name="xsl-region-body"> + <fo:block>The following line overflows its container:</fo:block> + <fo:block-container width="100pt" height="100pt" border="1pt solid black"> + <fo:block>ThisLineOverflowsItsContainer</fo:block> + </fo:block-container> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/events/resource.fo b/test/events/resource.fo new file mode 100644 index 000000000..64209e68d --- /dev/null +++ b/test/events/resource.fo @@ -0,0 +1,15 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="page" + page-height="420pt" page-width="320pt" margin="10pt"> + <fo:region-body background-color="#F0F0F0"/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="page"> + <fo:flow flow-name="xsl-region-body"> + <fo:block>This text contains a reference to a non-existent image: <fo:external-graphic + src="non-existent"/>.</fo:block> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/events/table.fo b/test/events/table.fo new file mode 100644 index 000000000..f71c30edb --- /dev/null +++ b/test/events/table.fo @@ -0,0 +1,34 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="page" + page-height="420pt" page-width="320pt" margin="10pt"> + <fo:region-body background-color="#F0F0F0"/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="page"> + <fo:flow flow-name="xsl-region-body"> + <fo:block>This table defines padding in collapsing border model:</fo:block> + <fo:table width="100%" table-layout="fixed" padding="1em"> + <fo:table-body> + <fo:table-row> + <fo:table-cell border="1pt solid black"> + <fo:block>Cell 1.1</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black"> + <fo:block>Cell 1.2</fo:block> + </fo:table-cell> + </fo:table-row> + <fo:table-row> + <fo:table-cell border="1pt solid black"> + <fo:block>Cell 2.1</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black"> + <fo:block>Cell 2.2</fo:block> + </fo:table-cell> + </fo:table-row> + </fo:table-body> + </fo:table> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/events/validation.fo b/test/events/validation.fo new file mode 100644 index 000000000..f4f30e05d --- /dev/null +++ b/test/events/validation.fo @@ -0,0 +1,15 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="page" + page-height="420pt" page-width="320pt" margin="10pt"> + <fo:region-body background-color="#F0F0F0"/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="page"> + <fo:flow flow-name="xsl-region-body"> + <fo:block border-before-style="blah">This block contains has a property with an invalid + value.</fo:block> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/java/org/apache/fop/events/EventChecker.java b/test/java/org/apache/fop/events/EventChecker.java new file mode 100644 index 000000000..767c590ed --- /dev/null +++ b/test/java/org/apache/fop/events/EventChecker.java @@ -0,0 +1,52 @@ +/* + * 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.events; + +import junit.framework.Assert; + +/** + * Class that checks that an expected event is produced, and only this one. + */ +class EventChecker extends Assert implements EventListener { + + private final String expectedEventID; + + private boolean eventReceived; + + EventChecker(String expectedEventID) { + this.expectedEventID = expectedEventID; + } + + public void processEvent(Event event) { + // Always create the message to make sure there is no error in the formatting process + String msg = EventFormatter.format(event); + if (event.getEventID().equals(expectedEventID)) { + eventReceived = true; + } else { + fail("Unexpected event: id = " + event.getEventID() + ": "+ msg); + } + } + + void end() { + if (!eventReceived) { + fail("Did not received expected event: " + expectedEventID); + } + } +} diff --git a/test/java/org/apache/fop/events/EventProcessingTestCase.java b/test/java/org/apache/fop/events/EventProcessingTestCase.java new file mode 100644 index 000000000..cf23c1dab --- /dev/null +++ b/test/java/org/apache/fop/events/EventProcessingTestCase.java @@ -0,0 +1,117 @@ +/* + * 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.events; + +import java.io.File; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +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.apache.commons.io.output.NullOutputStream; + +import org.apache.xmlgraphics.util.MimeConstants; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; +import org.apache.fop.area.AreaEventProducer; +import org.apache.fop.fo.FOValidationEventProducer; +import org.apache.fop.fo.flow.table.TableEventProducer; +import org.apache.fop.layoutmgr.BlockLevelEventProducer; +import org.apache.fop.layoutmgr.inline.InlineLevelEventProducer; + +/** + * Tests that the event notification system runs smoothly. + */ +public class EventProcessingTestCase extends TestCase { + + private final FopFactory fopFactory = FopFactory.newInstance(); + + private final TransformerFactory tFactory = TransformerFactory.newInstance(); + + private final File basedir; + + public EventProcessingTestCase(String name) { + super(name); + String base = System.getProperty("basedir"); + if (base != null) { + basedir = new File(base); + } else { + basedir = new File("."); + } + } + + private void doTest(String filename, String expectedEventID) + throws FOPException, TransformerException { + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, new NullOutputStream()); + EventChecker eventChecker = new EventChecker(expectedEventID); + fop.getUserAgent().getEventBroadcaster().addEventListener(eventChecker); + Transformer transformer = tFactory.newTransformer(); + Source src = new StreamSource(new File(basedir, filename)); + Result res = new SAXResult(fop.getDefaultHandler()); + transformer.transform(src, res); + eventChecker.end(); + } + + public void testArea() throws FOPException, TransformerException { + doTest("area.fo", + AreaEventProducer.class.getName() + ".unresolvedIDReferenceOnPage"); + } + + public void testResource() throws FOPException, TransformerException { + doTest("resource.fo", + ResourceEventProducer.class.getName() + ".imageNotFound"); + } + + public void testValidation() throws FOPException, TransformerException { + doTest("validation.fo", + FOValidationEventProducer.class.getName() + ".invalidPropertyValue"); + } + + public void testTable() throws FOPException, TransformerException { + doTest("table.fo", + TableEventProducer.class.getName() + ".noTablePaddingWithCollapsingBorderModel"); + } + + public void testBlockLevel() throws FOPException, TransformerException { + doTest("block-level.fo", + BlockLevelEventProducer.class.getName() + ".overconstrainedAdjustEndIndent"); + } + + public void testInlineLevel() throws FOPException, TransformerException { + doTest("inline-level.fo", + InlineLevelEventProducer.class.getName() + ".lineOverflows"); + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTestSuite(EventProcessingTestCase.class); + return suite; + } +} |