From d955d844f87378114e860a7a2ab637a03dc35d7e Mon Sep 17 00:00:00 2001 From: Mehdi Houshmand Date: Mon, 21 Nov 2011 16:35:41 +0000 Subject: Changed the error handling for AFP fonts such that errors are passed to the AFPEventProducer. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1204579 13f79535-47bb-0310-9956-ffa450edef68 --- test/config/afp-codepage-missing.xconf | 16 +++++ test/config/afp-font-missing.xconf | 13 ++++ test/config/afp-invalid-characterset.xconf | 16 +++++ test/config/afp-invalid-config.xconf | 16 +++++ test/config/afp-invalid-file-name.xconf | 16 +++++ test/config/afp-raster-font-missing.xconf | 15 ++++ test/config/afp-triplet-missing.xconf | 15 ++++ .../apache/fop/afp/AFPEventProcessingTestCase.java | 79 ++++++++++++++++++++++ test/java/org/apache/fop/afp/simple.fo | 14 ++++ .../apache/fop/events/EventProcessingTestCase.java | 15 ++-- .../fop/fonts/FontEventProcessingTestCase.java | 13 +++- 11 files changed, 217 insertions(+), 11 deletions(-) create mode 100644 test/config/afp-codepage-missing.xconf create mode 100644 test/config/afp-font-missing.xconf create mode 100644 test/config/afp-invalid-characterset.xconf create mode 100644 test/config/afp-invalid-config.xconf create mode 100644 test/config/afp-invalid-file-name.xconf create mode 100644 test/config/afp-raster-font-missing.xconf create mode 100644 test/config/afp-triplet-missing.xconf create mode 100644 test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java create mode 100644 test/java/org/apache/fop/afp/simple.fo (limited to 'test') diff --git a/test/config/afp-codepage-missing.xconf b/test/config/afp-codepage-missing.xconf new file mode 100644 index 000000000..c44b1256e --- /dev/null +++ b/test/config/afp-codepage-missing.xconf @@ -0,0 +1,16 @@ + + + . + + + + + + + + + + + + + diff --git a/test/config/afp-font-missing.xconf b/test/config/afp-font-missing.xconf new file mode 100644 index 000000000..8eeb3557d --- /dev/null +++ b/test/config/afp-font-missing.xconf @@ -0,0 +1,13 @@ + + + . + + + + + + + + + + diff --git a/test/config/afp-invalid-characterset.xconf b/test/config/afp-invalid-characterset.xconf new file mode 100644 index 000000000..48147e726 --- /dev/null +++ b/test/config/afp-invalid-characterset.xconf @@ -0,0 +1,16 @@ + + + . + + + + + + + + + + + + + diff --git a/test/config/afp-invalid-config.xconf b/test/config/afp-invalid-config.xconf new file mode 100644 index 000000000..30eecbe6d --- /dev/null +++ b/test/config/afp-invalid-config.xconf @@ -0,0 +1,16 @@ + + + . + + + + + + + + + + + + + diff --git a/test/config/afp-invalid-file-name.xconf b/test/config/afp-invalid-file-name.xconf new file mode 100644 index 000000000..8cbafcac9 --- /dev/null +++ b/test/config/afp-invalid-file-name.xconf @@ -0,0 +1,16 @@ + + + . + + + + + + + + + + + + + diff --git a/test/config/afp-raster-font-missing.xconf b/test/config/afp-raster-font-missing.xconf new file mode 100644 index 000000000..cf6578d6a --- /dev/null +++ b/test/config/afp-raster-font-missing.xconf @@ -0,0 +1,15 @@ + + + . + + + + + + + + + + + + diff --git a/test/config/afp-triplet-missing.xconf b/test/config/afp-triplet-missing.xconf new file mode 100644 index 000000000..59ddd9689 --- /dev/null +++ b/test/config/afp-triplet-missing.xconf @@ -0,0 +1,15 @@ + + + . + + + + + + + + + + + + diff --git a/test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java b/test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java new file mode 100644 index 000000000..cd0faa39b --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java @@ -0,0 +1,79 @@ +/* + * 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.afp; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.transform.TransformerException; + +import org.junit.Test; +import org.xml.sax.SAXException; + +import org.apache.xmlgraphics.util.MimeConstants; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.events.EventProcessingTestCase; + +/** + * A test class for testing AFP events. + */ +public class AFPEventProcessingTestCase { + + private EventProcessingTestCase eventsTests = new EventProcessingTestCase(); + private static final String CONFIG_BASE_DIR = EventProcessingTestCase.CONFIG_BASE_DIR; + + private void testInvalidConfigEvent(String xconf, String eventId) + throws FOPException, TransformerException, IOException, SAXException { + InputStream inStream = getClass().getResourceAsStream("simple.fo"); + eventsTests.doTest(inStream, CONFIG_BASE_DIR + xconf, + AFPEventProducer.class.getName() + eventId, MimeConstants.MIME_AFP); + } + + @Test + public void testMissingFontConfigurationElement() throws FOPException, TransformerException, + IOException, SAXException { + testInvalidConfigEvent("afp-font-missing.xconf", ".fontConfigMissing"); + } + + @Test + public void testInvalidCharactersetName() throws FOPException, TransformerException, + IOException, SAXException { + testInvalidConfigEvent("afp-invalid-characterset.xconf", ".characterSetNameInvalid"); + } + + @Test + public void testinvalidConfig() throws FOPException, TransformerException, IOException, + SAXException { + testInvalidConfigEvent("afp-invalid-config.xconf", ".invalidConfiguration"); + } + + @Test + public void testRasterFontElementMissing() throws FOPException, TransformerException, + IOException, SAXException { + testInvalidConfigEvent("afp-raster-font-missing.xconf", ".fontConfigMissing"); + } + + @Test + public void testTripletElementMissing() throws FOPException, TransformerException, + IOException, SAXException { + testInvalidConfigEvent("afp-triplet-missing.xconf", ".fontConfigMissing"); + } +} diff --git a/test/java/org/apache/fop/afp/simple.fo b/test/java/org/apache/fop/afp/simple.fo new file mode 100644 index 000000000..760ff4b63 --- /dev/null +++ b/test/java/org/apache/fop/afp/simple.fo @@ -0,0 +1,14 @@ + + + + + + + + + + This is a simple document. + + + diff --git a/test/java/org/apache/fop/events/EventProcessingTestCase.java b/test/java/org/apache/fop/events/EventProcessingTestCase.java index eda016002..8219fa71e 100644 --- a/test/java/org/apache/fop/events/EventProcessingTestCase.java +++ b/test/java/org/apache/fop/events/EventProcessingTestCase.java @@ -60,7 +60,10 @@ public class EventProcessingTestCase { private static final String BASE_DIR = "test/events/"; - public void doTest(InputStream inStream, String fopConf, String expectedEventID) + /** The base directory of configuration files */ + public static final String CONFIG_BASE_DIR = "test/config/"; + + public void doTest(InputStream inStream, String fopConf, String expectedEventID, String mimeType) throws FOPException, TransformerException, IOException, SAXException { EventChecker eventChecker = new EventChecker(expectedEventID); if (fopConf != null) { @@ -68,7 +71,7 @@ public class EventProcessingTestCase { } FOUserAgent userAgent = fopFactory.newFOUserAgent(); userAgent.getEventBroadcaster().addEventListener(eventChecker); - Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, new NullOutputStream()); + Fop fop = fopFactory.newFop(mimeType, userAgent, new NullOutputStream()); Transformer transformer = tFactory.newTransformer(); Source src = new StreamSource(inStream); Result res = new SAXResult(fop.getDefaultHandler()); @@ -78,12 +81,8 @@ public class EventProcessingTestCase { public void doTest(String filename, String expectedEventID) throws FOPException, TransformerException, IOException, SAXException { - doTest(filename, null, expectedEventID); - } - - public void doTest(String filename, String fopConf, String expectedEventID) throws - FOPException, TransformerException, IOException, SAXException { - doTest(new FileInputStream(BASE_DIR + filename), fopConf, expectedEventID); + doTest(new FileInputStream(BASE_DIR + filename), null, expectedEventID, + MimeConstants.MIME_PDF); } @Test diff --git a/test/java/org/apache/fop/fonts/FontEventProcessingTestCase.java b/test/java/org/apache/fop/fonts/FontEventProcessingTestCase.java index b35f38877..898f83197 100644 --- a/test/java/org/apache/fop/fonts/FontEventProcessingTestCase.java +++ b/test/java/org/apache/fop/fonts/FontEventProcessingTestCase.java @@ -27,6 +27,8 @@ import javax.xml.transform.TransformerException; import org.junit.Test; import org.xml.sax.SAXException; +import org.apache.xmlgraphics.util.MimeConstants; + import org.apache.fop.apps.FOPException; import org.apache.fop.events.EventProcessingTestCase; @@ -37,17 +39,22 @@ public class FontEventProcessingTestCase { private EventProcessingTestCase eventsTests = new EventProcessingTestCase(); + private static final String CONFIG_BASE_DIR = EventProcessingTestCase.CONFIG_BASE_DIR; + @Test public void testFont() throws FOPException, TransformerException, IOException, SAXException { InputStream inStream = getClass().getResourceAsStream("substituted-font.fo"); - eventsTests.doTest(inStream, null, FontEventProducer.class.getName() + ".fontSubstituted"); + eventsTests.doTest(inStream, null, FontEventProducer.class.getName() + ".fontSubstituted", + MimeConstants.MIME_PDF); } @Test public void testFontWithBadDirectory() throws FOPException, TransformerException, IOException, SAXException { InputStream inStream = getClass().getResourceAsStream("substituted-font.fo"); - eventsTests.doTest(inStream, "test/config/test_fonts_directory_bad.xconf", - FontEventProducer.class.getName() + ".fontDirectoryNotFound"); + eventsTests.doTest(inStream, CONFIG_BASE_DIR + "test_fonts_directory_bad.xconf", + FontEventProducer.class.getName() + ".fontDirectoryNotFound", + MimeConstants.MIME_PDF); } + } -- cgit v1.2.3