From 83f36b614c3f1f1a866ff70fe9363cd5be31e986 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 9 Apr 2010 15:21:00 +0000 Subject: [PATCH] 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 --- build.xml | 72 ++++++----- test/events/area.fo | 15 +++ test/events/block-level.fo | 19 +++ test/events/inline-level.fo | 17 +++ test/events/resource.fo | 15 +++ test/events/table.fo | 34 +++++ test/events/validation.fo | 15 +++ .../org/apache/fop/events/EventChecker.java | 52 ++++++++ .../fop/events/EventProcessingTestCase.java | 117 ++++++++++++++++++ 9 files changed, 328 insertions(+), 28 deletions(-) create mode 100644 test/events/area.fo create mode 100644 test/events/block-level.fo create mode 100644 test/events/inline-level.fo create mode 100644 test/events/resource.fo create mode 100644 test/events/table.fo create mode 100644 test/events/validation.fo create mode 100644 test/java/org/apache/fop/events/EventChecker.java create mode 100644 test/java/org/apache/fop/events/EventProcessingTestCase.java diff --git a/build.xml b/build.xml index 4601a48d1..c0bde2d3f 100644 --- a/build.xml +++ b/build.xml @@ -360,7 +360,8 @@ list of possible build targets. - + @@ -369,43 +370,55 @@ list of possible build targets. - + - + - + - + - + - + - + @@ -947,42 +960,45 @@ list of possible build targets. - + + + - + + - - - + - + - - - - - - - + + - - - - - - - + + + + + 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 @@ + + + + + + + + + + This text contains an unresolved reference. + + + 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 @@ + + + + + + + + + + The content of the following block-container is too wide: + + + + + + + + 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 @@ + + + + + + + + + + The following line overflows its container: + + ThisLineOverflowsItsContainer + + + + 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 @@ + + + + + + + + + + This text contains a reference to a non-existent image: . + + + 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 @@ + + + + + + + + + + This table defines padding in collapsing border model: + + + + + Cell 1.1 + + + Cell 1.2 + + + + + Cell 2.1 + + + Cell 2.2 + + + + + + + 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 @@ + + + + + + + + + + This block contains has a property with an invalid + value. + + + 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; + } +} -- 2.39.5