diff options
Diffstat (limited to 'test/java')
109 files changed, 3567 insertions, 375 deletions
diff --git a/test/java/org/apache/fop/AbstractBasicTranscoderTestCase.java b/test/java/org/apache/fop/AbstractBasicTranscoderTest.java index e249a8a23..f046ee615 100644 --- a/test/java/org/apache/fop/AbstractBasicTranscoderTestCase.java +++ b/test/java/org/apache/fop/AbstractBasicTranscoderTest.java @@ -34,7 +34,7 @@ import org.junit.Test; * Basic runtime test for FOP's transcoders. It is used to verify that * nothing obvious is broken after compiling. */ -public abstract class AbstractBasicTranscoderTestCase extends AbstractFOPTestCase { +public abstract class AbstractBasicTranscoderTest extends AbstractFOPTest { /** * Creates the transcoder to test. diff --git a/test/java/org/apache/fop/AbstractFOPTestCase.java b/test/java/org/apache/fop/AbstractFOPTest.java index 58108a036..eac140d31 100644 --- a/test/java/org/apache/fop/AbstractFOPTestCase.java +++ b/test/java/org/apache/fop/AbstractFOPTest.java @@ -24,19 +24,14 @@ import java.io.File; /** * Abstract base test class for FOP's tests. */ -public abstract class AbstractFOPTestCase { +public abstract class AbstractFOPTest { /** * Returns the base directory to use for the tests. * @return the base directory */ protected static File getBaseDir() { - String basedir = System.getProperty("basedir"); - if (basedir != null) { - return new File(basedir); - } else { - return new File("."); - } + return new File("."); } } diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java index f02debd1d..2fc23edfd 100644 --- a/test/java/org/apache/fop/BasicDriverTestCase.java +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -42,7 +42,7 @@ import org.junit.Test; * Basic runtime test for the old Fop class. It is used to verify that * nothing obvious is broken after compiling. */ -public class BasicDriverTestCase extends AbstractFOPTestCase { +public class BasicDriverTestCase extends AbstractFOPTest { private FopFactory fopFactory = FopFactory.newInstance(); diff --git a/test/java/org/apache/fop/BasicPDFTranscoderTestCase.java b/test/java/org/apache/fop/BasicPDFTranscoderTestCase.java index 61fbdb5a4..de35db94e 100644 --- a/test/java/org/apache/fop/BasicPDFTranscoderTestCase.java +++ b/test/java/org/apache/fop/BasicPDFTranscoderTestCase.java @@ -26,7 +26,7 @@ import org.apache.fop.svg.PDFTranscoder; * Basic runtime test for the PDF transcoder. It is used to verify that * nothing obvious is broken after compiling. */ -public class BasicPDFTranscoderTestCase extends AbstractBasicTranscoderTestCase { +public class BasicPDFTranscoderTestCase extends AbstractBasicTranscoderTest { @Override protected Transcoder createTranscoder() { diff --git a/test/java/org/apache/fop/BasicPSTranscoderTestCase.java b/test/java/org/apache/fop/BasicPSTranscoderTestCase.java index 40429a44f..f2f233a5a 100644 --- a/test/java/org/apache/fop/BasicPSTranscoderTestCase.java +++ b/test/java/org/apache/fop/BasicPSTranscoderTestCase.java @@ -26,7 +26,7 @@ import org.apache.fop.render.ps.PSTranscoder; * Basic runtime test for the PS transcoder. It is used to verify that * nothing obvious is broken after compiling. */ -public class BasicPSTranscoderTestCase extends AbstractBasicTranscoderTestCase { +public class BasicPSTranscoderTestCase extends AbstractBasicTranscoderTest { @Override protected Transcoder createTranscoder() { diff --git a/test/java/org/apache/fop/GenericFOPTestCase.java b/test/java/org/apache/fop/GenericFOPTestCase.java deleted file mode 100644 index 26fa296a7..000000000 --- a/test/java/org/apache/fop/GenericFOPTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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; -import static org.junit.Assert.fail; - -import java.io.ByteArrayOutputStream; -import java.io.StringReader; -import java.security.DigestOutputStream; -import java.security.MessageDigest; -import java.util.Date; - -import javax.xml.parsers.SAXParserFactory; - -import org.junit.Before; -import org.junit.Test; -import org.xml.sax.InputSource; - -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.apps.Fop; -import org.apache.fop.apps.FopFactory; -import org.apache.fop.apps.MimeConstants; -import org.apache.fop.util.DigestFilter; - -/** - * Framework for simple regression testing. - * The testcase reads a control XML file which specifies a FO source, - * a MD5 for the source to help diferentiating failures caused by causal - * source modification from failures caused by regression, a renderer (only - * PDF currently supported) and a MD5 for the result. - * - */ -public final class GenericFOPTestCase { - - // configure fopFactory as desired - private FopFactory fopFactory = FopFactory.newInstance(); - - private SAXParserFactory parserFactory; - - @Before - public void setUp() throws Exception { - parserFactory = SAXParserFactory.newInstance(); - parserFactory.setNamespaceAware(true); - } - - @org.junit.Test - public void testSimple() throws Exception { - final String digestIn = "17bf13298796065f7775db8707133aeb"; - final String digestOut = "e2761f51152f6663911e567901596707"; - final String fo - = "<fo:root xmlns:fo='http://www.w3.org/1999/XSL/Format'>" - + " <fo:layout-master-set>" - + " <fo:simple-page-master master-name='simple'" - + " page-height='25cm' page-width='20cm'>" - + " <fo:region-body/>" - + " </fo:simple-page-master>" - + " </fo:layout-master-set>" - + " <fo:page-sequence master-reference='simple'>" - + " <fo:flow flow-name='xsl-region-body'>" - + " <fo:block>This is a blind text.</fo:block>" - + " </fo:flow>" - + " </fo:page-sequence>" - + "</fo:root>"; - renderPDF(fo, digestIn, digestOut); - } - - private String digestToString(byte[] value) { - StringBuffer buffer = new StringBuffer(2 * value.length); - for (int i = 0; i < value.length; i++) { - int val = value[i]; - int hi = (val >> 4) & 0xF; - int lo = val & 0xF; - if (hi < 10) { - buffer.append((char) (hi + 0x30)); - } else { - buffer.append((char) (hi + 0x61 - 10)); - } - if (lo < 10) { - buffer.append((char) (lo + 0x30)); - } else { - buffer.append((char) (lo + 0x61 - 10)); - } - } - return buffer.toString(); - } - - private void renderPDF(String fo, String digestIn, String digestOut) - throws Exception { - FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); - foUserAgent.setCreationDate(new Date(10000)); - MessageDigest outDigest = MessageDigest.getInstance("MD5"); - DigestOutputStream out = new DigestOutputStream(new ByteArrayOutputStream(), outDigest); - Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); - InputSource source = new InputSource(new StringReader(fo)); - DigestFilter filter = new DigestFilter("MD5"); - filter.setParent(parserFactory.newSAXParser().getXMLReader()); - filter.setContentHandler(fop.getDefaultHandler()); - filter.parse(source); - String digestInActual = digestToString(filter.getDigestValue()); - if (!digestIn.equals(digestInActual)) { - fail("input MD5: was " + digestInActual + ", expected " + digestIn); - } - String digestOutActual = digestToString(outDigest.digest()); - if (!digestOut.equals(digestOutActual)) { - fail( - "output MD5: was " - + digestOutActual - + ", expected " - + digestOut); - } - } - -} diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index 840b04917..808542306 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -23,16 +23,19 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.apache.fop.afp.fonts.CharactersetEncoderTest; +import org.apache.fop.afp.fonts.CharactersetEncoderTestCase; import org.apache.fop.afp.parser.MODCAParserTestCase; import org.apache.fop.area.ViewportTestSuite; -import org.apache.fop.fonts.DejaVuLGCSerifTest; +import org.apache.fop.fonts.DejaVuLGCSerifTestCase; +import org.apache.fop.fonts.FontEventProcessingTestCase; import org.apache.fop.fonts.truetype.GlyfTableTestCase; +import org.apache.fop.fonts.type1.AFMParserTestCase; +import org.apache.fop.fonts.type1.AdobeStandardEncodingTestCase; import org.apache.fop.image.loader.batik.ImageLoaderTestCase; import org.apache.fop.image.loader.batik.ImagePreloaderTestCase; import org.apache.fop.intermediate.IFMimickingTestCase; -import org.apache.fop.render.extensions.prepress.PageBoundariesTest; -import org.apache.fop.render.extensions.prepress.PageScaleTest; +import org.apache.fop.render.extensions.prepress.PageBoundariesTestCase; +import org.apache.fop.render.extensions.prepress.PageScaleTestCase; import org.apache.fop.render.pdf.PDFAConformanceTestCase; import org.apache.fop.render.pdf.PDFCMapTestCase; import org.apache.fop.render.pdf.PDFEncodingTestCase; @@ -40,36 +43,41 @@ import org.apache.fop.render.pdf.PDFsRGBSettingsTestCase; import org.apache.fop.render.pdf.RenderPDFTestSuite; import org.apache.fop.render.ps.PSTestSuite; import org.apache.fop.render.rtf.RichTextFormatTestSuite; -import org.apache.fop.traits.MinOptMaxTest; +import org.apache.fop.traits.MinOptMaxTestCase; +import org.apache.fop.pdf.PDFLibraryTestSuite; /** * Test suite for basic functionality of FOP. */ @RunWith(Suite.class) @SuiteClasses({ - BasicDriverTestSuite.class, - UtilityCodeTestSuite.class, - PDFAConformanceTestCase.class, - PDFEncodingTestCase.class, - PDFCMapTestCase.class, - PDFsRGBSettingsTestCase.class, - DejaVuLGCSerifTest.class, - RichTextFormatTestSuite.class, - ImageLoaderTestCase.class, - ImagePreloaderTestCase.class, - IFMimickingTestCase.class, - PageBoundariesTest.class, - PageScaleTest.class, - org.apache.fop.afp.AFPTestSuite.class, - GlyfTableTestCase.class, - ViewportTestSuite.class, - RenderPDFTestSuite.class, - MODCAParserTestCase.class, - CharactersetEncoderTest.class, - org.apache.fop.render.afp.AFPTestSuite.class, - PSTestSuite.class, - MinOptMaxTest.class, - org.apache.fop.render.intermediate.IFStructureTreeBuilderTestCase.class + BasicDriverTestSuite.class, + UtilityCodeTestSuite.class, + PDFAConformanceTestCase.class, + PDFEncodingTestCase.class, + PDFCMapTestCase.class, + PDFsRGBSettingsTestCase.class, + DejaVuLGCSerifTestCase.class, + RichTextFormatTestSuite.class, + ImageLoaderTestCase.class, + ImagePreloaderTestCase.class, + IFMimickingTestCase.class, + PageBoundariesTestCase.class, + PageScaleTestCase.class, + org.apache.fop.afp.AFPTestSuite.class, + GlyfTableTestCase.class, + ViewportTestSuite.class, + RenderPDFTestSuite.class, + MODCAParserTestCase.class, + CharactersetEncoderTestCase.class, + org.apache.fop.render.afp.AFPTestSuite.class, + PDFLibraryTestSuite.class, + PSTestSuite.class, + MinOptMaxTestCase.class, + AdobeStandardEncodingTestCase.class, + AFMParserTestCase.class, + FontEventProcessingTestCase.class, + org.apache.fop.render.intermediate.IFStructureTreeBuilderTestCase.class }) public class StandardTestSuite { } diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index 16968e1b7..490486158 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.java @@ -39,24 +39,26 @@ import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.Document; + import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.xpath.XPathAPI; +import org.apache.xpath.objects.XObject; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; import org.apache.fop.render.xml.XMLRenderer; -import org.apache.xpath.XPathAPI; -import org.apache.xpath.objects.XObject; -import org.junit.BeforeClass; -import org.junit.Test; -import org.w3c.dom.Document; /** * Tests URI resolution facilities. */ -public class URIResolutionTestCase extends AbstractFOPTestCase { +public class URIResolutionTestCase extends AbstractFOPTest { // configure fopFactory as desired private FopFactory fopFactory = FopFactory.newInstance(); @@ -160,8 +162,7 @@ public class URIResolutionTestCase extends AbstractFOPTestCase { TransformerHandler athandler = tfactory.newTransformerHandler(); athandler.setResult(domres); - XMLRenderer atrenderer = new XMLRenderer(); - atrenderer.setUserAgent(ua); + XMLRenderer atrenderer = new XMLRenderer(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); diff --git a/test/java/org/apache/fop/UtilityCodeTestSuite.java b/test/java/org/apache/fop/UtilityCodeTestSuite.java index 442d63f5b..cf6b8875d 100644 --- a/test/java/org/apache/fop/UtilityCodeTestSuite.java +++ b/test/java/org/apache/fop/UtilityCodeTestSuite.java @@ -28,12 +28,10 @@ import org.apache.fop.pdf.FileIDGeneratorTestCase; import org.apache.fop.pdf.PDFDocumentGraphics2DTestCase; import org.apache.fop.pdf.PDFEncryptionJCETestCase; import org.apache.fop.pdf.PDFFactoryTestCase; -import org.apache.fop.pdf.PDFObjectTestCase; import org.apache.fop.traits.BorderPropsTestCase; import org.apache.fop.util.BitmapImageUtilTestCase; import org.apache.fop.util.ColorUtilTestCase; import org.apache.fop.util.ElementListUtilsTestCase; -import org.apache.fop.util.PDFNumberTestCase; import org.apache.fop.util.XMLResourceBundleTestCase; /** @@ -41,8 +39,6 @@ import org.apache.fop.util.XMLResourceBundleTestCase; */ @RunWith(Suite.class) @SuiteClasses({ - PDFNumberTestCase.class, - PDFObjectTestCase.class, ColorUtilTestCase.class, BorderPropsTestCase.class, ElementListUtilsTestCase.class, 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/AFPObjectAreaInfoTestCase.java b/test/java/org/apache/fop/afp/AFPObjectAreaInfoTestCase.java new file mode 100644 index 000000000..fc5f1825c --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPObjectAreaInfoTestCase.java @@ -0,0 +1,76 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for {@link AFPObjectAreaInfo}. + */ +public class AFPObjectAreaInfoTestCase { + + private AFPObjectAreaInfo sut; + + /** + * Instantiate the system under test + */ + @Before + public void setUp() { + sut = new AFPObjectAreaInfo(1, 2, 3, 4, 5, 6); + } + + /** + * Test the getter functions with arbitrary data. + */ + @Test + public void testGetters() { + assertEquals(1, sut.getX()); + assertEquals(2, sut.getY()); + assertEquals(3, sut.getWidth()); + assertEquals(4, sut.getHeight()); + assertEquals(5, sut.getWidthRes()); + assertEquals(5, sut.getHeightRes()); + assertEquals(6, sut.getRotation()); + } + + /** + * Test the resolution setters with arbitrary data. + */ + @Test + public void testSetters() { + assertEquals(5, sut.getWidthRes()); + assertEquals(5, sut.getHeightRes()); + + sut.setResolution(20); + assertEquals(20, sut.getWidthRes()); + assertEquals(20, sut.getHeightRes()); + + sut.setHeightRes(10); + assertEquals(20, sut.getWidthRes()); + assertEquals(10, sut.getHeightRes()); + + sut.setWidthRes(9); + assertEquals(9, sut.getWidthRes()); + assertEquals(10, sut.getHeightRes()); + } +} diff --git a/test/java/org/apache/fop/afp/AFPPaintingStateTestCase.java b/test/java/org/apache/fop/afp/AFPPaintingStateTestCase.java new file mode 100644 index 000000000..47c93064c --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPPaintingStateTestCase.java @@ -0,0 +1,61 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for {@link AFPPaintingState}. + */ +public class AFPPaintingStateTestCase { + private AFPPaintingState sut; + + /** + * Set up the system under test + */ + @Before + public void setUp() { + sut = new AFPPaintingState(); + } + + /** + * Test {get,set}BitmapEncodingQuality() + */ + @Test + public void testGetSetBitmapEncodingQuality() { + sut.setBitmapEncodingQuality(0.5f); + assertEquals(0.5f, sut.getBitmapEncodingQuality(), 0.01f); + + sut.setBitmapEncodingQuality(0.9f); + assertEquals(0.9f, sut.getBitmapEncodingQuality(), 0.01f); + } + + /** + * Test {,set}CanEmbedJpeg + */ + public void testGetSetCanEmbedJpeg() { + assertEquals(false, sut.canEmbedJpeg()); + sut.setCanEmbedJpeg(true); + assertEquals(true, sut.canEmbedJpeg()); + } +} diff --git a/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java b/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java new file mode 100644 index 000000000..c9ea9a5f4 --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java @@ -0,0 +1,89 @@ +/* + * 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 static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import org.apache.xmlgraphics.util.MimeConstants; + +/** + * Test case for {@link AFPResourceManager}. + */ +public class AFPResourceManagerTestCase { + + private AFPResourceManager sut; + + @Before + public void setUp() throws IOException { + sut = new AFPResourceManager(); + AFPPaintingState paintingState = new AFPPaintingState(); + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + DataStream stream = sut.createDataStream(paintingState, outStream); + stream.startPage(0, 0, 0, 10, 10); + } + + /** + * Ensures that if tryIncludeObject() is called with a new object, it returns false suggesting + * that we have to create said object. However, if it is called with an object that has already + * been created, it returns true suggesting that we don't have to create that object again. + * Page-segment is false. + * + * @throws IOException if an I/O error occurs + */ + @Test + public void testTryIncludeObjectWithPageSegFalse() throws IOException { + AFPDataObjectInfo dataInfo = createAFPDataObjectInfo(); + // An empty object needs to be created every time! + assertFalse(sut.tryIncludeObject(dataInfo)); + sut.createObject(dataInfo); + assertTrue(sut.tryIncludeObject(dataInfo)); + } + + /** + * {@code testTryIncludeObjectWithPageSegFalse()} but with page-segment true. + * + * @throws IOException if an I/O error occurs + */ + @Test + public void testTryIncludeObjectWithPageSegTrue() throws IOException { + AFPDataObjectInfo dataInfo = createAFPDataObjectInfo(); + dataInfo.setCreatePageSegment(true); + // An empty object needs to be created every time! + assertFalse(sut.tryIncludeObject(dataInfo)); + sut.createObject(dataInfo); + assertTrue(sut.tryIncludeObject(dataInfo)); + } + + private AFPDataObjectInfo createAFPDataObjectInfo() { + AFPDataObjectInfo dataInfo = new AFPDataObjectInfo(); + dataInfo.setMimeType(MimeConstants.MIME_TIFF); + dataInfo.setData(new byte[1]); + AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo(0, 0, 10, 10, 1, 0); + dataInfo.setObjectAreaInfo(objectAreaInfo); + return dataInfo; + } +} diff --git a/test/java/org/apache/fop/afp/AFPTestSuite.java b/test/java/org/apache/fop/afp/AFPTestSuite.java index 8fa3e819d..32d61cb35 100644 --- a/test/java/org/apache/fop/afp/AFPTestSuite.java +++ b/test/java/org/apache/fop/afp/AFPTestSuite.java @@ -19,18 +19,21 @@ package org.apache.fop.afp; -import org.apache.fop.afp.modca.IncludeObjectTestCase; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; +import org.apache.fop.afp.modca.IncludeObjectTestCase; + /** * Test suite for FOP's AFP classes. */ @RunWith(Suite.class) @SuiteClasses({ - IncludeObjectTestCase.class, - AFPResourceUtilTestCase.class + IncludeObjectTestCase.class, + AFPResourceUtilTestCase.class, + AFPObjectAreaInfoTestCase.class, + AFPPaintingStateTestCase.class }) public class AFPTestSuite { } diff --git a/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTest.java b/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTestCase.java index 3b5c945d8..dd776e41c 100644 --- a/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTest.java +++ b/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTestCase.java @@ -33,7 +33,7 @@ import org.junit.Test; /** * Test {@link CharactersetEncoder} */ -public class CharactersetEncoderTest { +public class CharactersetEncoderTestCase { private CharactersetEncoder singlebyteEncoder; private CharactersetEncoder doublebyteEncoder; diff --git a/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java b/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java new file mode 100644 index 000000000..b77ef6e12 --- /dev/null +++ b/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java @@ -0,0 +1,72 @@ +/* + * 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. + */ +package org.apache.fop.afp.goca; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.apache.fop.afp.fonts.CharacterSet; +import org.apache.fop.afp.fonts.CharacterSetBuilder; +import org.apache.fop.fonts.Typeface; +import org.junit.Before; +import org.junit.Test; + +public class GraphicsCharacterStringTestCase { + private GraphicsCharacterString gcsCp500; + private GraphicsCharacterString gcsCp1146; + // consider the EBCDIC code page variants Cp500 and Cp1146 + // the <A3> (pound sign) corresponds to byte 5B (position 91) in the CCSID 285 and CCSID 1146 + // the $ corresponds to byte 5B (position 91) in the CCSID 500 + private final String poundsText = "\u00A3\u00A3\u00A3\u00A3"; + private final String dollarsText = "$$$$"; + private final byte[] bytesToCheck = {(byte) 0x5b, (byte) 0x5b, (byte) 0x5b, (byte) 0x5b}; + + @Before + public void setUp() throws Exception { + CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance(); + CharacterSet cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146", + Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class) + .newInstance(), null); + gcsCp1146 = new GraphicsCharacterString(poundsText, 0, 0, cs1146); + CharacterSet cs500 = csb.build("C0H200B0", "T1V10500", "Cp500", + Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class) + .newInstance(), null); + gcsCp500 = new GraphicsCharacterString(dollarsText, 0, 0, cs500); + } + + @Test + public void testWriteToStream() throws IOException { + // check pounds + ByteArrayOutputStream baos1146 = new ByteArrayOutputStream(); + gcsCp1146.writeToStream(baos1146); + byte[] bytes1146 = baos1146.toByteArray(); + for (int i = 0; i < bytesToCheck.length; i++) { + assertEquals(bytesToCheck[i], bytes1146[6 + i]); + } + assertEquals(bytesToCheck.length + 6, bytes1146.length); + // check dollars + ByteArrayOutputStream baos500 = new ByteArrayOutputStream(); + gcsCp500.writeToStream(baos500); + byte[] bytes500 = baos500.toByteArray(); + for (int i = 0; i < bytesToCheck.length; i++) { + assertEquals(bytesToCheck[i], bytes500[6 + i]); + } + assertEquals(bytesToCheck.length + 6, bytes500.length); + } +} diff --git a/test/java/org/apache/fop/afp/modca/AbstractAFPObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractAFPObjectTest.java index b987a13f7..451616ad9 100644 --- a/test/java/org/apache/fop/afp/modca/AbstractAFPObjectTestCase.java +++ b/test/java/org/apache/fop/afp/modca/AbstractAFPObjectTest.java @@ -36,7 +36,7 @@ import org.junit.Test; /** * Tests the {@link AbstractAFPObject} class. */ -public abstract class AbstractAFPObjectTestCase<S extends AbstractAFPObject> { +public abstract class AbstractAFPObjectTest<S extends AbstractAFPObject> { private S sut; diff --git a/test/java/org/apache/fop/afp/modca/AbstractNamedAFPObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractNamedAFPObjectTest.java index 4b03b87d8..5c863b6e4 100644 --- a/test/java/org/apache/fop/afp/modca/AbstractNamedAFPObjectTestCase.java +++ b/test/java/org/apache/fop/afp/modca/AbstractNamedAFPObjectTest.java @@ -28,8 +28,8 @@ import org.junit.Test; /** * Tests the {@linkplain AbstractAFPObject} class. */ -public abstract class AbstractNamedAFPObjectTestCase<S extends AbstractNamedAFPObject> - extends AbstractAFPObjectTestCase<S> { +public abstract class AbstractNamedAFPObjectTest<S extends AbstractNamedAFPObject> + extends AbstractAFPObjectTest<S> { @Test public void testCopySF() { diff --git a/test/java/org/apache/fop/afp/modca/AbstractStructuredObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractStructuredObjectTest.java index e5bf70c7a..faef0a4f6 100644 --- a/test/java/org/apache/fop/afp/modca/AbstractStructuredObjectTestCase.java +++ b/test/java/org/apache/fop/afp/modca/AbstractStructuredObjectTest.java @@ -21,7 +21,7 @@ package org.apache.fop.afp.modca; import java.io.IOException; -public abstract class AbstractStructuredObjectTestCase<S extends AbstractStructuredObject> extends AbstractAFPObjectTestCase<S> { +public abstract class AbstractStructuredObjectTest<S extends AbstractStructuredObject> extends AbstractAFPObjectTest<S> { /** * Test writeStart() - test that the contract is maintained with diff --git a/test/java/org/apache/fop/afp/modca/AbstractTripletStructuredObjectTestCase.java b/test/java/org/apache/fop/afp/modca/AbstractTripletStructuredObjectTest.java index f43eb0646..10c154550 100644 --- a/test/java/org/apache/fop/afp/modca/AbstractTripletStructuredObjectTestCase.java +++ b/test/java/org/apache/fop/afp/modca/AbstractTripletStructuredObjectTest.java @@ -30,18 +30,20 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.junit.Before; +import org.junit.Test; + import org.apache.fop.afp.modca.triplets.AbstractTriplet; import org.apache.fop.afp.modca.triplets.AttributeQualifierTriplet; import org.apache.fop.afp.modca.triplets.CommentTriplet; import org.apache.fop.afp.modca.triplets.ObjectAreaSizeTriplet; import org.apache.fop.afp.modca.triplets.Triplet; -import org.junit.Before; /** * Test {@link AbstractTripletStructuredObject} */ -public abstract class AbstractTripletStructuredObjectTestCase<S extends AbstractTripletStructuredObject> - extends AbstractStructuredObjectTestCase<AbstractTripletStructuredObject> { +public class AbstractTripletStructuredObjectTest<S extends AbstractTripletStructuredObject> + extends AbstractStructuredObjectTest<AbstractTripletStructuredObject> { private static final List<AbstractTriplet> TRIPLETS; @@ -136,6 +138,7 @@ public abstract class AbstractTripletStructuredObjectTestCase<S extends Abstract /** * Test addTriplets() - ensure all triplets are added. */ + @Test public void testAddTriplets() { // Tested on empty object List<AbstractTriplet> expectedList = TRIPLETS; @@ -154,4 +157,4 @@ public abstract class AbstractTripletStructuredObjectTestCase<S extends Abstract emptyStructuredObject.addTriplets(null); } -}
\ No newline at end of file +} diff --git a/test/java/org/apache/fop/afp/modca/IncludeObjectTestCase.java b/test/java/org/apache/fop/afp/modca/IncludeObjectTestCase.java index 32bad5248..fb5097154 100644 --- a/test/java/org/apache/fop/afp/modca/IncludeObjectTestCase.java +++ b/test/java/org/apache/fop/afp/modca/IncludeObjectTestCase.java @@ -32,7 +32,7 @@ import org.junit.Test; /** * Test {@link IncludeObject} */ -public class IncludeObjectTestCase extends AbstractNamedAFPObjectTestCase<IncludeObject> { +public class IncludeObjectTestCase extends AbstractNamedAFPObjectTest<IncludeObject> { @Before public void setUp() throws Exception { 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 @@ +<?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 is a simple document.</fo:block> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/java/org/apache/fop/area/BlockViewportTestCase.java b/test/java/org/apache/fop/area/BlockViewportTestCase.java index 8cca4b244..f825fdda5 100644 --- a/test/java/org/apache/fop/area/BlockViewportTestCase.java +++ b/test/java/org/apache/fop/area/BlockViewportTestCase.java @@ -24,7 +24,7 @@ import org.junit.Test; /** * Tests the {@linkplain BlockViewport} class. */ -public class BlockViewportTestCase extends ViewportTestCase { +public class BlockViewportTestCase extends ViewportTest { @Test public void testNonClip() throws Exception { diff --git a/test/java/org/apache/fop/area/RegionViewportTestCase.java b/test/java/org/apache/fop/area/RegionViewportTestCase.java index e6cd8fe36..638126efb 100644 --- a/test/java/org/apache/fop/area/RegionViewportTestCase.java +++ b/test/java/org/apache/fop/area/RegionViewportTestCase.java @@ -27,7 +27,7 @@ import org.junit.Test; /** * Tests the {@linkplain RegionViewport} class. */ -public class RegionViewportTestCase extends ViewportTestCase { +public class RegionViewportTestCase extends ViewportTest { private RegionViewport createRegionViewport(int x, int y, int ipd, int bpd) { Rectangle2D v = new Rectangle(x, y, ipd, bpd); diff --git a/test/java/org/apache/fop/area/ViewportTestCase.java b/test/java/org/apache/fop/area/ViewportTest.java index d09b327b9..cb2282071 100644 --- a/test/java/org/apache/fop/area/ViewportTestCase.java +++ b/test/java/org/apache/fop/area/ViewportTest.java @@ -29,7 +29,7 @@ import java.awt.Rectangle; /** * Tests implementations of the {@linkplain Viewport} interface. */ -public abstract class ViewportTestCase { +public abstract class ViewportTest { protected void checkNonClip(Viewport v) throws Exception { assertFalse(v.hasClip()); diff --git a/test/java/org/apache/fop/area/inline/InlineViewportTestCase.java b/test/java/org/apache/fop/area/inline/InlineViewportTestCase.java index d6d6c395e..edcf99d14 100644 --- a/test/java/org/apache/fop/area/inline/InlineViewportTestCase.java +++ b/test/java/org/apache/fop/area/inline/InlineViewportTestCase.java @@ -19,13 +19,13 @@ package org.apache.fop.area.inline; -import org.apache.fop.area.ViewportTestCase; +import org.apache.fop.area.ViewportTest; import org.junit.Test; /** * Tests the {@linkplain InlineViewport} class. */ -public class InlineViewportTestCase extends ViewportTestCase { +public class InlineViewportTestCase extends ViewportTest { @Test public void testNonClip() throws Exception { diff --git a/test/java/org/apache/fop/config/BaseConstructiveUserConfigTestCase.java b/test/java/org/apache/fop/config/BaseConstructiveUserConfigTest.java index 3583729e9..fbcd9a441 100644 --- a/test/java/org/apache/fop/config/BaseConstructiveUserConfigTestCase.java +++ b/test/java/org/apache/fop/config/BaseConstructiveUserConfigTest.java @@ -26,7 +26,7 @@ import org.junit.Test; /** * Super class of several user config cases. */ -public abstract class BaseConstructiveUserConfigTestCase extends BaseUserConfigTestCase { +public abstract class BaseConstructiveUserConfigTest extends BaseUserConfigTest { /** * Test using a standard FOP font diff --git a/test/java/org/apache/fop/config/BaseDestructiveUserConfigTestCase.java b/test/java/org/apache/fop/config/BaseDestructiveUserConfigTest.java index 2ea259e78..eb8d202c3 100644 --- a/test/java/org/apache/fop/config/BaseDestructiveUserConfigTestCase.java +++ b/test/java/org/apache/fop/config/BaseDestructiveUserConfigTest.java @@ -27,7 +27,7 @@ import org.junit.Test; /** * Super class for several user configuration failure cases. */ -public abstract class BaseDestructiveUserConfigTestCase extends BaseUserConfigTestCase { +public abstract class BaseDestructiveUserConfigTest extends BaseUserConfigTest { /** * Test the user configuration failure. diff --git a/test/java/org/apache/fop/config/BaseUserConfigTestCase.java b/test/java/org/apache/fop/config/BaseUserConfigTest.java index ad884782d..645aea536 100644 --- a/test/java/org/apache/fop/config/BaseUserConfigTestCase.java +++ b/test/java/org/apache/fop/config/BaseUserConfigTest.java @@ -29,23 +29,23 @@ import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.render.pdf.BasePDFTestCase; +import org.apache.fop.render.pdf.BasePDFTest; import org.xml.sax.SAXException; /** * Basic runtime test for FOP's font configuration. It is used to verify that * nothing obvious is broken after compiling. */ -public abstract class BaseUserConfigTestCase extends BasePDFTestCase { +public abstract class BaseUserConfigTest extends BasePDFTest { protected DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); /** logging instance */ - protected Log log = LogFactory.getLog(BaseUserConfigTestCase.class); + protected Log log = LogFactory.getLog(BaseUserConfigTest.class); /** - * @see org.apache.fop.render.pdf.BasePDFTestCase#init() + * @see org.apache.fop.render.pdf.BasePDFTest#init() */ protected void init() { // do nothing diff --git a/test/java/org/apache/fop/config/FontAttributesMissingTestCase.java b/test/java/org/apache/fop/config/FontAttributesMissingTestCase.java index fe14a9928..7e17291d6 100644 --- a/test/java/org/apache/fop/config/FontAttributesMissingTestCase.java +++ b/test/java/org/apache/fop/config/FontAttributesMissingTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * this font is without a metrics-url or an embed-url */ -public class FontAttributesMissingTestCase extends BaseDestructiveUserConfigTestCase { +public class FontAttributesMissingTestCase extends BaseDestructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontBaseBadTestCase.java b/test/java/org/apache/fop/config/FontBaseBadTestCase.java index bffda3055..eb49ca9fe 100644 --- a/test/java/org/apache/fop/config/FontBaseBadTestCase.java +++ b/test/java/org/apache/fop/config/FontBaseBadTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * This font base does not exist and a relative font path is used. */ -public class FontBaseBadTestCase extends BaseDestructiveUserConfigTestCase { +public class FontBaseBadTestCase extends BaseDestructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java b/test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java index 1640024fb..9e341f8b4 100644 --- a/test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java +++ b/test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * this font has an embed-url that does not exist on filesystem. */ -public class FontEmbedUrlBadTestCase extends BaseDestructiveUserConfigTestCase { +public class FontEmbedUrlBadTestCase extends BaseDestructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java b/test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java index b45df16bc..e3f0a6a88 100644 --- a/test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java +++ b/test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * this font has a malformed embed-url */ -public class FontEmbedUrlMalformedTestCase extends BaseDestructiveUserConfigTestCase { +public class FontEmbedUrlMalformedTestCase extends BaseDestructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java b/test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java index c22cd3eb2..352d43920 100644 --- a/test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java +++ b/test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * this font has a metrics-url that does not exist on filesystem */ -public class FontMetricsUrlBadTestCase extends BaseDestructiveUserConfigTestCase { +public class FontMetricsUrlBadTestCase extends BaseDestructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java b/test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java index 27853adf9..ddf3ee8a6 100644 --- a/test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java +++ b/test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * this font has a malformed metrics-url */ -public class FontMetricsUrlMalformedTestCase extends BaseDestructiveUserConfigTestCase { +public class FontMetricsUrlMalformedTestCase extends BaseDestructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontTripletAttributeMissingTestCase.java b/test/java/org/apache/fop/config/FontTripletAttributeMissingTestCase.java index 186dd85df..8aa2acb81 100644 --- a/test/java/org/apache/fop/config/FontTripletAttributeMissingTestCase.java +++ b/test/java/org/apache/fop/config/FontTripletAttributeMissingTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * this font has a missing font triplet attribute */ -public class FontTripletAttributeMissingTestCase extends BaseDestructiveUserConfigTestCase { +public class FontTripletAttributeMissingTestCase extends BaseDestructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontsAutoDetectTestCase.java b/test/java/org/apache/fop/config/FontsAutoDetectTestCase.java index c435a08cf..cf9d19f99 100644 --- a/test/java/org/apache/fop/config/FontsAutoDetectTestCase.java +++ b/test/java/org/apache/fop/config/FontsAutoDetectTestCase.java @@ -19,7 +19,7 @@ package org.apache.fop.config; -public class FontsAutoDetectTestCase extends BaseConstructiveUserConfigTestCase { +public class FontsAutoDetectTestCase extends BaseConstructiveUserConfigTest { @Override public String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java b/test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java index 7eec1cab6..3817e7966 100644 --- a/test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java +++ b/test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java @@ -22,7 +22,7 @@ package org.apache.fop.config; /** * tests font directory on system */ -public class FontsDirectoryRecursiveTestCase extends BaseConstructiveUserConfigTestCase { +public class FontsDirectoryRecursiveTestCase extends BaseConstructiveUserConfigTest { @Override protected String getUserConfigFilename() { diff --git a/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java b/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java index 7ae576e9b..0918d5867 100644 --- a/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java +++ b/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java @@ -36,7 +36,7 @@ import org.apache.fop.render.PrintRenderer; * Tests the font substitution mechanism */ public class FontsSubstitutionTestCase extends - BaseConstructiveUserConfigTestCase { + BaseConstructiveUserConfigTest { @Override protected byte[] convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile) diff --git a/test/java/org/apache/fop/config/UserConfigTestSuite.java b/test/java/org/apache/fop/config/UserConfigTestSuite.java index d90efe37b..374d41fab 100644 --- a/test/java/org/apache/fop/config/UserConfigTestSuite.java +++ b/test/java/org/apache/fop/config/UserConfigTestSuite.java @@ -34,7 +34,6 @@ import org.junit.runners.Suite.SuiteClasses; FontMetricsUrlBadTestCase.class, FontEmbedUrlBadTestCase.class, FontMetricsUrlMalformedTestCase.class, - FontMetricsUrlMalformedTestCase.class, FontsDirectoryRecursiveTestCase.class, FontsAutoDetectTestCase.class, FontsSubstitutionTestCase.class, diff --git a/test/java/org/apache/fop/events/EventChecker.java b/test/java/org/apache/fop/events/EventChecker.java index 85193c01b..dac67a8cc 100644 --- a/test/java/org/apache/fop/events/EventChecker.java +++ b/test/java/org/apache/fop/events/EventChecker.java @@ -36,11 +36,9 @@ class EventChecker implements EventListener { 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)) { + String id = event.getEventID(); + if (id.equals(expectedEventID)) { eventReceived = true; - } else { - fail("Unexpected event: id = " + event.getEventID() + ": " + msg); } } diff --git a/test/java/org/apache/fop/events/EventProcessingTestCase.java b/test/java/org/apache/fop/events/EventProcessingTestCase.java index 9660e5b79..8219fa71e 100644 --- a/test/java/org/apache/fop/events/EventProcessingTestCase.java +++ b/test/java/org/apache/fop/events/EventProcessingTestCase.java @@ -19,7 +19,9 @@ package org.apache.fop.events; -import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import javax.xml.transform.Result; import javax.xml.transform.Source; @@ -29,19 +31,23 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.stream.StreamSource; +import org.junit.Test; +import org.xml.sax.SAXException; + import org.apache.commons.io.output.NullOutputStream; + +import org.apache.xmlgraphics.util.MimeConstants; + import org.apache.fop.ResourceEventProducer; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; 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.fonts.FontEventProducer; import org.apache.fop.layoutmgr.BlockLevelEventProducer; import org.apache.fop.layoutmgr.inline.InlineLevelEventProducer; -import org.apache.xmlgraphics.util.MimeConstants; -import org.junit.Test; /** * Tests that the event notification system runs smoothly. @@ -52,68 +58,70 @@ public class EventProcessingTestCase { private final TransformerFactory tFactory = TransformerFactory.newInstance(); - private final File basedir; + private static final String BASE_DIR = "test/events/"; - public EventProcessingTestCase() { - String base = System.getProperty("basedir"); - if (base != null) { - basedir = new File(base); - } else { - basedir = new File("."); - } - } + /** The base directory of configuration files */ + public static final String CONFIG_BASE_DIR = "test/config/"; - private void doTest(String filename, String expectedEventID) - throws FOPException, TransformerException { - Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, new NullOutputStream()); + public void doTest(InputStream inStream, String fopConf, String expectedEventID, String mimeType) + throws FOPException, TransformerException, IOException, SAXException { EventChecker eventChecker = new EventChecker(expectedEventID); - fop.getUserAgent().getEventBroadcaster().addEventListener(eventChecker); + if (fopConf != null) { + fopFactory.setUserConfig(fopConf); + } + FOUserAgent userAgent = fopFactory.newFOUserAgent(); + userAgent.getEventBroadcaster().addEventListener(eventChecker); + Fop fop = fopFactory.newFop(mimeType, userAgent, new NullOutputStream()); Transformer transformer = tFactory.newTransformer(); - Source src = new StreamSource(new File(basedir, filename)); + Source src = new StreamSource(inStream); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); eventChecker.end(); } + public void doTest(String filename, String expectedEventID) throws + FOPException, TransformerException, IOException, SAXException { + doTest(new FileInputStream(BASE_DIR + filename), null, expectedEventID, + MimeConstants.MIME_PDF); + } + @Test - public void testArea() throws FOPException, TransformerException { + public void testArea() throws TransformerException, IOException, SAXException { doTest("area.fo", AreaEventProducer.class.getName() + ".unresolvedIDReferenceOnPage"); } @Test - public void testResource() throws FOPException, TransformerException { + public void testResource() throws FOPException, TransformerException, IOException, + SAXException { doTest("resource.fo", ResourceEventProducer.class.getName() + ".imageNotFound"); } @Test - public void testValidation() throws FOPException, TransformerException { + public void testValidation() throws FOPException, TransformerException, IOException, + SAXException { doTest("validation.fo", FOValidationEventProducer.class.getName() + ".invalidPropertyValue"); } @Test - public void testTable() throws FOPException, TransformerException { + public void testTable() throws FOPException, TransformerException, IOException, SAXException { doTest("table.fo", TableEventProducer.class.getName() + ".noTablePaddingWithCollapsingBorderModel"); } @Test - public void testBlockLevel() throws FOPException, TransformerException { + public void testBlockLevel() throws FOPException, TransformerException, IOException, + SAXException { doTest("block-level.fo", BlockLevelEventProducer.class.getName() + ".overconstrainedAdjustEndIndent"); } @Test - public void testInlineLevel() throws FOPException, TransformerException { + public void testInlineLevel() throws FOPException, TransformerException, IOException, + SAXException { doTest("inline-level.fo", InlineLevelEventProducer.class.getName() + ".lineOverflows"); } - - @Test - public void testFont() throws FOPException, TransformerException { - doTest("font.fo", - FontEventProducer.class.getName() + ".fontSubstituted"); - } } diff --git a/test/java/org/apache/fop/fo/flow/table/AbstractTableTestCase.java b/test/java/org/apache/fop/fo/flow/table/AbstractTableTest.java index 01e20166a..fb6ec6a25 100644 --- a/test/java/org/apache/fop/fo/flow/table/AbstractTableTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/AbstractTableTest.java @@ -31,7 +31,7 @@ import org.apache.fop.util.ConsoleEventListenerForTests; /** * Superclass for testcases related to tables, factoring the common stuff. */ -abstract class AbstractTableTestCase { +abstract class AbstractTableTest { private FODocumentParser documentParser; diff --git a/test/java/org/apache/fop/config/FontsDirectoryBadTestCase.java b/test/java/org/apache/fop/fo/flow/table/AllTests.java index c19c161a3..7adca8f3a 100644 --- a/test/java/org/apache/fop/config/FontsDirectoryBadTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/AllTests.java @@ -17,20 +17,18 @@ /* $Id$ */ -package org.apache.fop.config; +package org.apache.fop.fo.flow.table; + +import org.junit.runners.Suite; /** - * this font has a metrics-url that does not exist on filesystem + * All test to be added in FOTreeTestSuite + * */ -public class FontsDirectoryBadTestCase extends BaseDestructiveUserConfigTestCase { +@Suite.SuiteClasses({ CollapsedConditionalBorderTestCase.class, IllegalRowSpanTestCase.class, + RowGroupBuilderTestCase.class, TableColumnColumnNumberTestCase.class, + TooManyColumnsTestCase.class }) - @Override - public String getUserConfigFilename() { - return "test_fonts_directory_bad.xconf"; - } - - @Override - protected String getFontFOFilePath() { - return "test/xml/bugtests/font-dir.fo"; - } +public final class AllTests { } + diff --git a/test/java/org/apache/fop/fo/flow/table/CollapsedConditionalBorderTestCase.java b/test/java/org/apache/fop/fo/flow/table/CollapsedConditionalBorderTestCase.java index d046537e3..7c0301ca7 100644 --- a/test/java/org/apache/fop/fo/flow/table/CollapsedConditionalBorderTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/CollapsedConditionalBorderTestCase.java @@ -36,7 +36,7 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo; * conditionality into account. The resolved borders are generated by the * collapsed-conditional-borders_test-generator.py Python script. */ -public class CollapsedConditionalBorderTestCase extends AbstractTableTestCase { +public class CollapsedConditionalBorderTestCase extends AbstractTableTest { private final Integer border0pt = new Integer(0); diff --git a/test/java/org/apache/fop/fo/flow/table/ErrorCheckTestCase.java b/test/java/org/apache/fop/fo/flow/table/ErrorCheckTest.java index 68c7d9f30..b30c64c07 100644 --- a/test/java/org/apache/fop/fo/flow/table/ErrorCheckTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/ErrorCheckTest.java @@ -28,7 +28,7 @@ import org.apache.fop.fo.ValidationException; /** * Abstract class for testing erroneous files, checking that a ValidationException is thrown. */ -abstract class ErrorCheckTestCase extends AbstractTableTestCase { +abstract class ErrorCheckTest extends AbstractTableTest { protected void launchTest(String filename) throws Exception { try { diff --git a/test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java b/test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java index 4018f957c..b2e7a2c9d 100644 --- a/test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java @@ -25,7 +25,7 @@ import org.junit.Test; * Testcase checking that cells spanning further than their parent element aren't * accepted. */ -public class IllegalRowSpanTestCase extends ErrorCheckTestCase { +public class IllegalRowSpanTestCase extends ErrorCheckTest { @Test public void testBody1() throws Exception { diff --git a/test/java/org/apache/fop/fo/flow/table/RowGroupBuilderTestCase.java b/test/java/org/apache/fop/fo/flow/table/RowGroupBuilderTestCase.java index 1af3083ec..361517a66 100644 --- a/test/java/org/apache/fop/fo/flow/table/RowGroupBuilderTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/RowGroupBuilderTestCase.java @@ -33,7 +33,7 @@ import org.junit.Test; * Tests that RowGroupBuilder returns, for each part of a table, the expected number of * row-groups with the expected number or rows in each. */ -public class RowGroupBuilderTestCase extends AbstractTableTestCase { +public class RowGroupBuilderTestCase extends AbstractTableTest { /** * Checks that the given table-body(header,footer) will return row groups as expected. diff --git a/test/java/org/apache/fop/fo/flow/table/TableColumnColumnNumberTestCase.java b/test/java/org/apache/fop/fo/flow/table/TableColumnColumnNumberTestCase.java index c6a93a65c..a21806559 100644 --- a/test/java/org/apache/fop/fo/flow/table/TableColumnColumnNumberTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/TableColumnColumnNumberTestCase.java @@ -29,7 +29,7 @@ import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.fo.FObj; -public class TableColumnColumnNumberTestCase extends AbstractTableTestCase { +public class TableColumnColumnNumberTestCase extends AbstractTableTest { /** * A percentBaseContext that mimics the behaviour of TableLM for computing the widths diff --git a/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java b/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java index 7a9af100e..76a5d196d 100644 --- a/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java @@ -21,7 +21,7 @@ package org.apache.fop.fo.flow.table; import org.junit.Test; -public class TooManyColumnsTestCase extends ErrorCheckTestCase { +public class TooManyColumnsTestCase extends ErrorCheckTest { @Test public void testBody1() throws Exception { diff --git a/test/java/org/apache/fop/fo/pagination/AllTests.java b/test/java/org/apache/fop/fo/pagination/AllTests.java new file mode 100644 index 000000000..664214195 --- /dev/null +++ b/test/java/org/apache/fop/fo/pagination/AllTests.java @@ -0,0 +1,35 @@ +/* + * 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.fo.pagination; + +import org.junit.runners.Suite; +import org.junit.runner.RunWith; + +/** + * All test to be added in FOTreeTestSuite + * + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ PageSequenceMasterTestCase.class, + RepeatablePageMasterAlternativesTestCase.class}) + +public final class AllTests { + +} diff --git a/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java b/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java new file mode 100644 index 000000000..d23ff3c57 --- /dev/null +++ b/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java @@ -0,0 +1,95 @@ +/* + * 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.fo.pagination; + +import static org.junit.Assert.fail; + +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.fop.fo.FONode; +import org.apache.fop.layoutmgr.BlockLevelEventProducer; + +import org.junit.Test; + + +/** + * Unit Test for PageSequenceMaster + * + */ +public class PageSequenceMasterTestCase { + + /** + * Test that PageProductionException is thrown if the final simple-page-master + * cannot handle the main-flow of the page sequence + * @throws Exception exception + */ + @Test + public void testGetNextSimplePageMasterException() throws Exception { + + final String mainFlowRegionName = "main"; + final String emptyFlowRegionName = "empty"; + // Create stubs + + FONode mockParent = mock(FONode.class); + Root mockRoot = mock(Root.class); + LayoutMasterSet mockLayoutMasterSet = mock(LayoutMasterSet.class); + + // This will represent a page master that does not map to the main flow + // of the page sequence + SimplePageMaster mockEmptySPM = mock(SimplePageMaster.class); + Region mockRegion = mock(Region.class); + SinglePageMasterReference mockSinglePageMasterReference + = mock(SinglePageMasterReference.class); + BlockLevelEventProducer mockBlockLevelEventProducer = mock(BlockLevelEventProducer.class); + + //Stub behaviour + when(mockParent.getRoot()).thenReturn(mockRoot); + when(mockRoot.getLayoutMasterSet()).thenReturn(mockLayoutMasterSet); + + //The layout master set should return the empty page master + when(mockLayoutMasterSet.getSimplePageMaster(anyString())).thenReturn(mockEmptySPM); + when(mockEmptySPM.getRegion(anyInt())).thenReturn(mockRegion); + + when(mockRegion.getRegionName()).thenReturn(emptyFlowRegionName); + + when(mockSinglePageMasterReference.getNextPageMaster(anyBoolean(), anyBoolean(), + anyBoolean(), anyBoolean())) + .thenReturn(null, mockEmptySPM); + + PageSequenceMaster pageSequenceMaster = new PageSequenceMaster(mockParent, + mockBlockLevelEventProducer); + pageSequenceMaster.startOfNode(); + pageSequenceMaster.addSubsequenceSpecifier(mockSinglePageMasterReference); + + try { + pageSequenceMaster.getNextSimplePageMaster(false, false, false, false, + mainFlowRegionName); + fail("The next simple page master does not refer to the main flow"); + } catch (PageProductionException ppe) { + //Passed test + } + } + +} + diff --git a/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java b/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java new file mode 100644 index 000000000..29810c472 --- /dev/null +++ b/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java @@ -0,0 +1,171 @@ +/* + * 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.fo.pagination; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.NumericProperty; +import org.apache.fop.fo.properties.Property; + + + +/** + * Unit Test for RepeatablePageMasterAlternatives + * + */ +public class RepeatablePageMasterAlternativesTestCase +implements Constants { + + /** + * + * @throws Exception exception + */ + @Test + public void testIsInfinite1() throws Exception { + // Create fixture + Property maximumRepeats = mock(Property.class); + ConditionalPageMasterReference cpmr = createCPMR("empty"); + + when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT); + + RepeatablePageMasterAlternatives objectUnderTest + = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats); + + assertTrue("is infinite", objectUnderTest.isInfinite()); + } + + /** + * + * @throws Exception exception + */ + @Test + public void testIsInfinite2() throws Exception { + // Create fixture + Property maximumRepeats = mock(Property.class); + ConditionalPageMasterReference cpmr = createCPMR("empty"); + + NumericProperty numericProperty = mock(NumericProperty.class); + + final int maxRepeatNum = 0; + assertTrue(maxRepeatNum != EN_NO_LIMIT); + + when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum); + when(maximumRepeats.getNumeric()).thenReturn(numericProperty); + + RepeatablePageMasterAlternatives objectUnderTest + = createRepeatablePageMasterAlternatives(createCPMR("empty"), + maximumRepeats); + + assertTrue("is infinite", !objectUnderTest.isInfinite()); + } + + /** + * Test that an infinite sequence of empty page masters has + * willTerminiate() returning false + * @throws Exception exception + */ + @Test + public void testCanProcess1() throws Exception { + // Create fixture + Property maximumRepeats = mock(Property.class); + ConditionalPageMasterReference cpmr = createCPMR("empty"); + + when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT); + when(cpmr.isValid(anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean())) + .thenReturn(true); + + RepeatablePageMasterAlternatives objectUnderTest + = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats); + + //Fixture assertion + assertTrue("Should be infinite", objectUnderTest.isInfinite()); + + //Test assertion + assertTrue("Infinite sequences that do not process the main flow will " + + " not terminate", + !objectUnderTest.canProcess("main-flow")); + } + /** + * Test that a finite sequence of simple page masters has + * willTerminate() returning true + * + * @throws Exception exception + */ + @Test + public void testCanProcess2() throws Exception { + // Create fixture + Property maximumRepeats = mock(Property.class); + NumericProperty numericProperty = mock(NumericProperty.class); + + final int maxRepeatNum = 0; + + when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum); + when(maximumRepeats.getNumeric()).thenReturn(numericProperty); + + RepeatablePageMasterAlternatives objectUnderTest + = createRepeatablePageMasterAlternatives(createCPMR("empty"), + maximumRepeats); + + //Fixture assertion + assertTrue("Should be finite sequence", !objectUnderTest.isInfinite()); + + //Test assertion + assertTrue("Finite sequences will terminate", + objectUnderTest.canProcess("main-flow")); + } + + private ConditionalPageMasterReference createCPMR(String regionName) { + ConditionalPageMasterReference cpmr = mock(ConditionalPageMasterReference.class); + SimplePageMaster master = mock(SimplePageMaster.class); + Region region = mock(Region.class); + when(master.getRegion(anyInt())).thenReturn(region); + when(region.getRegionName()).thenReturn(regionName); + when(cpmr.getMaster()).thenReturn(master); + + return cpmr; + } + + private RepeatablePageMasterAlternatives createRepeatablePageMasterAlternatives( + ConditionalPageMasterReference cpmr, Property maximumRepeats) throws Exception { + + PropertyList pList = mock(PropertyList.class); + + when(pList.get(anyInt())).thenReturn(maximumRepeats); + + PageSequenceMaster parent = mock(PageSequenceMaster.class); + + RepeatablePageMasterAlternatives sut = new RepeatablePageMasterAlternatives(parent); + + sut.startOfNode(); + sut.bind(pList); + sut.addConditionalPageMasterReference(cpmr); + return sut; + } + +} + diff --git a/test/java/org/apache/fop/fonts/DejaVuLGCSerifTest.java b/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java index 013d04d13..322d5f622 100644 --- a/test/java/org/apache/fop/fonts/DejaVuLGCSerifTest.java +++ b/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java @@ -29,22 +29,21 @@ import org.junit.Test; /** * */ -public class DejaVuLGCSerifTest { +public class DejaVuLGCSerifTestCase { private FontResolver fontResolver = FontManager.createMinimalFontResolver(); private CustomFont font; /** * sets up the testcase by loading the DejaVu Font. - * + * * @throws Exception * if the test fails. */ @Before public void setUp() throws Exception { - File file = new File("test/resources/fonts/DejaVuLGCSerif.ttf"); - font = FontLoader.loadFont(file, "", true, EncodingMode.AUTO, - fontResolver); + File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf"); + font = FontLoader.loadFont(file, "", true, EncodingMode.AUTO, fontResolver); } /** diff --git a/test/java/org/apache/fop/fonts/EncodingModeTest.java b/test/java/org/apache/fop/fonts/EncodingModeTestCase.java index 310916a04..1ec22e1ef 100644 --- a/test/java/org/apache/fop/fonts/EncodingModeTest.java +++ b/test/java/org/apache/fop/fonts/EncodingModeTestCase.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; -public class EncodingModeTest { +public class EncodingModeTestCase { @Test public void testGetName() { diff --git a/test/java/org/apache/fop/fonts/FontEventProcessingTestCase.java b/test/java/org/apache/fop/fonts/FontEventProcessingTestCase.java new file mode 100644 index 000000000..898f83197 --- /dev/null +++ b/test/java/org/apache/fop/fonts/FontEventProcessingTestCase.java @@ -0,0 +1,60 @@ +/* + * 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.fonts; + +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; + +/** + * Testing font events. + */ +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", + MimeConstants.MIME_PDF); + } + + @Test + public void testFontWithBadDirectory() throws FOPException, TransformerException, IOException, + SAXException { + InputStream inStream = getClass().getResourceAsStream("substituted-font.fo"); + eventsTests.doTest(inStream, CONFIG_BASE_DIR + "test_fonts_directory_bad.xconf", + FontEventProducer.class.getName() + ".fontDirectoryNotFound", + MimeConstants.MIME_PDF); + } + +} diff --git a/test/java/org/apache/fop/fonts/substituted-font.fo b/test/java/org/apache/fop/fonts/substituted-font.fo new file mode 100644 index 000000000..551527522 --- /dev/null +++ b/test/java/org/apache/fop/fonts/substituted-font.fo @@ -0,0 +1,14 @@ +<?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 font-family="blah">This block uses an unknown font.</fo:block> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java b/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java index a55d94e80..67191accc 100644 --- a/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java +++ b/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java @@ -55,7 +55,7 @@ public class GlyfTableTestCase { @Before public void setUp() throws IOException { - originalFontReader = new FontFileReader("test/resources/fonts/DejaVuLGCSerif.ttf"); + originalFontReader = new FontFileReader("test/resources/fonts/ttf/DejaVuLGCSerif.ttf"); } /** diff --git a/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java b/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java new file mode 100644 index 000000000..aadf877e0 --- /dev/null +++ b/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java @@ -0,0 +1,57 @@ +/* + * 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.fonts.truetype; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + +import org.apache.fop.fonts.EncodingMode; +import org.apache.fop.fonts.FontManager; +import org.apache.fop.fonts.FontResolver; + +/** + * Test case for {@link TTFFontLoader}. + */ +public class TTFFontLoaderTestCase { + + @Test + public void testUseKerning() throws IOException { + File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf"); + String absoluteFilePath = file.toURI().toURL().toExternalForm(); + FontResolver resolver = FontManager.createMinimalFontResolver(); + String fontName = "Deja Vu"; + boolean embedded = false; + boolean useKerning = true; + + TTFFontLoader fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded, + EncodingMode.AUTO, useKerning, resolver); + assertTrue(fontLoader.getFont().hasKerningInfo()); + useKerning = false; + + fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded, EncodingMode.AUTO, + useKerning, resolver); + assertFalse(fontLoader.getFont().hasKerningInfo()); + } +} diff --git a/test/java/org/apache/fop/fonts/type1/AFMParserTestCase.java b/test/java/org/apache/fop/fonts/type1/AFMParserTestCase.java new file mode 100644 index 000000000..93443a0d9 --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/AFMParserTestCase.java @@ -0,0 +1,131 @@ +/* + * 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.fonts.type1; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.awt.Rectangle; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import org.junit.Test; + +/** + * Test case for {@link AFMParser}. + */ +public class AFMParserTestCase { + + private AFMParser sut = new AFMParser(); + + /** + * We're testing with two identical files except one has: + * EncodingScheme AdobeStandardEncoding + * the other has: + * EncodingScheme ExpectedEncoding + * Both files have the correct character metrics data, and we're checking that both are handled + * consistently with both encoding settings. + * + * @throws IOException if an I/O error occurs + */ + @Test + public void testMappingAgainstAdobeStandardEncoding() throws IOException { + InputStream expectedStream = getClass().getResourceAsStream( + "adobe-charset_unknown-encoding.afm"); + InputStream adobeStandardStream = getClass().getResourceAsStream( + "adobe-charset_adobe-encoding.afm"); + AFMFile expectedParser = sut.parse(expectedStream, null); + AFMFile adobeStandard = sut.parse(adobeStandardStream, null); + List<AFMCharMetrics> adobeMetrics = adobeStandard.getCharMetrics(); + checkCharMtrxList(true, expectedParser.getCharMetrics(), adobeMetrics); + + compareMetrics(adobeMetrics); + + nonAdobeCharsetUnknownEncoding(adobeMetrics); + + nonAdobeCharsetAdobeEncoding(adobeMetrics); + } + + private void compareMetrics(List<AFMCharMetrics> charMetrics) { + // in order to ensure that every character is parsed properly, we're going to check them + // against the AFM file (bboxes were created with a counter) + AdobeStandardEncoding[] standardEncoding = AdobeStandardEncoding.values(); + for (int i = 0; i < charMetrics.size(); i++) { + Rectangle expectedBbox = new Rectangle(i + 1, i + 1, 0, 0); + AFMCharMetrics thisMetric = charMetrics.get(i); + assertTrue(thisMetric.getBBox().equals(expectedBbox)); + assertEquals(thisMetric.getCharName(), standardEncoding[i].getAdobeName()); + } + } + + /** + * A non-adobe encoded file is tested, all the character codes are not AdobeStandardEncoding and + * the encoding is not AdobeStandardEncoding, we are checking a failure case here. Checking that + * the AdobeStandardEncoding isn't forced on other encodings. + * + * @param expected the AdobeStandardEncoding encoded character metrics list + * @throws IOException if an IO error occurs + */ + private void nonAdobeCharsetUnknownEncoding(List<AFMCharMetrics> expected) + throws IOException { + InputStream inStream = getClass().getResourceAsStream( + "notadobe-charset_unknown-encoding.afm"); + AFMFile afmFile = sut.parse(inStream, null); + List<AFMCharMetrics> unknownEncodingMetrics = afmFile.getCharMetrics(); + checkCharMtrxList(false, expected, unknownEncodingMetrics); + } + + /** + * This tests a poorly encoded file, it has AdobeStandardEncoding. We are checking that the + * metrics are correctly analysed against properly encoded char metrics. + * + * @param expected + * @throws IOException + */ + private void nonAdobeCharsetAdobeEncoding(List<AFMCharMetrics> expected) + throws IOException { + InputStream inStream = getClass().getResourceAsStream( + "notadobe-charset_adobe-encoding.afm"); + AFMFile afmFile = sut.parse(inStream, null); + List<AFMCharMetrics> correctedCharMetrics = afmFile.getCharMetrics(); + checkCharMtrxList(true, expected, correctedCharMetrics); + } + + private boolean charMetricsEqual(AFMCharMetrics o1, AFMCharMetrics o2) { + return o1.getCharCode() == o2.getCharCode() + && objectEquals(o1.getCharacter(), o2.getCharacter()) + && o1.getWidthX() == o2.getWidthX() + && o1.getWidthY() == o2.getWidthY() + && objectEquals(o1.getBBox(), o2.getBBox()); + } + + private void checkCharMtrxList(boolean expectedResult, List<AFMCharMetrics> expectedList, + List<AFMCharMetrics> actualList) { + assertEquals(expectedList.size(), actualList.size()); + for (int i = 0; i < expectedList.size(); i++) { + assertEquals(expectedResult, charMetricsEqual(expectedList.get(i), actualList.get(i))); + } + } + + private boolean objectEquals(Object o1, Object o2) { + return o1 == null ? o2 == null : (o1 == o2 || o1.equals(o2)); + } +} diff --git a/test/java/org/apache/fop/fonts/type1/AdobeStandardEncoding.txt b/test/java/org/apache/fop/fonts/type1/AdobeStandardEncoding.txt new file mode 100644 index 000000000..e39486a31 --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/AdobeStandardEncoding.txt @@ -0,0 +1,213 @@ +# +# Name: Adobe Standard Encoding to Unicode +# Unicode version: 2.0 +# Table version: 1.0 +# Date: 2011 July 12 +# +# Copyright (c) 1991-2011 Unicode, Inc. All Rights reserved. +# +# This file is provided as-is by Unicode, Inc. (The Unicode Consortium). No +# claims are made as to fitness for any particular purpose. No warranties of +# any kind are expressed or implied. The recipient agrees to determine +# applicability of information provided. If this file has been provided on +# magnetic media by Unicode, Inc., the sole remedy for any claim will be +# exchange of defective media within 90 days of receipt. +# +# Unicode, Inc. hereby grants the right to freely use the information +# supplied in this file in the creation of products supporting the +# Unicode Standard, and to make copies of this file in any form for +# internal or external distribution as long as this notice remains +# attached. +# +# Format: 4 tab-delimited fields: +# +# (1) The Unicode value (in hexadecimal) +# (2) The Adobe Standard Encoding code point (in hexadecimal) +# (3) # Unicode name +# (4) # PostScript character name +# +# General Notes: +# +# The Unicode values in this table were produced as the result of applying +# the algorithm described in the section "Populating a Unicode space" in the +# document "Unicode and Glyph Names," at +# http://partners.adobe.com/asn/developer/typeforum/unicodegn.html +# to the characters encoded in Adobe Standard Encoding. Note that some +# Standard Encoding characters, such as "space", are mapped to 2 Unicode +# values. Refer to the above document for more details. +# +# 2011 July 12: The above link is no longer valid. For comparable, +# more current information, see the document, "Glyph", at: +# <http://www.adobe.com/devnet/opentype/archives/glyph.html> +# +# Revision History: +# +# [v1.0, 2011 July 12] +# Updated terms of use to current wording. +# Updated contact information and document link. +# No changes to the mapping data. +# +# [v0.2, 30 March 1999] +# Different algorithm to produce Unicode values (see notes above) results in +# some character codes being mapped to 2 Unicode values. Updated Unicode +# names to Unicode 2.0 names. +# +# [v0.1, 5 May 1995] First release. +# +# Use the Unicode reporting form <http://www.unicode.org/reporting.html> +# for any questions or comments or to report errors in the data. +# +0020 20 # SPACE # space +00A0 20 # NO-BREAK SPACE # space +0021 21 # EXCLAMATION MARK # exclam +0022 22 # QUOTATION MARK # quotedbl +0023 23 # NUMBER SIGN # numbersign +0024 24 # DOLLAR SIGN # dollar +0025 25 # PERCENT SIGN # percent +0026 26 # AMPERSAND # ampersand +2019 27 # RIGHT SINGLE QUOTATION MARK # quoteright +0028 28 # LEFT PARENTHESIS # parenleft +0029 29 # RIGHT PARENTHESIS # parenright +002A 2A # ASTERISK # asterisk +002B 2B # PLUS SIGN # plus +002C 2C # COMMA # comma +002D 2D # HYPHEN-MINUS # hyphen +00AD 2D # SOFT HYPHEN # hyphen +002E 2E # FULL STOP # period +002F 2F # SOLIDUS # slash +0030 30 # DIGIT ZERO # zero +0031 31 # DIGIT ONE # one +0032 32 # DIGIT TWO # two +0033 33 # DIGIT THREE # three +0034 34 # DIGIT FOUR # four +0035 35 # DIGIT FIVE # five +0036 36 # DIGIT SIX # six +0037 37 # DIGIT SEVEN # seven +0038 38 # DIGIT EIGHT # eight +0039 39 # DIGIT NINE # nine +003A 3A # COLON # colon +003B 3B # SEMICOLON # semicolon +003C 3C # LESS-THAN SIGN # less +003D 3D # EQUALS SIGN # equal +003E 3E # GREATER-THAN SIGN # greater +003F 3F # QUESTION MARK # question +0040 40 # COMMERCIAL AT # at +0041 41 # LATIN CAPITAL LETTER A # A +0042 42 # LATIN CAPITAL LETTER B # B +0043 43 # LATIN CAPITAL LETTER C # C +0044 44 # LATIN CAPITAL LETTER D # D +0045 45 # LATIN CAPITAL LETTER E # E +0046 46 # LATIN CAPITAL LETTER F # F +0047 47 # LATIN CAPITAL LETTER G # G +0048 48 # LATIN CAPITAL LETTER H # H +0049 49 # LATIN CAPITAL LETTER I # I +004A 4A # LATIN CAPITAL LETTER J # J +004B 4B # LATIN CAPITAL LETTER K # K +004C 4C # LATIN CAPITAL LETTER L # L +004D 4D # LATIN CAPITAL LETTER M # M +004E 4E # LATIN CAPITAL LETTER N # N +004F 4F # LATIN CAPITAL LETTER O # O +0050 50 # LATIN CAPITAL LETTER P # P +0051 51 # LATIN CAPITAL LETTER Q # Q +0052 52 # LATIN CAPITAL LETTER R # R +0053 53 # LATIN CAPITAL LETTER S # S +0054 54 # LATIN CAPITAL LETTER T # T +0055 55 # LATIN CAPITAL LETTER U # U +0056 56 # LATIN CAPITAL LETTER V # V +0057 57 # LATIN CAPITAL LETTER W # W +0058 58 # LATIN CAPITAL LETTER X # X +0059 59 # LATIN CAPITAL LETTER Y # Y +005A 5A # LATIN CAPITAL LETTER Z # Z +005B 5B # LEFT SQUARE BRACKET # bracketleft +005C 5C # REVERSE SOLIDUS # backslash +005D 5D # RIGHT SQUARE BRACKET # bracketright +005E 5E # CIRCUMFLEX ACCENT # asciicircum +005F 5F # LOW LINE # underscore +2018 60 # LEFT SINGLE QUOTATION MARK # quoteleft +0061 61 # LATIN SMALL LETTER A # a +0062 62 # LATIN SMALL LETTER B # b +0063 63 # LATIN SMALL LETTER C # c +0064 64 # LATIN SMALL LETTER D # d +0065 65 # LATIN SMALL LETTER E # e +0066 66 # LATIN SMALL LETTER F # f +0067 67 # LATIN SMALL LETTER G # g +0068 68 # LATIN SMALL LETTER H # h +0069 69 # LATIN SMALL LETTER I # i +006A 6A # LATIN SMALL LETTER J # j +006B 6B # LATIN SMALL LETTER K # k +006C 6C # LATIN SMALL LETTER L # l +006D 6D # LATIN SMALL LETTER M # m +006E 6E # LATIN SMALL LETTER N # n +006F 6F # LATIN SMALL LETTER O # o +0070 70 # LATIN SMALL LETTER P # p +0071 71 # LATIN SMALL LETTER Q # q +0072 72 # LATIN SMALL LETTER R # r +0073 73 # LATIN SMALL LETTER S # s +0074 74 # LATIN SMALL LETTER T # t +0075 75 # LATIN SMALL LETTER U # u +0076 76 # LATIN SMALL LETTER V # v +0077 77 # LATIN SMALL LETTER W # w +0078 78 # LATIN SMALL LETTER X # x +0079 79 # LATIN SMALL LETTER Y # y +007A 7A # LATIN SMALL LETTER Z # z +007B 7B # LEFT CURLY BRACKET # braceleft +007C 7C # VERTICAL LINE # bar +007D 7D # RIGHT CURLY BRACKET # braceright +007E 7E # TILDE # asciitilde +00A1 A1 # INVERTED EXCLAMATION MARK # exclamdown +00A2 A2 # CENT SIGN # cent +00A3 A3 # POUND SIGN # sterling +2044 A4 # FRACTION SLASH # fraction +2215 A4 # DIVISION SLASH # fraction +00A5 A5 # YEN SIGN # yen +0192 A6 # LATIN SMALL LETTER F WITH HOOK # florin +00A7 A7 # SECTION SIGN # section +00A4 A8 # CURRENCY SIGN # currency +0027 A9 # APOSTROPHE # quotesingle +201C AA # LEFT DOUBLE QUOTATION MARK # quotedblleft +00AB AB # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK # guillemotleft +2039 AC # SINGLE LEFT-POINTING ANGLE QUOTATION MARK # guilsinglleft +203A AD # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK # guilsinglright +FB01 AE # LATIN SMALL LIGATURE FI # fi +FB02 AF # LATIN SMALL LIGATURE FL # fl +2013 B1 # EN DASH # endash +2020 B2 # DAGGER # dagger +2021 B3 # DOUBLE DAGGER # daggerdbl +00B7 B4 # MIDDLE DOT # periodcentered +2219 B4 # BULLET OPERATOR # periodcentered +00B6 B6 # PILCROW SIGN # paragraph +2022 B7 # BULLET # bullet +201A B8 # SINGLE LOW-9 QUOTATION MARK # quotesinglbase +201E B9 # DOUBLE LOW-9 QUOTATION MARK # quotedblbase +201D BA # RIGHT DOUBLE QUOTATION MARK # quotedblright +00BB BB # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK # guillemotright +2026 BC # HORIZONTAL ELLIPSIS # ellipsis +2030 BD # PER MILLE SIGN # perthousand +00BF BF # INVERTED QUESTION MARK # questiondown +0060 C1 # GRAVE ACCENT # grave +00B4 C2 # ACUTE ACCENT # acute +02C6 C3 # MODIFIER LETTER CIRCUMFLEX ACCENT # circumflex +02DC C4 # SMALL TILDE # tilde +00AF C5 # MACRON # macron +02C9 C5 # MODIFIER LETTER MACRON # macron +02D8 C6 # BREVE # breve +02D9 C7 # DOT ABOVE # dotaccent +00A8 C8 # DIAERESIS # dieresis +02DA CA # RING ABOVE # ring +00B8 CB # CEDILLA # cedilla +02DD CD # DOUBLE ACUTE ACCENT # hungarumlaut +02DB CE # OGONEK # ogonek +02C7 CF # CARON # caron +2014 D0 # EM DASH # emdash +00C6 E1 # LATIN CAPITAL LETTER AE # AE +00AA E3 # FEMININE ORDINAL INDICATOR # ordfeminine +0141 E8 # LATIN CAPITAL LETTER L WITH STROKE # Lslash +00D8 E9 # LATIN CAPITAL LETTER O WITH STROKE # Oslash +0152 EA # LATIN CAPITAL LIGATURE OE # OE +00BA EB # MASCULINE ORDINAL INDICATOR # ordmasculine +00E6 F1 # LATIN SMALL LETTER AE # ae +0131 F5 # LATIN SMALL LETTER DOTLESS I # dotlessi +0142 F8 # LATIN SMALL LETTER L WITH STROKE # lslash +00F8 F9 # LATIN SMALL LETTER O WITH STROKE # oslash +0153 FA # LATIN SMALL LIGATURE OE # oe +00DF FB # LATIN SMALL LETTER SHARP S # germandbls diff --git a/test/java/org/apache/fop/fonts/type1/AdobeStandardEncodingTestCase.java b/test/java/org/apache/fop/fonts/type1/AdobeStandardEncodingTestCase.java new file mode 100644 index 000000000..10ba42119 --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/AdobeStandardEncodingTestCase.java @@ -0,0 +1,84 @@ +/* + * 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.fonts.type1; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test case for {@link AdobeStandardEncoding}. + */ +public class AdobeStandardEncodingTestCase { + + private static BufferedReader adobeStandardEncoding; + + /** + * Sets up the file reader, this file was retrieved from the url below. + * http://unicode.org/Public/MAPPINGS/VENDORS/ADOBE/stdenc.txt + * + * @throws FileNotFoundException if the file was not found + */ + @BeforeClass + public static void setupReader() throws FileNotFoundException { + InputStream inStream = AdobeStandardEncodingTestCase.class.getResourceAsStream( + "AdobeStandardEncoding.txt"); + adobeStandardEncoding = new BufferedReader(new InputStreamReader(inStream)); + } + + /** + * Probably the best way to test the encoding is by converting it back to format specified in + * the file, that way we can ensure data has been migrated properly. + * + * @throws IOException if an I/O error occurs + */ + @Test + public void testCorrectEncoding() throws IOException { + for (AdobeStandardEncoding encoding : AdobeStandardEncoding.values()) { + String expectedLine = getLine(); + String hexUnicode = toHexString(encoding.getUnicodeIndex(), 4); + String hexAdobe = toHexString(encoding.getAdobeCodePoint(), 2); + String actualLine = hexUnicode + "\t" + + hexAdobe + "\t# " + + encoding.getUnicodeName() + "\t# " + + encoding.getAdobeName(); + assertEquals(expectedLine, actualLine); + } + } + + private String getLine() throws IOException { + String line = "# The first few lines are comments, these should be ignored"; + while (line.startsWith("#")) { + line = adobeStandardEncoding.readLine(); + } + return line; + } + + private String toHexString(int number, int length) { + return String.format("%0" + length + "X", number); + } +} diff --git a/test/java/org/apache/fop/fonts/type1/CharMetricsHandlerTestCase.java b/test/java/org/apache/fop/fonts/type1/CharMetricsHandlerTestCase.java new file mode 100644 index 000000000..de9af2d33 --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/CharMetricsHandlerTestCase.java @@ -0,0 +1,85 @@ +/* + * 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.fonts.type1; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.awt.Rectangle; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; + +import org.junit.Test; + +import org.apache.fop.fonts.NamedCharacter; +import org.apache.fop.fonts.type1.AFMParser.ValueHandler; + +/** + * Test case for {@link CharMetricsHandler}. + */ +public class CharMetricsHandlerTestCase { + + private static final String GOOD_LINE = "C 32 ; WX 32 ; N space ; B 1 1 1 1"; + + private static final AFMCharMetrics EXPECTED_CHM; + + static { + EXPECTED_CHM = new AFMCharMetrics(); + EXPECTED_CHM.setCharCode(32); + EXPECTED_CHM.setWidthX(32.0); + EXPECTED_CHM.setCharacter(new NamedCharacter("space")); + EXPECTED_CHM.setBBox(new Rectangle(1, 1, 0, 0)); + } + + @Test + public void testHandlers() throws IOException { + testEncodingWithMetricsLine("", GOOD_LINE); + testEncodingWithMetricsLine("WrongEncoding", GOOD_LINE); + testEncodingWithMetricsLine("AdobeStandardEncoding", GOOD_LINE); + } + + private void testEncodingWithMetricsLine(String encoding, String line) throws IOException { + Map<String, ValueHandler> valueParsers = mock(HashMap.class); + ValueHandler cHandler = mock(ValueHandler.class); + ValueHandler wxHandler = mock(ValueHandler.class); + ValueHandler nHandler = mock(ValueHandler.class); + ValueHandler bHandler = mock(ValueHandler.class); + when(valueParsers.get("C")).thenReturn(cHandler); + when(valueParsers.get("WX")).thenReturn(wxHandler); + when(valueParsers.get("N")).thenReturn(nHandler); + when(valueParsers.get("B")).thenReturn(bHandler); + + CharMetricsHandler handler = CharMetricsHandler.getHandler(valueParsers, encoding); + Stack<Object> stack = new Stack<Object>(); + handler.parse(line, stack, null); + + verify(valueParsers).get("C"); + verify(valueParsers).get("WX"); + verify(valueParsers).get("N"); + verify(valueParsers).get("B"); + verify(cHandler).parse("32", 0, new Stack<Object>()); + verify(wxHandler).parse("32", 0, new Stack<Object>()); + verify(nHandler).parse("space", 0, new Stack<Object>()); + verify(bHandler).parse("1 1 1 1", 0, new Stack<Object>()); + } +} diff --git a/test/java/org/apache/fop/fonts/type1/adobe-charset_adobe-encoding.afm b/test/java/org/apache/fop/fonts/type1/adobe-charset_adobe-encoding.afm new file mode 100644 index 000000000..50f8c3381 --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/adobe-charset_adobe-encoding.afm @@ -0,0 +1,158 @@ +StartFontMetrics 2.0 +EncodingScheme AdobeStandardEncoding +StartCharMetrics 154 +C 32 ; WX 32 ; N space ; B 1 1 1 1 +C 32 ; WX 32 ; N space ; B 2 2 2 2 +C 33 ; WX 33 ; N exclam ; B 3 3 3 3 +C 34 ; WX 34 ; N quotedbl ; B 4 4 4 4 +C 35 ; WX 35 ; N numbersign ; B 5 5 5 5 +C 36 ; WX 36 ; N dollar ; B 6 6 6 6 +C 37 ; WX 37 ; N percent ; B 7 7 7 7 +C 38 ; WX 38 ; N ampersand ; B 8 8 8 8 +C 39 ; WX 39 ; N quoteright ; B 9 9 9 9 +C 40 ; WX 40 ; N parenleft ; B 10 10 10 10 +C 41 ; WX 41 ; N parenright ; B 11 11 11 11 +C 42 ; WX 42 ; N asterisk ; B 12 12 12 12 +C 43 ; WX 43 ; N plus ; B 13 13 13 13 +C 44 ; WX 44 ; N comma ; B 14 14 14 14 +C 45 ; WX 45 ; N hyphen ; B 15 15 15 15 +C 45 ; WX 45 ; N hyphen ; B 16 16 16 16 +C 46 ; WX 46 ; N period ; B 17 17 17 17 +C 47 ; WX 47 ; N slash ; B 18 18 18 18 +C 48 ; WX 48 ; N zero ; B 19 19 19 19 +C 49 ; WX 49 ; N one ; B 20 20 20 20 +C 50 ; WX 50 ; N two ; B 21 21 21 21 +C 51 ; WX 51 ; N three ; B 22 22 22 22 +C 52 ; WX 52 ; N four ; B 23 23 23 23 +C 53 ; WX 53 ; N five ; B 24 24 24 24 +C 54 ; WX 54 ; N six ; B 25 25 25 25 +C 55 ; WX 55 ; N seven ; B 26 26 26 26 +C 56 ; WX 56 ; N eight ; B 27 27 27 27 +C 57 ; WX 57 ; N nine ; B 28 28 28 28 +C 58 ; WX 58 ; N colon ; B 29 29 29 29 +C 59 ; WX 59 ; N semicolon ; B 30 30 30 30 +C 60 ; WX 60 ; N less ; B 31 31 31 31 +C 61 ; WX 61 ; N equal ; B 32 32 32 32 +C 62 ; WX 62 ; N greater ; B 33 33 33 33 +C 63 ; WX 63 ; N question ; B 34 34 34 34 +C 64 ; WX 64 ; N at ; B 35 35 35 35 +C 65 ; WX 65 ; N A ; B 36 36 36 36 +C 66 ; WX 66 ; N B ; B 37 37 37 37 +C 67 ; WX 67 ; N C ; B 38 38 38 38 +C 68 ; WX 68 ; N D ; B 39 39 39 39 +C 69 ; WX 69 ; N E ; B 40 40 40 40 +C 70 ; WX 70 ; N F ; B 41 41 41 41 +C 71 ; WX 71 ; N G ; B 42 42 42 42 +C 72 ; WX 72 ; N H ; B 43 43 43 43 +C 73 ; WX 73 ; N I ; B 44 44 44 44 +C 74 ; WX 74 ; N J ; B 45 45 45 45 +C 75 ; WX 75 ; N K ; B 46 46 46 46 +C 76 ; WX 76 ; N L ; B 47 47 47 47 +C 77 ; WX 77 ; N M ; B 48 48 48 48 +C 78 ; WX 78 ; N N ; B 49 49 49 49 +C 79 ; WX 79 ; N O ; B 50 50 50 50 +C 80 ; WX 80 ; N P ; B 51 51 51 51 +C 81 ; WX 81 ; N Q ; B 52 52 52 52 +C 82 ; WX 82 ; N R ; B 53 53 53 53 +C 83 ; WX 83 ; N S ; B 54 54 54 54 +C 84 ; WX 84 ; N T ; B 55 55 55 55 +C 85 ; WX 85 ; N U ; B 56 56 56 56 +C 86 ; WX 86 ; N V ; B 57 57 57 57 +C 87 ; WX 87 ; N W ; B 58 58 58 58 +C 88 ; WX 88 ; N X ; B 59 59 59 59 +C 89 ; WX 89 ; N Y ; B 60 60 60 60 +C 90 ; WX 90 ; N Z ; B 61 61 61 61 +C 91 ; WX 91 ; N bracketleft ; B 62 62 62 62 +C 92 ; WX 92 ; N backslash ; B 63 63 63 63 +C 93 ; WX 93 ; N bracketright ; B 64 64 64 64 +C 94 ; WX 94 ; N asciicircum ; B 65 65 65 65 +C 95 ; WX 95 ; N underscore ; B 66 66 66 66 +C 96 ; WX 96 ; N quoteleft ; B 67 67 67 67 +C 97 ; WX 97 ; N a ; B 68 68 68 68 +C 98 ; WX 98 ; N b ; B 69 69 69 69 +C 99 ; WX 99 ; N c ; B 70 70 70 70 +C 100 ; WX 100 ; N d ; B 71 71 71 71 +C 101 ; WX 101 ; N e ; B 72 72 72 72 +C 102 ; WX 102 ; N f ; B 73 73 73 73 +C 103 ; WX 103 ; N g ; B 74 74 74 74 +C 104 ; WX 104 ; N h ; B 75 75 75 75 +C 105 ; WX 105 ; N i ; B 76 76 76 76 +C 106 ; WX 106 ; N j ; B 77 77 77 77 +C 107 ; WX 107 ; N k ; B 78 78 78 78 +C 108 ; WX 108 ; N l ; B 79 79 79 79 +C 109 ; WX 109 ; N m ; B 80 80 80 80 +C 110 ; WX 110 ; N n ; B 81 81 81 81 +C 111 ; WX 111 ; N o ; B 82 82 82 82 +C 112 ; WX 112 ; N p ; B 83 83 83 83 +C 113 ; WX 113 ; N q ; B 84 84 84 84 +C 114 ; WX 114 ; N r ; B 85 85 85 85 +C 115 ; WX 115 ; N s ; B 86 86 86 86 +C 116 ; WX 116 ; N t ; B 87 87 87 87 +C 117 ; WX 117 ; N u ; B 88 88 88 88 +C 118 ; WX 118 ; N v ; B 89 89 89 89 +C 119 ; WX 119 ; N w ; B 90 90 90 90 +C 120 ; WX 120 ; N x ; B 91 91 91 91 +C 121 ; WX 121 ; N y ; B 92 92 92 92 +C 122 ; WX 122 ; N z ; B 93 93 93 93 +C 123 ; WX 123 ; N braceleft ; B 94 94 94 94 +C 124 ; WX 124 ; N bar ; B 95 95 95 95 +C 125 ; WX 125 ; N braceright ; B 96 96 96 96 +C 126 ; WX 126 ; N asciitilde ; B 97 97 97 97 +C 161 ; WX 161 ; N exclamdown ; B 98 98 98 98 +C 162 ; WX 162 ; N cent ; B 99 99 99 99 +C 163 ; WX 163 ; N sterling ; B 100 100 100 100 +C 164 ; WX 164 ; N fraction ; B 101 101 101 101 +C 164 ; WX 164 ; N fraction ; B 102 102 102 102 +C 165 ; WX 165 ; N yen ; B 103 103 103 103 +C 166 ; WX 166 ; N florin ; B 104 104 104 104 +C 167 ; WX 167 ; N section ; B 105 105 105 105 +C 168 ; WX 168 ; N currency ; B 106 106 106 106 +C 169 ; WX 169 ; N quotesingle ; B 107 107 107 107 +C 170 ; WX 170 ; N quotedblleft ; B 108 108 108 108 +C 171 ; WX 171 ; N guillemotleft ; B 109 109 109 109 +C 172 ; WX 172 ; N guilsinglleft ; B 110 110 110 110 +C 173 ; WX 173 ; N guilsinglright ; B 111 111 111 111 +C 174 ; WX 174 ; N fi ; B 112 112 112 112 +C 175 ; WX 175 ; N fl ; B 113 113 113 113 +C 177 ; WX 177 ; N endash ; B 114 114 114 114 +C 178 ; WX 178 ; N dagger ; B 115 115 115 115 +C 179 ; WX 179 ; N daggerdbl ; B 116 116 116 116 +C 180 ; WX 180 ; N periodcentered ; B 117 117 117 117 +C 180 ; WX 180 ; N periodcentered ; B 118 118 118 118 +C 182 ; WX 182 ; N paragraph ; B 119 119 119 119 +C 183 ; WX 183 ; N bullet ; B 120 120 120 120 +C 184 ; WX 184 ; N quotesinglbase ; B 121 121 121 121 +C 185 ; WX 185 ; N quotedblbase ; B 122 122 122 122 +C 186 ; WX 186 ; N quotedblright ; B 123 123 123 123 +C 187 ; WX 187 ; N guillemotright ; B 124 124 124 124 +C 188 ; WX 188 ; N ellipsis ; B 125 125 125 125 +C 189 ; WX 189 ; N perthousand ; B 126 126 126 126 +C 191 ; WX 191 ; N questiondown ; B 127 127 127 127 +C 193 ; WX 193 ; N grave ; B 128 128 128 128 +C 194 ; WX 194 ; N acute ; B 129 129 129 129 +C 195 ; WX 195 ; N circumflex ; B 130 130 130 130 +C 196 ; WX 196 ; N tilde ; B 131 131 131 131 +C 197 ; WX 197 ; N macron ; B 132 132 132 132 +C 197 ; WX 197 ; N macron ; B 133 133 133 133 +C 198 ; WX 198 ; N breve ; B 134 134 134 134 +C 199 ; WX 199 ; N dotaccent ; B 135 135 135 135 +C 200 ; WX 200 ; N dieresis ; B 136 136 136 136 +C 202 ; WX 202 ; N ring ; B 137 137 137 137 +C 203 ; WX 203 ; N cedilla ; B 138 138 138 138 +C 205 ; WX 205 ; N hungarumlaut ; B 139 139 139 139 +C 206 ; WX 206 ; N ogonek ; B 140 140 140 140 +C 207 ; WX 207 ; N caron ; B 141 141 141 141 +C 208 ; WX 208 ; N emdash ; B 142 142 142 142 +C 225 ; WX 225 ; N AE ; B 143 143 143 143 +C 227 ; WX 227 ; N ordfeminine ; B 144 144 144 144 +C 232 ; WX 232 ; N Lslash ; B 145 145 145 145 +C 233 ; WX 233 ; N Oslash ; B 146 146 146 146 +C 234 ; WX 234 ; N OE ; B 147 147 147 147 +C 235 ; WX 235 ; N ordmasculine ; B 148 148 148 148 +C 241 ; WX 241 ; N ae ; B 149 149 149 149 +C 245 ; WX 245 ; N dotlessi ; B 150 150 150 150 +C 248 ; WX 248 ; N lslash ; B 151 151 151 151 +C 249 ; WX 249 ; N oslash ; B 152 152 152 152 +C 250 ; WX 250 ; N oe ; B 153 153 153 153 +C 251 ; WX 251 ; N germandbls ; B 154 154 154 154 +EndCharMetrics diff --git a/test/java/org/apache/fop/fonts/type1/adobe-charset_unknown-encoding.afm b/test/java/org/apache/fop/fonts/type1/adobe-charset_unknown-encoding.afm new file mode 100644 index 000000000..8edbe0d76 --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/adobe-charset_unknown-encoding.afm @@ -0,0 +1,158 @@ +StartFontMetrics 2.0 +EncodingScheme FontSpecific +StartCharMetrics 154 +C 32 ; WX 32 ; N space ; B 1 1 1 1 +C 32 ; WX 32 ; N space ; B 2 2 2 2 +C 33 ; WX 33 ; N exclam ; B 3 3 3 3 +C 34 ; WX 34 ; N quotedbl ; B 4 4 4 4 +C 35 ; WX 35 ; N numbersign ; B 5 5 5 5 +C 36 ; WX 36 ; N dollar ; B 6 6 6 6 +C 37 ; WX 37 ; N percent ; B 7 7 7 7 +C 38 ; WX 38 ; N ampersand ; B 8 8 8 8 +C 39 ; WX 39 ; N quoteright ; B 9 9 9 9 +C 40 ; WX 40 ; N parenleft ; B 10 10 10 10 +C 41 ; WX 41 ; N parenright ; B 11 11 11 11 +C 42 ; WX 42 ; N asterisk ; B 12 12 12 12 +C 43 ; WX 43 ; N plus ; B 13 13 13 13 +C 44 ; WX 44 ; N comma ; B 14 14 14 14 +C 45 ; WX 45 ; N hyphen ; B 15 15 15 15 +C 45 ; WX 45 ; N hyphen ; B 16 16 16 16 +C 46 ; WX 46 ; N period ; B 17 17 17 17 +C 47 ; WX 47 ; N slash ; B 18 18 18 18 +C 48 ; WX 48 ; N zero ; B 19 19 19 19 +C 49 ; WX 49 ; N one ; B 20 20 20 20 +C 50 ; WX 50 ; N two ; B 21 21 21 21 +C 51 ; WX 51 ; N three ; B 22 22 22 22 +C 52 ; WX 52 ; N four ; B 23 23 23 23 +C 53 ; WX 53 ; N five ; B 24 24 24 24 +C 54 ; WX 54 ; N six ; B 25 25 25 25 +C 55 ; WX 55 ; N seven ; B 26 26 26 26 +C 56 ; WX 56 ; N eight ; B 27 27 27 27 +C 57 ; WX 57 ; N nine ; B 28 28 28 28 +C 58 ; WX 58 ; N colon ; B 29 29 29 29 +C 59 ; WX 59 ; N semicolon ; B 30 30 30 30 +C 60 ; WX 60 ; N less ; B 31 31 31 31 +C 61 ; WX 61 ; N equal ; B 32 32 32 32 +C 62 ; WX 62 ; N greater ; B 33 33 33 33 +C 63 ; WX 63 ; N question ; B 34 34 34 34 +C 64 ; WX 64 ; N at ; B 35 35 35 35 +C 65 ; WX 65 ; N A ; B 36 36 36 36 +C 66 ; WX 66 ; N B ; B 37 37 37 37 +C 67 ; WX 67 ; N C ; B 38 38 38 38 +C 68 ; WX 68 ; N D ; B 39 39 39 39 +C 69 ; WX 69 ; N E ; B 40 40 40 40 +C 70 ; WX 70 ; N F ; B 41 41 41 41 +C 71 ; WX 71 ; N G ; B 42 42 42 42 +C 72 ; WX 72 ; N H ; B 43 43 43 43 +C 73 ; WX 73 ; N I ; B 44 44 44 44 +C 74 ; WX 74 ; N J ; B 45 45 45 45 +C 75 ; WX 75 ; N K ; B 46 46 46 46 +C 76 ; WX 76 ; N L ; B 47 47 47 47 +C 77 ; WX 77 ; N M ; B 48 48 48 48 +C 78 ; WX 78 ; N N ; B 49 49 49 49 +C 79 ; WX 79 ; N O ; B 50 50 50 50 +C 80 ; WX 80 ; N P ; B 51 51 51 51 +C 81 ; WX 81 ; N Q ; B 52 52 52 52 +C 82 ; WX 82 ; N R ; B 53 53 53 53 +C 83 ; WX 83 ; N S ; B 54 54 54 54 +C 84 ; WX 84 ; N T ; B 55 55 55 55 +C 85 ; WX 85 ; N U ; B 56 56 56 56 +C 86 ; WX 86 ; N V ; B 57 57 57 57 +C 87 ; WX 87 ; N W ; B 58 58 58 58 +C 88 ; WX 88 ; N X ; B 59 59 59 59 +C 89 ; WX 89 ; N Y ; B 60 60 60 60 +C 90 ; WX 90 ; N Z ; B 61 61 61 61 +C 91 ; WX 91 ; N bracketleft ; B 62 62 62 62 +C 92 ; WX 92 ; N backslash ; B 63 63 63 63 +C 93 ; WX 93 ; N bracketright ; B 64 64 64 64 +C 94 ; WX 94 ; N asciicircum ; B 65 65 65 65 +C 95 ; WX 95 ; N underscore ; B 66 66 66 66 +C 96 ; WX 96 ; N quoteleft ; B 67 67 67 67 +C 97 ; WX 97 ; N a ; B 68 68 68 68 +C 98 ; WX 98 ; N b ; B 69 69 69 69 +C 99 ; WX 99 ; N c ; B 70 70 70 70 +C 100 ; WX 100 ; N d ; B 71 71 71 71 +C 101 ; WX 101 ; N e ; B 72 72 72 72 +C 102 ; WX 102 ; N f ; B 73 73 73 73 +C 103 ; WX 103 ; N g ; B 74 74 74 74 +C 104 ; WX 104 ; N h ; B 75 75 75 75 +C 105 ; WX 105 ; N i ; B 76 76 76 76 +C 106 ; WX 106 ; N j ; B 77 77 77 77 +C 107 ; WX 107 ; N k ; B 78 78 78 78 +C 108 ; WX 108 ; N l ; B 79 79 79 79 +C 109 ; WX 109 ; N m ; B 80 80 80 80 +C 110 ; WX 110 ; N n ; B 81 81 81 81 +C 111 ; WX 111 ; N o ; B 82 82 82 82 +C 112 ; WX 112 ; N p ; B 83 83 83 83 +C 113 ; WX 113 ; N q ; B 84 84 84 84 +C 114 ; WX 114 ; N r ; B 85 85 85 85 +C 115 ; WX 115 ; N s ; B 86 86 86 86 +C 116 ; WX 116 ; N t ; B 87 87 87 87 +C 117 ; WX 117 ; N u ; B 88 88 88 88 +C 118 ; WX 118 ; N v ; B 89 89 89 89 +C 119 ; WX 119 ; N w ; B 90 90 90 90 +C 120 ; WX 120 ; N x ; B 91 91 91 91 +C 121 ; WX 121 ; N y ; B 92 92 92 92 +C 122 ; WX 122 ; N z ; B 93 93 93 93 +C 123 ; WX 123 ; N braceleft ; B 94 94 94 94 +C 124 ; WX 124 ; N bar ; B 95 95 95 95 +C 125 ; WX 125 ; N braceright ; B 96 96 96 96 +C 126 ; WX 126 ; N asciitilde ; B 97 97 97 97 +C 161 ; WX 161 ; N exclamdown ; B 98 98 98 98 +C 162 ; WX 162 ; N cent ; B 99 99 99 99 +C 163 ; WX 163 ; N sterling ; B 100 100 100 100 +C 164 ; WX 164 ; N fraction ; B 101 101 101 101 +C 164 ; WX 164 ; N fraction ; B 102 102 102 102 +C 165 ; WX 165 ; N yen ; B 103 103 103 103 +C 166 ; WX 166 ; N florin ; B 104 104 104 104 +C 167 ; WX 167 ; N section ; B 105 105 105 105 +C 168 ; WX 168 ; N currency ; B 106 106 106 106 +C 169 ; WX 169 ; N quotesingle ; B 107 107 107 107 +C 170 ; WX 170 ; N quotedblleft ; B 108 108 108 108 +C 171 ; WX 171 ; N guillemotleft ; B 109 109 109 109 +C 172 ; WX 172 ; N guilsinglleft ; B 110 110 110 110 +C 173 ; WX 173 ; N guilsinglright ; B 111 111 111 111 +C 174 ; WX 174 ; N fi ; B 112 112 112 112 +C 175 ; WX 175 ; N fl ; B 113 113 113 113 +C 177 ; WX 177 ; N endash ; B 114 114 114 114 +C 178 ; WX 178 ; N dagger ; B 115 115 115 115 +C 179 ; WX 179 ; N daggerdbl ; B 116 116 116 116 +C 180 ; WX 180 ; N periodcentered ; B 117 117 117 117 +C 180 ; WX 180 ; N periodcentered ; B 118 118 118 118 +C 182 ; WX 182 ; N paragraph ; B 119 119 119 119 +C 183 ; WX 183 ; N bullet ; B 120 120 120 120 +C 184 ; WX 184 ; N quotesinglbase ; B 121 121 121 121 +C 185 ; WX 185 ; N quotedblbase ; B 122 122 122 122 +C 186 ; WX 186 ; N quotedblright ; B 123 123 123 123 +C 187 ; WX 187 ; N guillemotright ; B 124 124 124 124 +C 188 ; WX 188 ; N ellipsis ; B 125 125 125 125 +C 189 ; WX 189 ; N perthousand ; B 126 126 126 126 +C 191 ; WX 191 ; N questiondown ; B 127 127 127 127 +C 193 ; WX 193 ; N grave ; B 128 128 128 128 +C 194 ; WX 194 ; N acute ; B 129 129 129 129 +C 195 ; WX 195 ; N circumflex ; B 130 130 130 130 +C 196 ; WX 196 ; N tilde ; B 131 131 131 131 +C 197 ; WX 197 ; N macron ; B 132 132 132 132 +C 197 ; WX 197 ; N macron ; B 133 133 133 133 +C 198 ; WX 198 ; N breve ; B 134 134 134 134 +C 199 ; WX 199 ; N dotaccent ; B 135 135 135 135 +C 200 ; WX 200 ; N dieresis ; B 136 136 136 136 +C 202 ; WX 202 ; N ring ; B 137 137 137 137 +C 203 ; WX 203 ; N cedilla ; B 138 138 138 138 +C 205 ; WX 205 ; N hungarumlaut ; B 139 139 139 139 +C 206 ; WX 206 ; N ogonek ; B 140 140 140 140 +C 207 ; WX 207 ; N caron ; B 141 141 141 141 +C 208 ; WX 208 ; N emdash ; B 142 142 142 142 +C 225 ; WX 225 ; N AE ; B 143 143 143 143 +C 227 ; WX 227 ; N ordfeminine ; B 144 144 144 144 +C 232 ; WX 232 ; N Lslash ; B 145 145 145 145 +C 233 ; WX 233 ; N Oslash ; B 146 146 146 146 +C 234 ; WX 234 ; N OE ; B 147 147 147 147 +C 235 ; WX 235 ; N ordmasculine ; B 148 148 148 148 +C 241 ; WX 241 ; N ae ; B 149 149 149 149 +C 245 ; WX 245 ; N dotlessi ; B 150 150 150 150 +C 248 ; WX 248 ; N lslash ; B 151 151 151 151 +C 249 ; WX 249 ; N oslash ; B 152 152 152 152 +C 250 ; WX 250 ; N oe ; B 153 153 153 153 +C 251 ; WX 251 ; N germandbls ; B 154 154 154 154 +EndCharMetrics diff --git a/test/java/org/apache/fop/fonts/type1/notadobe-charset_adobe-encoding.afm b/test/java/org/apache/fop/fonts/type1/notadobe-charset_adobe-encoding.afm new file mode 100644 index 000000000..11cecb17f --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/notadobe-charset_adobe-encoding.afm @@ -0,0 +1,158 @@ +StartFontMetrics 2.0 +EncodingScheme AdobeStandardEncoding +StartCharMetrics 154 +C 33 ; WX 32 ; N space ; B 1 1 1 1 +C 33 ; WX 32 ; N space ; B 2 2 2 2 +C 34 ; WX 33 ; N exclam ; B 3 3 3 3 +C 35 ; WX 34 ; N quotedbl ; B 4 4 4 4 +C 36 ; WX 35 ; N numbersign ; B 5 5 5 5 +C 37 ; WX 36 ; N dollar ; B 6 6 6 6 +C 38 ; WX 37 ; N percent ; B 7 7 7 7 +C 39 ; WX 38 ; N ampersand ; B 8 8 8 8 +C 40 ; WX 39 ; N quoteright ; B 9 9 9 9 +C 41 ; WX 40 ; N parenleft ; B 10 10 10 10 +C 42 ; WX 41 ; N parenright ; B 11 11 11 11 +C 43 ; WX 42 ; N asterisk ; B 12 12 12 12 +C 44 ; WX 43 ; N plus ; B 13 13 13 13 +C 45 ; WX 44 ; N comma ; B 14 14 14 14 +C 46 ; WX 45 ; N hyphen ; B 15 15 15 15 +C 46 ; WX 45 ; N hyphen ; B 16 16 16 16 +C 47 ; WX 46 ; N period ; B 17 17 17 17 +C 48 ; WX 47 ; N slash ; B 18 18 18 18 +C 49 ; WX 48 ; N zero ; B 19 19 19 19 +C 50 ; WX 49 ; N one ; B 20 20 20 20 +C 51 ; WX 50 ; N two ; B 21 21 21 21 +C 52 ; WX 51 ; N three ; B 22 22 22 22 +C 53 ; WX 52 ; N four ; B 23 23 23 23 +C 54 ; WX 53 ; N five ; B 24 24 24 24 +C 55 ; WX 54 ; N six ; B 25 25 25 25 +C 56 ; WX 55 ; N seven ; B 26 26 26 26 +C 57 ; WX 56 ; N eight ; B 27 27 27 27 +C 58 ; WX 57 ; N nine ; B 28 28 28 28 +C 59 ; WX 58 ; N colon ; B 29 29 29 29 +C 60 ; WX 59 ; N semicolon ; B 30 30 30 30 +C 61 ; WX 60 ; N less ; B 31 31 31 31 +C 62 ; WX 61 ; N equal ; B 32 32 32 32 +C 63 ; WX 62 ; N greater ; B 33 33 33 33 +C 64 ; WX 63 ; N question ; B 34 34 34 34 +C 65 ; WX 64 ; N at ; B 35 35 35 35 +C 66 ; WX 65 ; N A ; B 36 36 36 36 +C 67 ; WX 66 ; N B ; B 37 37 37 37 +C 68 ; WX 67 ; N C ; B 38 38 38 38 +C 69 ; WX 68 ; N D ; B 39 39 39 39 +C 70 ; WX 69 ; N E ; B 40 40 40 40 +C 71 ; WX 70 ; N F ; B 41 41 41 41 +C 72 ; WX 71 ; N G ; B 42 42 42 42 +C 73 ; WX 72 ; N H ; B 43 43 43 43 +C 74 ; WX 73 ; N I ; B 44 44 44 44 +C 75 ; WX 74 ; N J ; B 45 45 45 45 +C 76 ; WX 75 ; N K ; B 46 46 46 46 +C 77 ; WX 76 ; N L ; B 47 47 47 47 +C 78 ; WX 77 ; N M ; B 48 48 48 48 +C 79 ; WX 78 ; N N ; B 49 49 49 49 +C 80 ; WX 79 ; N O ; B 50 50 50 50 +C 81 ; WX 80 ; N P ; B 51 51 51 51 +C 82 ; WX 81 ; N Q ; B 52 52 52 52 +C 83 ; WX 82 ; N R ; B 53 53 53 53 +C 84 ; WX 83 ; N S ; B 54 54 54 54 +C 85 ; WX 84 ; N T ; B 55 55 55 55 +C 86 ; WX 85 ; N U ; B 56 56 56 56 +C 87 ; WX 86 ; N V ; B 57 57 57 57 +C 88 ; WX 87 ; N W ; B 58 58 58 58 +C 89 ; WX 88 ; N X ; B 59 59 59 59 +C 90 ; WX 89 ; N Y ; B 60 60 60 60 +C 91 ; WX 90 ; N Z ; B 61 61 61 61 +C 92 ; WX 91 ; N bracketleft ; B 62 62 62 62 +C 93 ; WX 92 ; N backslash ; B 63 63 63 63 +C 94 ; WX 93 ; N bracketright ; B 64 64 64 64 +C 95 ; WX 94 ; N asciicircum ; B 65 65 65 65 +C 96 ; WX 95 ; N underscore ; B 66 66 66 66 +C 97 ; WX 96 ; N quoteleft ; B 67 67 67 67 +C 98 ; WX 97 ; N a ; B 68 68 68 68 +C 99 ; WX 98 ; N b ; B 69 69 69 69 +C 100 ; WX 99 ; N c ; B 70 70 70 70 +C 101 ; WX 100 ; N d ; B 71 71 71 71 +C 102 ; WX 101 ; N e ; B 72 72 72 72 +C 103 ; WX 102 ; N f ; B 73 73 73 73 +C 104 ; WX 103 ; N g ; B 74 74 74 74 +C 105 ; WX 104 ; N h ; B 75 75 75 75 +C 106 ; WX 105 ; N i ; B 76 76 76 76 +C 107 ; WX 106 ; N j ; B 77 77 77 77 +C 108 ; WX 107 ; N k ; B 78 78 78 78 +C 109 ; WX 108 ; N l ; B 79 79 79 79 +C 110 ; WX 109 ; N m ; B 80 80 80 80 +C 111 ; WX 110 ; N n ; B 81 81 81 81 +C 112 ; WX 111 ; N o ; B 82 82 82 82 +C 113 ; WX 112 ; N p ; B 83 83 83 83 +C 114 ; WX 113 ; N q ; B 84 84 84 84 +C 115 ; WX 114 ; N r ; B 85 85 85 85 +C 116 ; WX 115 ; N s ; B 86 86 86 86 +C 117 ; WX 116 ; N t ; B 87 87 87 87 +C 118 ; WX 117 ; N u ; B 88 88 88 88 +C 119 ; WX 118 ; N v ; B 89 89 89 89 +C 120 ; WX 119 ; N w ; B 90 90 90 90 +C 121 ; WX 120 ; N x ; B 91 91 91 91 +C 122 ; WX 121 ; N y ; B 92 92 92 92 +C 123 ; WX 122 ; N z ; B 93 93 93 93 +C 124 ; WX 123 ; N braceleft ; B 94 94 94 94 +C 125 ; WX 124 ; N bar ; B 95 95 95 95 +C 126 ; WX 125 ; N braceright ; B 96 96 96 96 +C 127 ; WX 126 ; N asciitilde ; B 97 97 97 97 +C 162 ; WX 161 ; N exclamdown ; B 98 98 98 98 +C 163 ; WX 162 ; N cent ; B 99 99 99 99 +C 164 ; WX 163 ; N sterling ; B 100 100 100 100 +C 165 ; WX 164 ; N fraction ; B 101 101 101 101 +C 165 ; WX 164 ; N fraction ; B 102 102 102 102 +C 166 ; WX 165 ; N yen ; B 103 103 103 103 +C 167 ; WX 166 ; N florin ; B 104 104 104 104 +C 168 ; WX 167 ; N section ; B 105 105 105 105 +C 169 ; WX 168 ; N currency ; B 106 106 106 106 +C 170 ; WX 169 ; N quotesingle ; B 107 107 107 107 +C 171 ; WX 170 ; N quotedblleft ; B 108 108 108 108 +C 172 ; WX 171 ; N guillemotleft ; B 109 109 109 109 +C 173 ; WX 172 ; N guilsinglleft ; B 110 110 110 110 +C 174 ; WX 173 ; N guilsinglright ; B 111 111 111 111 +C 175 ; WX 174 ; N fi ; B 112 112 112 112 +C 176 ; WX 175 ; N fl ; B 113 113 113 113 +C 178 ; WX 177 ; N endash ; B 114 114 114 114 +C 179 ; WX 178 ; N dagger ; B 115 115 115 115 +C 180 ; WX 179 ; N daggerdbl ; B 116 116 116 116 +C 181 ; WX 180 ; N periodcentered ; B 117 117 117 117 +C 181 ; WX 180 ; N periodcentered ; B 118 118 118 118 +C 183 ; WX 182 ; N paragraph ; B 119 119 119 119 +C 184 ; WX 183 ; N bullet ; B 120 120 120 120 +C 185 ; WX 184 ; N quotesinglbase ; B 121 121 121 121 +C 186 ; WX 185 ; N quotedblbase ; B 122 122 122 122 +C 187 ; WX 186 ; N quotedblright ; B 123 123 123 123 +C 188 ; WX 187 ; N guillemotright ; B 124 124 124 124 +C 189 ; WX 188 ; N ellipsis ; B 125 125 125 125 +C 190 ; WX 189 ; N perthousand ; B 126 126 126 126 +C 192 ; WX 191 ; N questiondown ; B 127 127 127 127 +C 194 ; WX 193 ; N grave ; B 128 128 128 128 +C 195 ; WX 194 ; N acute ; B 129 129 129 129 +C 196 ; WX 195 ; N circumflex ; B 130 130 130 130 +C 197 ; WX 196 ; N tilde ; B 131 131 131 131 +C 198 ; WX 197 ; N macron ; B 132 132 132 132 +C 198 ; WX 197 ; N macron ; B 133 133 133 133 +C 199 ; WX 198 ; N breve ; B 134 134 134 134 +C 200 ; WX 199 ; N dotaccent ; B 135 135 135 135 +C 201 ; WX 200 ; N dieresis ; B 136 136 136 136 +C 203 ; WX 202 ; N ring ; B 137 137 137 137 +C 204 ; WX 203 ; N cedilla ; B 138 138 138 138 +C 206 ; WX 205 ; N hungarumlaut ; B 139 139 139 139 +C 207 ; WX 206 ; N ogonek ; B 140 140 140 140 +C 208 ; WX 207 ; N caron ; B 141 141 141 141 +C 209 ; WX 208 ; N emdash ; B 142 142 142 142 +C 226 ; WX 225 ; N AE ; B 143 143 143 143 +C 228 ; WX 227 ; N ordfeminine ; B 144 144 144 144 +C 233 ; WX 232 ; N Lslash ; B 145 145 145 145 +C 234 ; WX 233 ; N Oslash ; B 146 146 146 146 +C 235 ; WX 234 ; N OE ; B 147 147 147 147 +C 236 ; WX 235 ; N ordmasculine ; B 148 148 148 148 +C 242 ; WX 241 ; N ae ; B 149 149 149 149 +C 246 ; WX 245 ; N dotlessi ; B 150 150 150 150 +C 249 ; WX 248 ; N lslash ; B 151 151 151 151 +C 250 ; WX 249 ; N oslash ; B 152 152 152 152 +C 251 ; WX 250 ; N oe ; B 153 153 153 153 +C 252 ; WX 251 ; N germandbls ; B 154 154 154 154 +EndCharMetrics diff --git a/test/java/org/apache/fop/fonts/type1/notadobe-charset_unknown-encoding.afm b/test/java/org/apache/fop/fonts/type1/notadobe-charset_unknown-encoding.afm new file mode 100644 index 000000000..1714288ab --- /dev/null +++ b/test/java/org/apache/fop/fonts/type1/notadobe-charset_unknown-encoding.afm @@ -0,0 +1,158 @@ +StartFontMetrics 2.0 +EncodingScheme FontSpecific +StartCharMetrics 154 +C 33 ; WX 32 ; N space ; B 1 1 1 1 +C 33 ; WX 32 ; N space ; B 2 2 2 2 +C 34 ; WX 33 ; N exclam ; B 3 3 3 3 +C 35 ; WX 34 ; N quotedbl ; B 4 4 4 4 +C 36 ; WX 35 ; N numbersign ; B 5 5 5 5 +C 37 ; WX 36 ; N dollar ; B 6 6 6 6 +C 38 ; WX 37 ; N percent ; B 7 7 7 7 +C 39 ; WX 38 ; N ampersand ; B 8 8 8 8 +C 40 ; WX 39 ; N quoteright ; B 9 9 9 9 +C 41 ; WX 40 ; N parenleft ; B 10 10 10 10 +C 42 ; WX 41 ; N parenright ; B 11 11 11 11 +C 43 ; WX 42 ; N asterisk ; B 12 12 12 12 +C 44 ; WX 43 ; N plus ; B 13 13 13 13 +C 45 ; WX 44 ; N comma ; B 14 14 14 14 +C 46 ; WX 45 ; N hyphen ; B 15 15 15 15 +C 46 ; WX 45 ; N hyphen ; B 16 16 16 16 +C 47 ; WX 46 ; N period ; B 17 17 17 17 +C 48 ; WX 47 ; N slash ; B 18 18 18 18 +C 49 ; WX 48 ; N zero ; B 19 19 19 19 +C 50 ; WX 49 ; N one ; B 20 20 20 20 +C 51 ; WX 50 ; N two ; B 21 21 21 21 +C 52 ; WX 51 ; N three ; B 22 22 22 22 +C 53 ; WX 52 ; N four ; B 23 23 23 23 +C 54 ; WX 53 ; N five ; B 24 24 24 24 +C 55 ; WX 54 ; N six ; B 25 25 25 25 +C 56 ; WX 55 ; N seven ; B 26 26 26 26 +C 57 ; WX 56 ; N eight ; B 27 27 27 27 +C 58 ; WX 57 ; N nine ; B 28 28 28 28 +C 59 ; WX 58 ; N colon ; B 29 29 29 29 +C 60 ; WX 59 ; N semicolon ; B 30 30 30 30 +C 61 ; WX 60 ; N less ; B 31 31 31 31 +C 62 ; WX 61 ; N equal ; B 32 32 32 32 +C 63 ; WX 62 ; N greater ; B 33 33 33 33 +C 64 ; WX 63 ; N question ; B 34 34 34 34 +C 65 ; WX 64 ; N at ; B 35 35 35 35 +C 66 ; WX 65 ; N A ; B 36 36 36 36 +C 67 ; WX 66 ; N B ; B 37 37 37 37 +C 68 ; WX 67 ; N C ; B 38 38 38 38 +C 69 ; WX 68 ; N D ; B 39 39 39 39 +C 70 ; WX 69 ; N E ; B 40 40 40 40 +C 71 ; WX 70 ; N F ; B 41 41 41 41 +C 72 ; WX 71 ; N G ; B 42 42 42 42 +C 73 ; WX 72 ; N H ; B 43 43 43 43 +C 74 ; WX 73 ; N I ; B 44 44 44 44 +C 75 ; WX 74 ; N J ; B 45 45 45 45 +C 76 ; WX 75 ; N K ; B 46 46 46 46 +C 77 ; WX 76 ; N L ; B 47 47 47 47 +C 78 ; WX 77 ; N M ; B 48 48 48 48 +C 79 ; WX 78 ; N N ; B 49 49 49 49 +C 80 ; WX 79 ; N O ; B 50 50 50 50 +C 81 ; WX 80 ; N P ; B 51 51 51 51 +C 82 ; WX 81 ; N Q ; B 52 52 52 52 +C 83 ; WX 82 ; N R ; B 53 53 53 53 +C 84 ; WX 83 ; N S ; B 54 54 54 54 +C 85 ; WX 84 ; N T ; B 55 55 55 55 +C 86 ; WX 85 ; N U ; B 56 56 56 56 +C 87 ; WX 86 ; N V ; B 57 57 57 57 +C 88 ; WX 87 ; N W ; B 58 58 58 58 +C 89 ; WX 88 ; N X ; B 59 59 59 59 +C 90 ; WX 89 ; N Y ; B 60 60 60 60 +C 91 ; WX 90 ; N Z ; B 61 61 61 61 +C 92 ; WX 91 ; N bracketleft ; B 62 62 62 62 +C 93 ; WX 92 ; N backslash ; B 63 63 63 63 +C 94 ; WX 93 ; N bracketright ; B 64 64 64 64 +C 95 ; WX 94 ; N asciicircum ; B 65 65 65 65 +C 96 ; WX 95 ; N underscore ; B 66 66 66 66 +C 97 ; WX 96 ; N quoteleft ; B 67 67 67 67 +C 98 ; WX 97 ; N a ; B 68 68 68 68 +C 99 ; WX 98 ; N b ; B 69 69 69 69 +C 100 ; WX 99 ; N c ; B 70 70 70 70 +C 101 ; WX 100 ; N d ; B 71 71 71 71 +C 102 ; WX 101 ; N e ; B 72 72 72 72 +C 103 ; WX 102 ; N f ; B 73 73 73 73 +C 104 ; WX 103 ; N g ; B 74 74 74 74 +C 105 ; WX 104 ; N h ; B 75 75 75 75 +C 106 ; WX 105 ; N i ; B 76 76 76 76 +C 107 ; WX 106 ; N j ; B 77 77 77 77 +C 108 ; WX 107 ; N k ; B 78 78 78 78 +C 109 ; WX 108 ; N l ; B 79 79 79 79 +C 110 ; WX 109 ; N m ; B 80 80 80 80 +C 111 ; WX 110 ; N n ; B 81 81 81 81 +C 112 ; WX 111 ; N o ; B 82 82 82 82 +C 113 ; WX 112 ; N p ; B 83 83 83 83 +C 114 ; WX 113 ; N q ; B 84 84 84 84 +C 115 ; WX 114 ; N r ; B 85 85 85 85 +C 116 ; WX 115 ; N s ; B 86 86 86 86 +C 117 ; WX 116 ; N t ; B 87 87 87 87 +C 118 ; WX 117 ; N u ; B 88 88 88 88 +C 119 ; WX 118 ; N v ; B 89 89 89 89 +C 120 ; WX 119 ; N w ; B 90 90 90 90 +C 121 ; WX 120 ; N x ; B 91 91 91 91 +C 122 ; WX 121 ; N y ; B 92 92 92 92 +C 123 ; WX 122 ; N z ; B 93 93 93 93 +C 124 ; WX 123 ; N braceleft ; B 94 94 94 94 +C 125 ; WX 124 ; N bar ; B 95 95 95 95 +C 126 ; WX 125 ; N braceright ; B 96 96 96 96 +C 127 ; WX 126 ; N asciitilde ; B 97 97 97 97 +C 162 ; WX 161 ; N exclamdown ; B 98 98 98 98 +C 163 ; WX 162 ; N cent ; B 99 99 99 99 +C 164 ; WX 163 ; N sterling ; B 100 100 100 100 +C 165 ; WX 164 ; N fraction ; B 101 101 101 101 +C 165 ; WX 164 ; N fraction ; B 102 102 102 102 +C 166 ; WX 165 ; N yen ; B 103 103 103 103 +C 167 ; WX 166 ; N florin ; B 104 104 104 104 +C 168 ; WX 167 ; N section ; B 105 105 105 105 +C 169 ; WX 168 ; N currency ; B 106 106 106 106 +C 170 ; WX 169 ; N quotesingle ; B 107 107 107 107 +C 171 ; WX 170 ; N quotedblleft ; B 108 108 108 108 +C 172 ; WX 171 ; N guillemotleft ; B 109 109 109 109 +C 173 ; WX 172 ; N guilsinglleft ; B 110 110 110 110 +C 174 ; WX 173 ; N guilsinglright ; B 111 111 111 111 +C 175 ; WX 174 ; N fi ; B 112 112 112 112 +C 176 ; WX 175 ; N fl ; B 113 113 113 113 +C 178 ; WX 177 ; N endash ; B 114 114 114 114 +C 179 ; WX 178 ; N dagger ; B 115 115 115 115 +C 180 ; WX 179 ; N daggerdbl ; B 116 116 116 116 +C 181 ; WX 180 ; N periodcentered ; B 117 117 117 117 +C 181 ; WX 180 ; N periodcentered ; B 118 118 118 118 +C 183 ; WX 182 ; N paragraph ; B 119 119 119 119 +C 184 ; WX 183 ; N bullet ; B 120 120 120 120 +C 185 ; WX 184 ; N quotesinglbase ; B 121 121 121 121 +C 186 ; WX 185 ; N quotedblbase ; B 122 122 122 122 +C 187 ; WX 186 ; N quotedblright ; B 123 123 123 123 +C 188 ; WX 187 ; N guillemotright ; B 124 124 124 124 +C 189 ; WX 188 ; N ellipsis ; B 125 125 125 125 +C 190 ; WX 189 ; N perthousand ; B 126 126 126 126 +C 192 ; WX 191 ; N questiondown ; B 127 127 127 127 +C 194 ; WX 193 ; N grave ; B 128 128 128 128 +C 195 ; WX 194 ; N acute ; B 129 129 129 129 +C 196 ; WX 195 ; N circumflex ; B 130 130 130 130 +C 197 ; WX 196 ; N tilde ; B 131 131 131 131 +C 198 ; WX 197 ; N macron ; B 132 132 132 132 +C 198 ; WX 197 ; N macron ; B 133 133 133 133 +C 199 ; WX 198 ; N breve ; B 134 134 134 134 +C 200 ; WX 199 ; N dotaccent ; B 135 135 135 135 +C 201 ; WX 200 ; N dieresis ; B 136 136 136 136 +C 203 ; WX 202 ; N ring ; B 137 137 137 137 +C 204 ; WX 203 ; N cedilla ; B 138 138 138 138 +C 206 ; WX 205 ; N hungarumlaut ; B 139 139 139 139 +C 207 ; WX 206 ; N ogonek ; B 140 140 140 140 +C 208 ; WX 207 ; N caron ; B 141 141 141 141 +C 209 ; WX 208 ; N emdash ; B 142 142 142 142 +C 226 ; WX 225 ; N AE ; B 143 143 143 143 +C 228 ; WX 227 ; N ordfeminine ; B 144 144 144 144 +C 233 ; WX 232 ; N Lslash ; B 145 145 145 145 +C 234 ; WX 233 ; N Oslash ; B 146 146 146 146 +C 235 ; WX 234 ; N OE ; B 147 147 147 147 +C 236 ; WX 235 ; N ordmasculine ; B 148 148 148 148 +C 242 ; WX 241 ; N ae ; B 149 149 149 149 +C 246 ; WX 245 ; N dotlessi ; B 150 150 150 150 +C 249 ; WX 248 ; N lslash ; B 151 151 151 151 +C 250 ; WX 249 ; N oslash ; B 152 152 152 152 +C 251 ; WX 250 ; N oe ; B 153 153 153 153 +C 252 ; WX 251 ; N germandbls ; B 154 154 154 154 +EndCharMetrics diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTester.java b/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java index 3eb7a490d..aa0cbe841 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTester.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java @@ -49,7 +49,7 @@ import org.apache.fop.util.ConsoleEventListenerForTests; * Test driver class for FO tree tests. */ @RunWith(Parameterized.class) -public class FOTreeTester { +public class FOTreeTestCase { @BeforeClass public static void registerElementListObservers() { @@ -84,7 +84,7 @@ public class FOTreeTester { * * @param testFile the FO file to test */ - public FOTreeTester(File testFile) { + public FOTreeTestCase(File testFile) { fopFactory.addElementMapping(new TestElementMapping()); this.testFile = testFile; } diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java index b43576901..b74afefc5 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java @@ -22,26 +22,16 @@ package org.apache.fop.fotreetest; import org.junit.runner.RunWith; import org.junit.runners.Suite; -import org.apache.fop.fo.DelegatingFOEventHandlerTestCase; -import org.apache.fop.fo.flow.table.CollapsedConditionalBorderTestCase; -import org.apache.fop.fo.flow.table.IllegalRowSpanTestCase; -import org.apache.fop.fo.flow.table.RowGroupBuilderTestCase; -import org.apache.fop.fo.flow.table.TableColumnColumnNumberTestCase; -import org.apache.fop.fo.flow.table.TooManyColumnsTestCase; - /** * JUnit test suit for running layout engine test under JUnit control. */ @RunWith(Suite.class) @Suite.SuiteClasses({ - TooManyColumnsTestCase.class, - IllegalRowSpanTestCase.class, - RowGroupBuilderTestCase.class, - TableColumnColumnNumberTestCase.class, - CollapsedConditionalBorderTestCase.class, - FOTreeTester.class, - org.apache.fop.fo.properties.CommonAccessibilityHolderTestCase.class, - DelegatingFOEventHandlerTestCase.class + org.apache.fop.fo.flow.table.AllTests.class, + org.apache.fop.fo.pagination.AllTests.class, + org.apache.fop.fotreetest.FOTreeTestCase.class, + org.apache.fop.fo.properties.CommonAccessibilityHolderTestCase.class, + org.apache.fop.fo.DelegatingFOEventHandlerTestCase.class }) public final class FOTreeTestSuite { } diff --git a/test/java/org/apache/fop/intermediate/AbstractIFTestCase.java b/test/java/org/apache/fop/intermediate/AbstractIFTest.java index 7bdebd706..cdb7e0cf9 100644 --- a/test/java/org/apache/fop/intermediate/AbstractIFTestCase.java +++ b/test/java/org/apache/fop/intermediate/AbstractIFTest.java @@ -48,7 +48,7 @@ import org.apache.fop.render.intermediate.IFSerializer; /** * A common super-class for intermediate format test cases. */ -abstract class AbstractIFTestCase extends AbstractIntermediateTestCase { +abstract class AbstractIFTest extends AbstractIntermediateTest { private static final Schema IF_SCHEMA; @@ -89,7 +89,7 @@ abstract class AbstractIFTestCase extends AbstractIntermediateTestCase { * @param testFile the file containing the document and the tests * @throws IOException if an I/O error occurs while loading the test case */ - public AbstractIFTestCase(File testFile) throws IOException { + public AbstractIFTest(File testFile) throws IOException { super(testFile); } diff --git a/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java b/test/java/org/apache/fop/intermediate/AbstractIntermediateTest.java index 6705d7e3d..567d2adba 100644 --- a/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java +++ b/test/java/org/apache/fop/intermediate/AbstractIntermediateTest.java @@ -51,7 +51,7 @@ import org.apache.fop.util.ConsoleEventListenerForTests; /** * Abstract base class for intermediate format tests. */ -public abstract class AbstractIntermediateTestCase { +public abstract class AbstractIntermediateTest { /** the test environment */ protected static TestAssistant testAssistant = new TestAssistant(); @@ -76,7 +76,7 @@ public abstract class AbstractIntermediateTestCase { * @param testFile the test file to run * @throws IOException if an I/O error occurs while loading the test case */ - public AbstractIntermediateTestCase(File testFile) + public AbstractIntermediateTest(File testFile) throws IOException { this.testFile = testFile; } diff --git a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java index 6c06971e6..1f8abb9be 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -53,7 +53,7 @@ import org.w3c.dom.Document; * Tests the area tree parser. */ @RunWith(Parameterized.class) -public class AreaTreeParserTestCase extends AbstractIntermediateTestCase { +public class AreaTreeParserTestCase extends AbstractIntermediateTest { /** * Creates the parameters for this test. @@ -97,10 +97,9 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTestCase { Renderer targetRenderer = userAgent.getRendererFactory().createRenderer( userAgent, getTargetMIME()); - XMLRenderer renderer = new XMLRenderer(); + XMLRenderer renderer = new XMLRenderer(userAgent); renderer.mimicRenderer(targetRenderer); renderer.setContentHandler(handler); - renderer.setUserAgent(userAgent); userAgent.setRendererOverride(renderer); @@ -131,12 +130,10 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTestCase { TransformerHandler handler = testAssistant.getTransformerFactory().newTransformerHandler(); DOMResult domResult = new DOMResult(); handler.setResult(domResult); - XMLRenderer renderer = new XMLRenderer(); - renderer.setContentHandler(handler); - FOUserAgent userAgent = createUserAgent(); + XMLRenderer renderer = new XMLRenderer(userAgent); userAgent.setRendererOverride(renderer); - renderer.setUserAgent(userAgent); + renderer.setContentHandler(handler); FontInfo fontInfo = new FontInfo(); AreaTreeModel treeModel = new RenderPagesModel(userAgent, diff --git a/test/java/org/apache/fop/intermediate/IFParserTestCase.java b/test/java/org/apache/fop/intermediate/IFParserTestCase.java index 6ac20c556..7d4fb7ad8 100644 --- a/test/java/org/apache/fop/intermediate/IFParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/IFParserTestCase.java @@ -46,7 +46,7 @@ import org.apache.fop.render.intermediate.IFSerializer; * Tests the intermediate format parser. */ @RunWith(Parameterized.class) -public class IFParserTestCase extends AbstractIFTestCase { +public class IFParserTestCase extends AbstractIFTest { /** Set this to true to get the correspondence between test number and test file. */ private static final boolean DEBUG = false; diff --git a/test/java/org/apache/fop/intermediate/IFTestCase.java b/test/java/org/apache/fop/intermediate/IFTestCase.java index a6ff171e3..562302ba4 100644 --- a/test/java/org/apache/fop/intermediate/IFTestCase.java +++ b/test/java/org/apache/fop/intermediate/IFTestCase.java @@ -43,7 +43,7 @@ import org.w3c.dom.NodeList; * Test case for the IF output. */ @RunWith(Parameterized.class) -public class IFTestCase extends AbstractIFTestCase { +public class IFTestCase extends AbstractIFTest { /** * Gets the files for this test. diff --git a/test/java/org/apache/fop/layoutengine/HyphenationLayoutTestCase.java b/test/java/org/apache/fop/layoutengine/HyphenationLayoutTestCase.java new file mode 100644 index 000000000..6b5ebbf71 --- /dev/null +++ b/test/java/org/apache/fop/layoutengine/HyphenationLayoutTestCase.java @@ -0,0 +1,53 @@ +/* + * 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; +import java.io.IOException; +import java.util.Collection; + +import org.junit.runners.Parameterized.Parameters; + +/** + * Class for testing the FOP's hyphenation layout engine using testcases specified in XML + * files. + */ +public class HyphenationLayoutTestCase extends LayoutEngineTestCase { + + /** + * Creates the parameters for this test. + * + * @return the list of file arrays populated with test files + * @throws IOException if an I/O error occurs while reading the test file + */ + @Parameters + public static Collection<File[]> getParameters() throws IOException { + return LayoutEngineTestUtils.getLayoutTestFiles("hyphenation-testcases"); + } + + /** + * Constructor + * @param testFile the file to test + */ + public HyphenationLayoutTestCase(File testFile) { + super(testFile); + } + +} diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java index 33f621f84..6a0d424e9 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java @@ -70,7 +70,7 @@ import org.apache.fop.util.DelegatingContentHandler; * files. */ @RunWith(Parameterized.class) -public class LayoutEngineTester { +public class LayoutEngineTestCase { private static File areaTreeBackupDir; @BeforeClass @@ -108,7 +108,7 @@ public class LayoutEngineTester { * * @param testFile the test file */ - public LayoutEngineTester(File testFile) { + public LayoutEngineTestCase(File testFile) { this.ifTester = new IFTester(tfactory, areaTreeBackupDir); this.testFile = testFile; } @@ -150,8 +150,7 @@ public class LayoutEngineTester { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - XMLRenderer atrenderer = new XMLRenderer(); - atrenderer.setUserAgent(ua); + XMLRenderer atrenderer = new XMLRenderer(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); fop = effFactory.newFop(ua); @@ -208,8 +207,7 @@ public class LayoutEngineTester { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - IFRenderer ifRenderer = new IFRenderer(); - ifRenderer.setUserAgent(ua); + IFRenderer ifRenderer = new IFRenderer(ua); IFSerializer serializer = new IFSerializer(); serializer.setContext(new IFContext(ua)); diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java index 00a660999..2a70f255d 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestSuite.java @@ -27,6 +27,6 @@ import org.junit.runners.Suite.SuiteClasses; * JUnit test suit for running layout engine test under JUnit control. */ @RunWith(Suite.class) -@SuiteClasses({ LayoutEngineTester.class }) +@SuiteClasses({ LayoutEngineTestCase.class }) public class LayoutEngineTestSuite { } diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java index 772204d28..935b86c3b 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java @@ -172,15 +172,26 @@ public final class LayoutEngineTestUtils { * @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"; + return getLayoutTestFiles(testSet); + } + + /** + * This is a helper method that uses the standard parameters for FOP's layout engine tests, + * given a test set name returns a set of test files. + * + * @param testSetName the name of the test set + * @return A collection of file arrays that contain the test files + */ + public static Collection<File[]> getLayoutTestFiles(String testSetName) { + TestFilesConfiguration.Builder builder = new TestFilesConfiguration.Builder(); builder.testDir("test/layoutengine") .singleProperty("fop.layoutengine.single") .startsWithProperty("fop.layoutengine.starts-with") .suffix(".xml") - .testSet(testSet) + .testSet(testSetName) .disabledProperty("fop.layoutengine.disabled", "test/layoutengine/disabled-testcases.xml") .privateTestsProperty("fop.layoutengine.private"); diff --git a/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java b/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java new file mode 100644 index 000000000..b930a8b6d --- /dev/null +++ b/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java @@ -0,0 +1,92 @@ +/* + * 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.pdf; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for {@link AbstractPDFStream}. + */ +public class AbstractPDFStreamTestCase extends PDFObjectTestCase { + + private AbstractPDFStream abstractStream; + + private String textData = "This is an arbitrary string for testing."; + + private static byte[] encodedBytes; + static { + int[] encoded = { 0x78, 0x9c, 0x0b, 0xc9, 0xc8, 0x2c, 0x56, 0x00, 0xa2, 0xc4, 0x3c, 0x85, + 0xc4, 0xa2, 0xa4, 0xcc, 0x92, 0xa2, 0xc4, 0xa2, 0x4a, 0x85, 0xe2, 0x92, 0xa2, 0xcc, + 0xbc, 0x74, 0x85, 0xb4, 0xfc, 0x22, 0x85, 0x92, 0xd4, 0xe2, 0x12, 0x20, 0x5b, 0x0f, + 0x00, 0x2d, 0x2b, 0x0e, 0xde, 0x0a }; + encodedBytes = new byte[encoded.length]; + int i = 0; + for (int in : encoded) { + encodedBytes[i++] = (byte) (in & 0xff); + } + } + private String startStream = "1 0 obj\n" + + "<< /Length 5 0 R /Filter /FlateDecode >>\n" + + "stream\n"; + private String endStream = "endstream\nendobj\n"; + + @Before + public void setUp() { + abstractStream = new AbstractPDFStream() { + + @Override + protected void outputRawStreamData(OutputStream out) throws IOException { + out.write(textData.getBytes()); + } + + @Override + protected int getSizeHint() throws IOException { + return textData.length(); + } + }; + abstractStream.setDocument(doc); + abstractStream.setParent(parent); + + pdfObjectUnderTest = abstractStream; + } + + /** + * Tests output() - ensure that this object is correctly formatted to the output stream. + * @throws IOException if an I/O error occurs + */ + @Test + public void testOutput() throws IOException { + // This differs from most other objects, if the object number = 0 an exception is thrown + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + abstractStream.setObjectNumber(1); + ByteArrayOutputStream expectedStream = new ByteArrayOutputStream(); + expectedStream.write(startStream.getBytes()); + expectedStream.write(encodedBytes); + expectedStream.write(endStream.getBytes()); + assertEquals(expectedStream.size(), abstractStream.output(outStream)); + assertEquals(expectedStream.toString(), outStream.toString()); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFArrayTestCase.java b/test/java/org/apache/fop/pdf/PDFArrayTestCase.java new file mode 100644 index 000000000..418b2f1a9 --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFArrayTestCase.java @@ -0,0 +1,237 @@ +/* + * 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.pdf; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Test case for {@link PDFArray}. + */ +public class PDFArrayTestCase extends PDFObjectTestCase { + private PDFArray intArray; + private String intArrayOutput; + private PDFArray doubleArray; + private String doubleArrayOutput; + private PDFArray collectionArray; + private String collectionArrayOutput; + private PDFArray objArray; + private String objArrayOutput; + + /** A PDF object used solely for testing */ + private PDFNumber num; + + @Before + public void setUp() { + intArray = new PDFArray(parent, new int[] {1, 2, 3, 4, 5}); + intArrayOutput = "[1 2 3 4 5]"; + + doubleArray = new PDFArray(parent, new double[] {1.1, 2.2, 3.3, 4.4, 5.5}); + doubleArrayOutput = "[1.1 2.2 3.3 4.4 5.5]"; + + List<Object> strList = new ArrayList<Object>(); + strList.add("one"); + strList.add("two"); + strList.add("three"); + collectionArray = new PDFArray(parent, strList); + collectionArrayOutput = "[(one) (two) (three)]"; + + // Set arbitrary values here + num = new PDFNumber(); + num.setNumber(20); + num.setObjectNumber(4); + objArray = new PDFArray(parent, new Object[] {"one", 2, 3.0f, num}); + objArrayOutput = "[(one) 2 3 4 0 R]"; + + // set the document + intArray.setDocument(doc); + doubleArray.setDocument(doc); + collectionArray.setDocument(doc); + objArray.setDocument(doc); + + // Test the progenitor in the inheritance stack + objArray.setParent(parent); + pdfObjectUnderTest = objArray; + } + + private void intArrayContainsTests() { + for (int i = 1; i <= 5; i++) { + assertTrue(intArray.contains(i)); + } + assertFalse(intArray.contains(6)); + assertFalse(intArray.contains(0)); + } + + private void doubleArrayContainsTests() { + assertTrue(doubleArray.contains(1.1)); + assertTrue(doubleArray.contains(2.2)); + assertTrue(doubleArray.contains(3.3)); + assertTrue(doubleArray.contains(4.4)); + assertTrue(doubleArray.contains(5.5)); + assertFalse(doubleArray.contains(10.0)); + assertFalse(doubleArray.contains(0.0)); + } + + private void collectionArrayContainsTests() { + assertTrue(collectionArray.contains("one")); + assertTrue(collectionArray.contains("two")); + assertTrue(collectionArray.contains("three")); + assertFalse(collectionArray.contains("zero")); + assertFalse(collectionArray.contains("four")); + } + + private void objectArrayContainsTests() { + assertTrue(objArray.contains("one")); + assertTrue(objArray.contains(2)); + assertTrue(objArray.contains(3.0f)); + assertTrue(objArray.contains(num)); + assertFalse(objArray.contains("four")); + assertFalse(objArray.contains(0.0)); + } + + /** + * Test contains() - test whether this PDFArray contains an object. + */ + @Test + public void testContains() { + // Test some arbitrary values + intArrayContainsTests(); + doubleArrayContainsTests(); + collectionArrayContainsTests(); + objectArrayContainsTests(); + } + + /** + * Test length() - tests the length of an array. + */ + @Test + public void testLength() { + assertEquals(5, intArray.length()); + assertEquals(5, doubleArray.length()); + assertEquals(3, collectionArray.length()); + assertEquals(4, objArray.length()); + + // Test the count is incremented when an object is added (this only + // needs to be tested once) + intArray.add(6); + assertEquals(6, intArray.length()); + } + + /** + * Test set() - tests that a particular point has been properly set. + */ + @Test + public void testSet() { + PDFName name = new PDFName("zero test"); + objArray.set(0, name); + assertEquals(name, objArray.get(0)); + + objArray.set(1, "test"); + assertEquals("test", objArray.get(1)); + // This goes through the set(int, double) code path rather than set(int, Object) + objArray.set(2, 5); + assertEquals(5.0, objArray.get(2)); + try { + objArray.set(4, 2); + fail("out of bounds"); + } catch (IndexOutOfBoundsException e) { + // Pass + } + } + + /** + * Test get() - gets the object stored at a given index. + */ + @Test + public void testGet() { + // Test some arbitrary values + for (int i = 1; i <= 5; i++) { + assertEquals(i, intArray.get(i - 1)); + } + + assertEquals(1.1, doubleArray.get(0)); + assertEquals(2.2, doubleArray.get(1)); + assertEquals(3.3, doubleArray.get(2)); + assertEquals(4.4, doubleArray.get(3)); + assertEquals(5.5, doubleArray.get(4)); + + assertEquals("one", collectionArray.get(0)); + assertEquals("two", collectionArray.get(1)); + assertEquals("three", collectionArray.get(2)); + + assertEquals("one", objArray.get(0)); + assertEquals(2, objArray.get(1)); + assertEquals(0, Double.compare(3.0, (Float) objArray.get(2))); + assertEquals(num, objArray.get(3)); + } + + /** + * Tests add() - tests that objects are appended to the end of the array as expected. + */ + @Test + public void testAdd() { + intArray.add(new Integer(6)); + doubleArray.add(6.6); + // Test some arbitrary values + for (int i = 1; i <= 6; i++) { + assertEquals(i, intArray.get(i - 1)); + } + + assertEquals(1.1, doubleArray.get(0)); + assertEquals(2.2, doubleArray.get(1)); + assertEquals(3.3, doubleArray.get(2)); + assertEquals(4.4, doubleArray.get(3)); + assertEquals(5.5, doubleArray.get(4)); + assertEquals(6.6, doubleArray.get(5)); + + collectionArray.add(1); + assertEquals("one", collectionArray.get(0)); + assertEquals("two", collectionArray.get(1)); + assertEquals("three", collectionArray.get(2)); + assertEquals(1.0, collectionArray.get(3)); + + objArray.add("four"); + assertEquals("one", objArray.get(0)); + assertEquals(2, objArray.get(1)); + assertEquals(0, Double.compare(3.0, (Float) objArray.get(2))); + assertEquals("four", objArray.get(4)); + } + + /** + * Tests output() - tests that this object is properly streamed to the PDF document. + * @throws IOException error caused by I/O + */ + @Test + public void testOutput() throws IOException { + testOutputStreams(intArrayOutput, intArray); + testOutputStreams(doubleArrayOutput, doubleArray); + testOutputStreams(collectionArrayOutput, collectionArray); + testOutputStreams(objArrayOutput, objArray); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFDestsTestCase.java b/test/java/org/apache/fop/pdf/PDFDestsTestCase.java new file mode 100644 index 000000000..08d841ede --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFDestsTestCase.java @@ -0,0 +1,64 @@ +/* + * 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.pdf; + +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Test case for {@link PDFDests}. + */ +public class PDFDestsTestCase extends PDFObjectTestCase { + + private PDFDests dests = new PDFDests(); + private String expectedString = "<< /Names [(number) 10 (name) /Test#20name] >>\n"; + + @Before + public void setUp() { + List<PDFDestination> destinations = new ArrayList<PDFDestination>(); + PDFNumber number = new PDFNumber(); + number.setNumber(10); + PDFDestination testNumber = new PDFDestination("number", number); + testNumber.setDocument(doc); + destinations.add(testNumber); + PDFDestination testName = new PDFDestination("name", new PDFName("Test name")); + testName.setDocument(doc); + destinations.add(testName); + + dests = new PDFDests(destinations); + dests.setDocument(doc); + dests.setParent(parent); + pdfObjectUnderTest = dests; + } + + /** + * Populate the object with some arbitrary values and ensure they are wrapped properly. + * @throws IOException if an I/O error occurs + */ + @Test + public void testConstructor() throws IOException { + // Seems the only way to test this is by testing the output + testOutputStreams(expectedString, dests); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFDictionaryTestCase.java b/test/java/org/apache/fop/pdf/PDFDictionaryTestCase.java new file mode 100644 index 000000000..3f84fac2e --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFDictionaryTestCase.java @@ -0,0 +1,135 @@ +/* + * 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.pdf; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.apache.commons.io.output.CountingOutputStream; +import org.junit.Before; +import org.junit.Test; + + +/** + * Test case for {@link PDFDictionary}. + */ +public class PDFDictionaryTestCase extends PDFObjectTestCase { + /** The test subject */ + private PDFDictionary pdfDictUnderTest; + private PDFArray testArray; + private PDFNumber testNumber; + /** The order in which these objects are put into the dictionary MUST be maintained. */ + private String expectedOutput = "<<\n" + + " /String (TestValue)\n" + + " /int 10\n" + + " /double 3.1\n" + + " /array [1 (two) 20]\n" + + " /number 20\n" + + " /null null\n" + + ">>\n"; + + @Before + public void setUp() { + // A PDFNumber for testing, this DOES have a parent + testNumber = new PDFNumber(); + testNumber.setParent(parent); + testNumber.setNumber(20); + // An array for testing, this DOES NOT have a parent + testArray = new PDFArray(); + testArray.add(1); + testArray.add("two"); + testArray.add(testNumber); + // Populating the dictionary with a parent, document and the various objects + pdfDictUnderTest = new PDFDictionary(parent); + pdfDictUnderTest.setDocument(doc); + pdfDictUnderTest.put("String", "TestValue"); + pdfDictUnderTest.put("int", 10); + pdfDictUnderTest.put("double", Double.valueOf(3.1)); + pdfDictUnderTest.put("array", testArray); + pdfDictUnderTest.put("number", testNumber); + // null is a valid PDF object + pdfDictUnderTest.put("null", null); + // test that the interface is maintained + pdfObjectUnderTest = pdfDictUnderTest; + } + + /** + * Tests put() - tests that the object is put into the dictionary and it is handled if it is a + * {@link PDFObject}. + */ + @Test + public void testPut() { + // The "put()" commands have already been done in setUp(), so just test them. + assertEquals("TestValue", pdfDictUnderTest.get("String")); + assertEquals(10, pdfDictUnderTest.get("int")); + assertEquals(3.1, pdfDictUnderTest.get("double")); + // With PDFObjects, if they DO NOT have a parent, the dict becomes their parent. + assertEquals(testArray, pdfDictUnderTest.get("array")); + assertEquals(pdfDictUnderTest, testArray.getParent()); + // With PDFObjects, if they DO have a parent, the dict DOES NOT change the parent object. + assertEquals(testNumber, pdfDictUnderTest.get("number")); + // Test it doesn't explode when we try to get a non-existent entry + assertNull(pdfDictUnderTest.get("Not in dictionary")); + // Tests that we can over-write objects + pdfDictUnderTest.put("array", 10); + assertEquals(10, pdfDictUnderTest.get("array")); + // Test that nulls are handled appropriately + assertNull(pdfDictUnderTest.get("null")); + } + + /** + * Tests get() - tests that objects can be properly retrieved from the dictionary. + */ + @Test + public void testGet() { + // Tested fairly comprehensively in testPut(). + } + + /** + * Tests writeDictionary() - tests that the dictionary is properly written to the output-stream. + */ + @Test + public void testWriteDictionary() { + // Ensure that the objects stored in the dictionary are streamed in the correct format. + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + CountingOutputStream cout = new CountingOutputStream(outStream); + StringBuilder textBuffer = new StringBuilder(); + try { + pdfDictUnderTest.writeDictionary(cout, textBuffer); + PDFDocument.flushTextBuffer(textBuffer, cout); + assertEquals(expectedOutput, outStream.toString()); + } catch (IOException e) { + fail("IOException: " + e.getMessage()); + } + } + + /** + * Tests output() - test that this object can write itself to an output stream. + * @throws IOException error caused by I/O + */ + @Test + public void testOutput() throws IOException { + testOutputStreams(expectedOutput, pdfDictUnderTest); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java b/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java new file mode 100644 index 000000000..f65d73872 --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java @@ -0,0 +1,62 @@ +/* + * 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.pdf; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Test case for {@link PDFDocument} + */ +public class PDFDocumentTestCase { + + /** + * Test flushTextBuffer() - ensure that the text given will stream to the PDF document as + * expected. + * @throws IOException when an I/O error occurs + */ + @Test + public void testFlushTextBuffer() throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + StringBuilder textBuffer = new StringBuilder(); + String testString = "This is a test string, just some arbitrary data."; + textBuffer.append(testString); + + PDFDocument.flushTextBuffer(textBuffer, out); + assertEquals(testString, out.toString()); + + // Should reset the textBuffer + assertEquals(0, textBuffer.length()); + assertEquals("", textBuffer.toString()); + out.reset(); + + String[] strArray = { "Try ", "with ", "multiple ", "strings." }; + for (String str : strArray) { + textBuffer.append(str); + } + String fullString = textBuffer.toString(); + PDFDocument.flushTextBuffer(textBuffer, out); + assertEquals(fullString, out.toString()); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFLibraryTestSuite.java b/test/java/org/apache/fop/pdf/PDFLibraryTestSuite.java new file mode 100644 index 000000000..4df325969 --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFLibraryTestSuite.java @@ -0,0 +1,54 @@ +/* + * 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.pdf; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + * Test suite for FOP's utility classes. + */ +public class PDFLibraryTestSuite { + + /** + * Builds the test suite + * @return the test suite + */ + public static Test suite() { + TestSuite suite = new TestSuite( + "Test suite for FOP's utility classes"); + //$JUnit-BEGIN$ + suite.addTest(new TestSuite(PDFArrayTestCase.class)); + suite.addTest(new TestSuite(PDFDictionaryTestCase.class)); + suite.addTest(new TestSuite(PDFNumberTestCase.class)); + suite.addTest(new TestSuite(PDFObjectTestCase.class)); + suite.addTest(new TestSuite(PDFNameTestCase.class)); + suite.addTest(new TestSuite(AbstractPDFStreamTestCase.class)); + suite.addTest(new TestSuite(PDFDestsTestCase.class)); + suite.addTest(new TestSuite(PDFDocumentTestCase.class)); + suite.addTest(new TestSuite(PDFNullTestCase.class)); + suite.addTest(new TestSuite(PDFNumsArrayTestCase.class)); + suite.addTest(new TestSuite(PDFRectangleTestCase.class)); + suite.addTest(new TestSuite(PDFReferenceTestCase.class)); + //$JUnit-END$ + return suite; + } +} diff --git a/test/java/org/apache/fop/pdf/PDFNameTestCase.java b/test/java/org/apache/fop/pdf/PDFNameTestCase.java new file mode 100644 index 000000000..80917f416 --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFNameTestCase.java @@ -0,0 +1,169 @@ +/* + * 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.pdf; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.apache.commons.io.output.CountingOutputStream; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; + +/** + * Test class for {@link PDFName}. + */ +public class PDFNameTestCase extends PDFObjectTestCase { + private PDFName pdfName; + + /** + * Sets up the local variables + */ + @Before + public void setUp() { + pdfName = new PDFName("TestName"); + pdfName.setParent(parent); + pdfName.setDocument(doc); + + pdfObjectUnderTest = pdfName; + } + + /** + * Tests escapeName() - tests that this method escapes the necessary characters. + */ + @Test + public void testEscapeName() { + try { + // Test for null, this is a programming error thus the NPE + PDFName.escapeName(null); + fail("NPE not thrown when null object given to escapeName()"); + } catch (NullPointerException e) { + // PASS + } + // All names are prefixed by "/", check the PDF spec for further details. + assertEquals("/Test", PDFName.escapeName("Test")); + // Check that if the name is already prefixed with "/" it doens't do it twice + assertEquals("/Test", PDFName.escapeName("/Test")); + // Test with a space in the middle + assertEquals("/Test#20test", PDFName.escapeName("Test test")); + // Test that all chars apart from ASCII '!' --> '~' are escaped + nonEscapedCharactersTests(); + escapedCharactersTests(); + } + + private void escapedCharactersTests() { + for (char i = 0; i < '!'; i++) { + String str = Integer.toHexString(i >>> 4 & 0x0f).toUpperCase(); + str += Integer.toHexString(i & 0x0f).toUpperCase(); + assertEquals("/#" + str, PDFName.escapeName(String.valueOf(i))); + } + for (char i = '~' + 1; i < 256; i++) { + String str = Integer.toHexString(i >>> 4 & 0x0f).toUpperCase(); + str += Integer.toHexString(i & 0x0f).toUpperCase(); + assertEquals("/#" + str, PDFName.escapeName(String.valueOf(i))); + } + checkCharacterIsEscaped('#'); + checkCharacterIsEscaped('%'); + checkCharacterIsEscaped('('); + checkCharacterIsEscaped(')'); + checkCharacterIsEscaped('<'); + checkCharacterIsEscaped('>'); + checkCharacterIsEscaped('['); + checkCharacterIsEscaped(']'); + checkCharacterIsEscaped('>'); + } + + private void checkCharacterIsEscaped(char c) { + String str = Integer.toHexString(c >>> 4 & 0x0f).toUpperCase(); + str += Integer.toHexString(c & 0x0f).toUpperCase(); + assertEquals("/#" + str, PDFName.escapeName(String.valueOf(c))); + } + + private void nonEscapedCharactersTests() { + charactersNotEscapedBetween('!', '"'); + charactersNotEscapedBetween('*', ';'); + charactersNotEscapedBetween('?', 'Z'); + charactersNotEscapedBetween('^', '~'); + } + + private void charactersNotEscapedBetween(char c1, char c2) { + for (char i = c1; i <= c2; i++) { + String str = String.valueOf(i); + String expected = !str.equals("/") ? "/" + str : str; + assertEquals(expected, PDFName.escapeName(str)); + } + } + + /** + * Tests toString() - this has been overridden to return the String that PDFName wraps. + */ + @Test + public void testToString() { + // The escape characters have already been tested in testEscapeName() so this doesn't need + // to be done twice. + PDFName test1 = new PDFName("test1"); + assertEquals("/test1", test1.toString()); + PDFName test2 = new PDFName("another test"); + assertEquals("/another#20test", test2.toString()); + try { + new PDFName(null); + fail("NPE not thrown when null passed to constructor"); + } catch (NullPointerException e) { + // PASS + } + } + + /** + * Tests output() - check that this object can stream itself in the correct format. + * @throws IOException error caused by I/O + */ + @Test + public void testOutput() throws IOException { + testOutputStreams("/TestName", pdfName); + testOutputStreams("/test#20test", new PDFName("test test")); + } + + /** + * Test outputInline() - this writes the object reference if it is a direct object (has an + * object number), or writes the String representation if there is no object number. + */ + @Test + public void testOutputInline() { + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + CountingOutputStream cout = new CountingOutputStream(outStream); + StringBuilder textBuffer = new StringBuilder(); + try { + // test with no object number set. + pdfName.outputInline(outStream, textBuffer); + PDFDocument.flushTextBuffer(textBuffer, cout); + assertEquals("/TestName", outStream.toString()); + + outStream.reset(); + // test with object number set + pdfName.setObjectNumber(1); + pdfName.outputInline(outStream, textBuffer); + PDFDocument.flushTextBuffer(textBuffer, cout); + assertEquals("1 0 R", outStream.toString()); + } catch (IOException e) { + fail("IOException: " + e.getMessage()); + } + } +} diff --git a/test/java/org/apache/fop/pdf/PDFNullTestCase.java b/test/java/org/apache/fop/pdf/PDFNullTestCase.java new file mode 100644 index 000000000..98427cd20 --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFNullTestCase.java @@ -0,0 +1,49 @@ +/* + * 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.pdf; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Test case for {@link PDFNull}. + */ +public class PDFNullTestCase extends PDFObjectTestCase { + + /** + * Test outputInline() - test that "null" is printed to the output stream. + */ + @Test + public void testOutputInline() throws IOException { + PDFNull obj = PDFNull.INSTANCE; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + StringBuilder text = new StringBuilder(); + obj.outputInline(out, text); + assertEquals("null", text.toString()); + + // Ensure previously written text is not discarded + obj.outputInline(out, text); + assertEquals("nullnull", text.toString()); + } +} diff --git a/test/java/org/apache/fop/util/PDFNumberTestCase.java b/test/java/org/apache/fop/pdf/PDFNumberTestCase.java index 73eb6fd77..ed660af8d 100644 --- a/test/java/org/apache/fop/util/PDFNumberTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFNumberTestCase.java @@ -17,18 +17,29 @@ /* $Id$ */ -package org.apache.fop.util; +package org.apache.fop.pdf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import org.apache.fop.pdf.PDFNumber; +import org.junit.Before; import org.junit.Test; +import java.io.IOException; + /** * This test tests PDFNumber's doubleOut() methods. */ -public class PDFNumberTestCase { +public class PDFNumberTestCase extends PDFObjectTestCase { + /** + * Sets up the local variables, most of these are inherited from PDFObjectTestCase + */ + @Before + public void setUp() { + pdfObjectUnderTest = new PDFNumber(); + pdfObjectUnderTest.setParent(parent); + pdfObjectUnderTest.setDocument(doc); + } /** * Tests PDFNumber.doubleOut(). @@ -54,7 +65,6 @@ public class PDFNumberTestCase { * Tests PDFNumber.doubleOut(). * @throws Exception if the test fails */ - @Test public void testDoubleOut2() throws Exception { //4 decimal digits in this case assertEquals("0", PDFNumber.doubleOut(0.0f, 4)); @@ -70,7 +80,6 @@ public class PDFNumberTestCase { * Tests PDFNumber.doubleOut(). * @throws Exception if the test fails */ - @Test public void testDoubleOut3() throws Exception { //0 decimal digits in this case assertEquals("0", PDFNumber.doubleOut(0.0f, 0)); @@ -84,7 +93,6 @@ public class PDFNumberTestCase { * Tests PDFNumber.doubleOut(). Special cases (former bugs). * @throws Exception if the test fails */ - @Test public void testDoubleOut4() throws Exception { double d = Double.parseDouble("5.7220458984375E-6"); assertEquals("0.000006", PDFNumber.doubleOut(d)); @@ -96,7 +104,6 @@ public class PDFNumberTestCase { * Tests PDFNumber.doubleOut(). Tests for wrong parameters. * @throws Exception if the test fails */ - @Test public void testDoubleOutWrongParameters() throws Exception { try { PDFNumber.doubleOut(0.1f, -1); @@ -116,6 +123,40 @@ public class PDFNumberTestCase { } catch (IllegalArgumentException iae) { //we want that } + try { + PDFNumber.doubleOut(null); + fail("NullPointer expected!"); + } catch (NullPointerException e) { + // PASS + } + } + + /** + * Tests both getNumber() and setNumber() - basic getter/setter methods... Why there isn't a + * constructor is beyond me... + */ + public void testGetSetNumber() { + PDFNumber pdfNum = new PDFNumber(); + // Check with a floating point number + pdfNum.setNumber(1.111f); + assertEquals(1.111f, pdfNum.getNumber()); + // try with an int + pdfNum.setNumber(2); + assertEquals(2, pdfNum.getNumber()); + // See what happens with a null... make sure it doesn't explode + pdfNum.setNumber(null); + assertEquals(null, pdfNum.getNumber()); } + /** + * Tests toPDFString() - this serializes PDFNumber to PDF format. + * @throws IOException error caused by I/O + */ + public void testToPDFString() throws IOException { + PDFNumber testSubject = new PDFNumber(); + testSubject.setNumber(1.0001); + testOutputStreams("1.0001", testSubject); + testSubject.setNumber(999); + testOutputStreams("999", testSubject); + } } diff --git a/test/java/org/apache/fop/pdf/PDFNumsArrayTestCase.java b/test/java/org/apache/fop/pdf/PDFNumsArrayTestCase.java new file mode 100644 index 000000000..e0dca33bf --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFNumsArrayTestCase.java @@ -0,0 +1,54 @@ +/* + * 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.pdf; + +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +/** + * Test case for {@link PDFNumsArray}. + */ +public class PDFNumsArrayTestCase extends PDFObjectTestCase { + private PDFNumsArray numsArray; + private String expectedString = "[0 /Test#20name 1 10]"; + + @Before + public void setUp() { + numsArray = new PDFNumsArray(parent); + numsArray.put(0, new PDFName("Test name")); + PDFNumber num = new PDFNumber(); + num.setNumber(10); + numsArray.put(1, num); + numsArray.setDocument(doc); + + pdfObjectUnderTest = numsArray; + } + + /** + * Test output() - ensure that this object is properly outputted to the PDF document. + * @throws IOException if an I/O error occurs + */ + @Test + public void testOutput() throws IOException { + testOutputStreams(expectedString, numsArray); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFObjectTestCase.java b/test/java/org/apache/fop/pdf/PDFObjectTestCase.java index 2e1f452af..ee9512d88 100644 --- a/test/java/org/apache/fop/pdf/PDFObjectTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFObjectTestCase.java @@ -20,43 +20,136 @@ package org.apache.fop.pdf; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import org.junit.Before; import org.junit.Test; /** * Tests the PDFObject class. */ public class PDFObjectTestCase { + /** The document behind this object */ + protected final PDFDocument doc = new PDFDocument("test"); + /** The parent of this object */ + protected final PDFObject parent = new DummyPDFObject(); + /** The test subject */ + protected PDFObject pdfObjectUnderTest; + /** The string to begin describing the object <code>"1 0 obj\n"</code> */ + protected final String beginObj = "1 0 obj\n"; + /** The string to end describing the object <code>"\nendobj\n"</code> */ + protected final String endObj = "\nendobj\n"; + + private static class DummyPDFObject extends PDFObject { + + }; + + @Before + public void setUp() { + pdfObjectUnderTest = new DummyPDFObject(); + pdfObjectUnderTest.setDocument(doc); + pdfObjectUnderTest.setParent(parent); + } /** - * Tests date/time formatting in PDFObject. - * @throws Exception if an error occurs + * Tests setObjectNumber() + */ + @Test + public void testSetObjectNumber() { + pdfObjectUnderTest.setObjectNumber(1); + assertEquals(1, pdfObjectUnderTest.getObjectNumber()); + + pdfObjectUnderTest.setObjectNumber(5); + assertEquals(5, pdfObjectUnderTest.getObjectNumber()); + } + + /** + * Tests hasObjectNumber() - returns the object number of the underlying PDF object. + */ + @Test + public void testHasObjectNumber() { + assertFalse(pdfObjectUnderTest.hasObjectNumber()); + + pdfObjectUnderTest.setObjectNumber(1); + assertTrue(pdfObjectUnderTest.hasObjectNumber()); + } + + /** + * Tests getGeneration() - returns the generation number of the underlying PDF object. + */ + @Test + public void testGetGeneration() { + // Default should be 0 + assertEquals(0, pdfObjectUnderTest.getGeneration()); + // apparently there is no way to set this to anything other than 0 + } + + /** + * Tests setDocument() - returns the document to which this object is bound. */ @Test - public void testDateFormatting() throws Exception { - Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH); - cal.set(2008, Calendar.FEBRUARY, 07, 15, 11, 07); - cal.set(Calendar.MILLISECOND, 0); - Date dt = cal.getTime(); - - MyPDFObject obj = new MyPDFObject(); - String s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT")); - assertEquals("D:20080207151107Z", s); - s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT+02:00")); - assertEquals("D:20080207171107+02'00'", s); - s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT+02:30")); - assertEquals("D:20080207174107+02'30'", s); - s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT-08:00")); - assertEquals("D:20080207071107-08'00'", s); + public void testSetDocument() { + assertEquals(doc, pdfObjectUnderTest.getDocument()); + // assign a different document to the object and test (this should be immutable but isn't) + PDFDocument anotherDoc = new PDFDocument("another test"); + pdfObjectUnderTest.setDocument(anotherDoc); + assertEquals(anotherDoc, pdfObjectUnderTest.getDocument()); } - private class MyPDFObject extends PDFObject { + /** + * Tests setParent() - assigns the object a parent. + */ + @Test + public void testSetParent() { + assertEquals(parent, pdfObjectUnderTest.getParent()); + // assign another parent (this probably shouldn't me mutable) + DummyPDFObject anotherParent = new DummyPDFObject(); + pdfObjectUnderTest.setParent(anotherParent); + assertEquals(anotherParent, pdfObjectUnderTest.getParent()); + } + /** + * Test getObjectID() - returns the PDF object ID. + */ + @Test + public void testGetObjectID() { + pdfObjectUnderTest.setObjectNumber(10); + // String is of the format "<object#> <generation#> obj\n" + assertEquals("10 0 obj\n", pdfObjectUnderTest.getObjectID()); + } + + /** + * Test referencePDF() - returns a {@link String} in PDF format to reference this object. + */ + @Test + public void testReferencePDF() { + try { + pdfObjectUnderTest.referencePDF(); + fail("The object number is not set, an exception should be thrown"); + } catch (IllegalArgumentException e) { + // PASS + } + pdfObjectUnderTest.setObjectNumber(10); + // Referencing this object is in the format "<obj#> <gen#> R" + assertEquals("10 0 R", pdfObjectUnderTest.referencePDF()); + } + + /** + * Test makeReference() - returns this object represented as a {@link PDFReference}. + */ + @Test + public void testMakeReference() { + // Not very intelligent but, there's not much to test here + pdfObjectUnderTest.setObjectNumber(10); + PDFReference ref = pdfObjectUnderTest.makeReference(); + assertEquals(pdfObjectUnderTest.getObjectNumber(), ref.getObjectNumber()); + assertEquals(pdfObjectUnderTest, ref.getObject()); + assertEquals(pdfObjectUnderTest.referencePDF(), ref.toString()); } /** @@ -78,4 +171,32 @@ public class PDFObjectTestCase { assertEquals(ref.toString(), "8 0 R"); } + /** + * A generic method to test output() for sub-classes of (@link PDFObject}. The expected String + * should be formatted such that the object number and object descriptor aren't printed i.e. + * for a simple integer object in PDF: + * <pre> + * 1 0 obj ** ommited from expectedString + * 10 + * endobj ** ommited from expectedString + * </pre> + * Thus the expected string would be "10". + * @param expectedString the string that is expected. + * @param object the object being tested + * @throws IOException error with I/O + */ + protected void testOutputStreams(String expectedString, PDFObject object) throws IOException { + // Test both with and without object numbers + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + // Ensure that + object.setObjectNumber(0); + assertEquals(expectedString.length(), object.output(outStream)); + assertEquals(expectedString, outStream.toString()); + outStream.reset(); + object.setObjectNumber(1); + // Test the length of the output string is returned correctly. + String string = beginObj + expectedString + endObj; + assertEquals(string.length(), object.output(outStream)); + assertEquals(string, outStream.toString()); + } } diff --git a/test/java/org/apache/fop/pdf/PDFRectangleTestCase.java b/test/java/org/apache/fop/pdf/PDFRectangleTestCase.java new file mode 100644 index 000000000..24b6a1c71 --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFRectangleTestCase.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.pdf; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * Test case for {@link PDFRectangle}. + */ +public class PDFRectangleTestCase { + + /** + * Test outputInline() - ensure properly formatted co-ords are printed to the output stream. + * @throws IOException if an I/O error occurs + */ + @Test + public void testOutputInline() throws IOException { + OutputStream out = new ByteArrayOutputStream(); + // These are arbitrary values thus have no meaning + PDFRectangle rect = new PDFRectangle(1, 2, 3, 4); + + StringBuilder textBuffer = new StringBuilder(); + // Ensure text before the outputInline() is maintained + textBuffer.append("Test "); + + rect.outputInline(out, textBuffer); + assertEquals("Test [1 2 3 4]", textBuffer.toString()); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFReferenceTestCase.java b/test/java/org/apache/fop/pdf/PDFReferenceTestCase.java new file mode 100644 index 000000000..a2c6193cf --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFReferenceTestCase.java @@ -0,0 +1,64 @@ +/* + * 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.pdf; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Test case for {@link PDFReference}. + */ +public class PDFReferenceTestCase { + + /** + * Tests outputInline() - ensure that this object is properly formatted when printed to the + * output stream. + * @throws IOException if an I/O error occurs + */ + @Test + public void testOutputInline() throws IOException { + PDFName name = new PDFName("Test name"); + name.setObjectNumber(2); + PDFReference pdfRef = new PDFReference(name); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + StringBuilder textBuffer = new StringBuilder(); + // Ensure that text before outputInline() is kept + textBuffer.append("Text "); + + pdfRef.outputInline(out, textBuffer); + assertEquals("Text 2 0 R", textBuffer.toString()); + } + + /** + * Tests toString() - since this is used quite a lot, we have to ensure the format is correct. + */ + @Test + public void testToString() { + PDFName name = new PDFName("arbitrary"); + name.setObjectNumber(10); + PDFReference ref = new PDFReference(name); + assertEquals("10 0 R", ref.toString()); + } +} diff --git a/test/java/org/apache/fop/render/AbstractRenderingTestCase.java b/test/java/org/apache/fop/render/AbstractRenderingTest.java index 9eecfb106..1f91f5b06 100644 --- a/test/java/org/apache/fop/render/AbstractRenderingTestCase.java +++ b/test/java/org/apache/fop/render/AbstractRenderingTest.java @@ -41,7 +41,7 @@ import org.apache.fop.apps.MimeConstants; /** * Abstract base class for rendering (output) verification tests. */ -public abstract class AbstractRenderingTestCase { +public abstract class AbstractRenderingTest { private static final Map<String, String> MIME_MAP = new java.util.HashMap<String, String>(); diff --git a/test/java/org/apache/fop/render/RendererFactoryTest.java b/test/java/org/apache/fop/render/RendererFactoryTestCase.java index 4f1c50986..9ca4c2545 100644 --- a/test/java/org/apache/fop/render/RendererFactoryTest.java +++ b/test/java/org/apache/fop/render/RendererFactoryTestCase.java @@ -22,7 +22,10 @@ package org.apache.fop.render; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import org.junit.Test; + import org.apache.commons.io.output.NullOutputStream; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; @@ -34,12 +37,11 @@ import org.apache.fop.render.intermediate.IFDocumentHandler; import org.apache.fop.render.intermediate.IFRenderer; import org.apache.fop.render.pdf.PDFDocumentHandler; import org.apache.fop.render.rtf.RTFHandler; -import org.junit.Test; /** * Tests for {@link RendererFactory}. */ -public class RendererFactoryTest { +public class RendererFactoryTestCase { @Test public void testDocumentHandlerLevel() throws Exception { @@ -51,7 +53,6 @@ public class RendererFactoryTest { ua = fopFactory.newFOUserAgent(); handler = factory.createDocumentHandler(ua, MimeConstants.MIME_PDF); - assertTrue(handler instanceof PDFDocumentHandler); ua = fopFactory.newFOUserAgent(); overrideHandler = new PDFDocumentHandler(); diff --git a/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java b/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java new file mode 100644 index 000000000..7c08e6d99 --- /dev/null +++ b/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java @@ -0,0 +1,92 @@ +/* + * 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.render.afp; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import org.apache.fop.afp.AFPPaintingState; +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; + +/** + * Test case for {@link AFPRendererConfigurator}. + */ +public class AFPRendererConfiguratorTestCase { + private static FOUserAgent userAgent; + + private AFPRendererConfigurator sut; + + /** + * The FOUserAgent only needs to be created once. + */ + @BeforeClass + public static void createUserAgent() { + userAgent = FopFactory.newInstance().newFOUserAgent(); + } + + /** + * Assigns an FOUserAgen with a config file at <code>uri</code> + * + * @param uri the URI of the config file + */ + private void setConfigFile(String uri) { + String confTestsDir = "test/resources/conf/afp/"; + try { + userAgent.getFactory().setUserConfig(confTestsDir + uri); + sut = new AFPRendererConfigurator(userAgent); + } catch (IOException ioe) { + fail("IOException: " + ioe); + } catch (SAXException se) { + fail("SAXException: " + se); + } + } + + /** + * Test several config files relating to JPEG images in AFP. + * + * @throws FOPException if an error is thrown + */ + @Test + public void testJpegImageConfig() throws FOPException { + testJpegSettings("no_image_config.xconf", 1.0f, false); + testJpegSettings("can_embed_jpeg.xconf", 1.0f, true); + testJpegSettings("bitmap_encode_quality.xconf", 0.5f, false); + } + + private void testJpegSettings(String uri, float bitmapEncodingQual, boolean canEmbed) + throws FOPException { + AFPDocumentHandler docHandler = new AFPDocumentHandler(); + + setConfigFile(uri); + sut.configure(docHandler); + + AFPPaintingState paintingState = docHandler.getPaintingState(); + assertEquals(bitmapEncodingQual, paintingState.getBitmapEncodingQuality(), 0.01f); + assertEquals(canEmbed, paintingState.canEmbedJpeg()); + } +} diff --git a/test/java/org/apache/fop/render/afp/AFPTestSuite.java b/test/java/org/apache/fop/render/afp/AFPTestSuite.java index 16b6651a6..117e7efcf 100644 --- a/test/java/org/apache/fop/render/afp/AFPTestSuite.java +++ b/test/java/org/apache/fop/render/afp/AFPTestSuite.java @@ -27,6 +27,8 @@ import org.junit.runners.Suite.SuiteClasses; * Test suite for FOP's AFP output. */ @RunWith(Suite.class) -@SuiteClasses({ NoOperationTestCase.class }) +@SuiteClasses({ + NoOperationTestCase.class, + AFPRendererConfiguratorTestCase.class }) public class AFPTestSuite { } diff --git a/test/java/org/apache/fop/render/afp/AbstractAFPTestCase.java b/test/java/org/apache/fop/render/afp/AbstractAFPTest.java index 7f081a4d0..916c68395 100644 --- a/test/java/org/apache/fop/render/afp/AbstractAFPTestCase.java +++ b/test/java/org/apache/fop/render/afp/AbstractAFPTest.java @@ -23,12 +23,12 @@ import java.io.File; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.render.AbstractRenderingTestCase; +import org.apache.fop.render.AbstractRenderingTest; /** * Abstract base class for AFP verification tests. */ -abstract class AbstractAFPTestCase extends AbstractRenderingTestCase { +abstract class AbstractAFPTest extends AbstractRenderingTest { /** * Renders a test file. diff --git a/test/java/org/apache/fop/render/afp/NoOperationTestCase.java b/test/java/org/apache/fop/render/afp/NoOperationTestCase.java index eadc14f48..78578a2b6 100644 --- a/test/java/org/apache/fop/render/afp/NoOperationTestCase.java +++ b/test/java/org/apache/fop/render/afp/NoOperationTestCase.java @@ -37,7 +37,7 @@ import org.junit.Test; /** * Tests generation of afp:no-operation (NOPs). */ -public class NoOperationTestCase extends AbstractAFPTestCase { +public class NoOperationTestCase extends AbstractAFPTest { /** * Tests afp:no-operation. diff --git a/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java b/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTestCase.java index 7ec515ece..6e48845c1 100644 --- a/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTest.java +++ b/test/java/org/apache/fop/render/extensions/prepress/PageBoundariesTestCase.java @@ -31,7 +31,7 @@ import org.junit.Test; /** * Tests for the fox:bleed, fox:crop-offset, fox:crop-box extension properties. */ -public class PageBoundariesTest { +public class PageBoundariesTestCase { private static final Dimension TEST_AREA_SIZE = new Dimension(20000, 15000); diff --git a/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java b/test/java/org/apache/fop/render/extensions/prepress/PageScaleTestCase.java index 0908e869e..ff07e63ce 100644 --- a/test/java/org/apache/fop/render/extensions/prepress/PageScaleTest.java +++ b/test/java/org/apache/fop/render/extensions/prepress/PageScaleTestCase.java @@ -30,7 +30,7 @@ import org.junit.Test; /** * Tests for the fox:scale extension property. */ -public class PageScaleTest { +public class PageScaleTestCase { /** 1 value is used for both x and y. */ @Test diff --git a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java b/test/java/org/apache/fop/render/pdf/BasePDFTest.java index 256f78839..09db7538d 100644 --- a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java +++ b/test/java/org/apache/fop/render/pdf/BasePDFTest.java @@ -30,7 +30,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.fop.AbstractFOPTestCase; +import org.apache.fop.AbstractFOPTest; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; @@ -40,7 +40,7 @@ import org.xml.sax.SAXException; /** * Base class for automated tests that create PDF files */ -public class BasePDFTestCase extends AbstractFOPTestCase { +public class BasePDFTest extends AbstractFOPTest { /** the FopFactory */ protected final FopFactory fopFactory = FopFactory.newInstance(); @@ -51,7 +51,7 @@ public class BasePDFTestCase extends AbstractFOPTestCase { /** * Main constructor */ - protected BasePDFTestCase() { + protected BasePDFTest() { init(); } diff --git a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java index 67c4df280..fa6d9d89e 100644 --- a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java @@ -30,7 +30,7 @@ import org.junit.Test; /** * Tests PDF/A-1 functionality. */ -public class PDFAConformanceTestCase extends BasePDFTestCase { +public class PDFAConformanceTestCase extends BasePDFTest { private File foBaseDir = new File("test/xml/pdf-a"); private boolean dumpPDF = Boolean.getBoolean("PDFAConformanceTestCase.dumpPDF"); diff --git a/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java b/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java index b385e5598..122c23967 100644 --- a/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java @@ -31,7 +31,7 @@ import org.junit.Ignore; import org.junit.Test; /** Test that characters are correctly encoded in a generated PDF file */ -public class PDFEncodingTestCase extends BasePDFTestCase { +public class PDFEncodingTestCase extends BasePDFTest { private File foBaseDir = new File("test/xml/pdf-encoding"); private final boolean dumpPDF = Boolean.getBoolean("PDFEncodingTestCase.dumpPDF"); static final String INPUT_FILE = "test/xml/pdf-encoding/pdf-encoding-test.xconf"; diff --git a/test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java b/test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java index 6818537a8..dd67e97fa 100644 --- a/test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java @@ -29,7 +29,7 @@ import org.junit.Test; /** * Tests the disables-srgb-colorspace setting. */ -public class PDFsRGBSettingsTestCase extends BasePDFTestCase { +public class PDFsRGBSettingsTestCase extends BasePDFTest { private File foBaseDir = new File("test/xml/pdf-a"); diff --git a/test/java/org/apache/fop/render/ps/AbstractPostScriptTestCase.java b/test/java/org/apache/fop/render/ps/AbstractPostScriptTest.java index cdd1ee567..dcbc2d757 100644 --- a/test/java/org/apache/fop/render/ps/AbstractPostScriptTestCase.java +++ b/test/java/org/apache/fop/render/ps/AbstractPostScriptTest.java @@ -33,12 +33,12 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCEvent; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.render.AbstractRenderingTestCase; +import org.apache.fop.render.AbstractRenderingTest; /** * Abstract base class for PostScript verification tests. */ -public abstract class AbstractPostScriptTestCase extends AbstractRenderingTestCase { +public abstract class AbstractPostScriptTest extends AbstractRenderingTest { /** * Renders a test file. diff --git a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java index f4c3617e3..416372187 100644 --- a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java +++ b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java @@ -25,9 +25,10 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import org.junit.Test; + import org.apache.commons.io.IOUtils; -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.render.intermediate.IFContext; + import org.apache.xmlgraphics.ps.DSCConstants; import org.apache.xmlgraphics.ps.PSResource; import org.apache.xmlgraphics.ps.dsc.DSCException; @@ -36,12 +37,14 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPage; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPages; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentTitle; import org.apache.xmlgraphics.ps.dsc.events.DSCEvent; -import org.junit.Test; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.render.intermediate.IFContext; /** * Tests the image handling in PostScript output. */ -public class ImageHandlingTestCase extends AbstractPostScriptTestCase { +public class ImageHandlingTestCase extends AbstractPostScriptTest { /** * Tests JPEG handling. @@ -71,7 +74,8 @@ public class ImageHandlingTestCase extends AbstractPostScriptTestCase { ua.setDocumentHandlerOverride(handler); // Prepare output file - File outputFile = renderFile(ua, "ps-jpeg-image.fo", "-if-l" + psUtil.getLanguageLevel()); + File outputFile = renderFile(ua, "ps-jpeg-image.fo", + "-if-l" + psUtil.getLanguageLevel()); verifyPostScriptFile(outputFile, psUtil.getLanguageLevel()); } diff --git a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java index 91787aca1..e4cb743b4 100644 --- a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java +++ b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java @@ -31,9 +31,10 @@ import java.util.Arrays; import java.util.Collection; import java.util.Set; +import org.junit.Test; + import org.apache.commons.io.IOUtils; -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.render.intermediate.IFContext; + import org.apache.xmlgraphics.ps.DSCConstants; import org.apache.xmlgraphics.ps.PSResource; import org.apache.xmlgraphics.ps.dsc.DSCException; @@ -49,13 +50,15 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCCommentEndOfFile; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentIncludeResource; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPage; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPages; -import org.junit.Test; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.render.intermediate.IFContext; /** * Tests the PostScript resource optimization (selective de-duplication of * images that are used multiple times). */ -public class ResourceOptimizationTestCase extends AbstractPostScriptTestCase { +public class ResourceOptimizationTestCase extends AbstractPostScriptTest { /** * Tests resource optimization. diff --git a/test/java/org/apache/fop/text/linebreak/LineBreakStatusTest.java b/test/java/org/apache/fop/text/linebreak/LineBreakStatusTestCase.java index 97ac470e3..42ca8dee6 100644 --- a/test/java/org/apache/fop/text/linebreak/LineBreakStatusTest.java +++ b/test/java/org/apache/fop/text/linebreak/LineBreakStatusTestCase.java @@ -27,7 +27,7 @@ import org.junit.Test; /** * JUnit test case for the LineBreakStatus class */ -public class LineBreakStatusTest { +public class LineBreakStatusTestCase { /* * These symbols are used to indicate the break action returned diff --git a/test/java/org/apache/fop/text/linebreak/LineBreakUtilsTest.java b/test/java/org/apache/fop/text/linebreak/LineBreakUtilsTestCase.java index 9c5b0d8c6..015c1846f 100644 --- a/test/java/org/apache/fop/text/linebreak/LineBreakUtilsTest.java +++ b/test/java/org/apache/fop/text/linebreak/LineBreakUtilsTestCase.java @@ -28,7 +28,7 @@ import org.junit.Test; * * */ -public class LineBreakUtilsTest { +public class LineBreakUtilsTestCase { @Test public void testLineBreakProperty() { @@ -61,7 +61,7 @@ public class LineBreakUtilsTest { LineBreakUtils.getLineBreakPairProperty( LineBreakUtils.LINE_BREAK_PROPERTY_AL, LineBreakUtils.LINE_BREAK_PROPERTY_OP), - LineBreakUtils.DIRECT_BREAK); + LineBreakUtils.INDIRECT_BREAK); assertEquals( LineBreakUtils.getLineBreakPairProperty( LineBreakUtils.LINE_BREAK_PROPERTY_LF, diff --git a/test/java/org/apache/fop/traits/MinOptMaxTest.java b/test/java/org/apache/fop/traits/MinOptMaxTestCase.java index 9e08a63cb..73465fdcc 100644 --- a/test/java/org/apache/fop/traits/MinOptMaxTest.java +++ b/test/java/org/apache/fop/traits/MinOptMaxTestCase.java @@ -27,9 +27,9 @@ import static org.junit.Assert.fail; import org.junit.Test; /** - * Tests the {@link MinOptMaxTest} class. + * Tests the {@link MinOptMax} class. */ -public class MinOptMaxTest { +public class MinOptMaxTestCase { /** * Tests that the constant <code>MinOptMax.ZERO</code> is really zero. |