From f651f86849503244dee06e64108c48841a841717 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 4 Jul 2003 20:50:29 +0000 Subject: [PATCH] Initial set of test cases git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196604 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/AbstractBasicTranscoderTestCase.java | 112 +++++++++ .../org/apache/fop/AbstractFOPTestCase.java | 83 +++++++ .../org/apache/fop/BasicDriverTestCase.java | 235 ++++++++++++++++++ .../org/apache/fop/BasicDriverTestSuite.java | 74 ++++++ .../fop/BasicPDFTranscoderTestCase.java | 77 ++++++ .../apache/fop/BasicPSTranscoderTestCase.java | 77 ++++++ .../apache/fop/BasicTranscoderTestSuite.java | 75 ++++++ .../org/apache/fop/UtilityCodeTestSuite.java | 78 ++++++ .../fop/util/ASCII85InputStreamTestCase.java | 202 +++++++++++++++ .../fop/util/ASCII85OutputStreamTestCase.java | 133 ++++++++++ 10 files changed, 1146 insertions(+) create mode 100644 test/java/org/apache/fop/AbstractBasicTranscoderTestCase.java create mode 100644 test/java/org/apache/fop/AbstractFOPTestCase.java create mode 100644 test/java/org/apache/fop/BasicDriverTestCase.java create mode 100644 test/java/org/apache/fop/BasicDriverTestSuite.java create mode 100644 test/java/org/apache/fop/BasicPDFTranscoderTestCase.java create mode 100644 test/java/org/apache/fop/BasicPSTranscoderTestCase.java create mode 100644 test/java/org/apache/fop/BasicTranscoderTestSuite.java create mode 100644 test/java/org/apache/fop/UtilityCodeTestSuite.java create mode 100644 test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java create mode 100644 test/java/org/apache/fop/util/ASCII85OutputStreamTestCase.java diff --git a/test/java/org/apache/fop/AbstractBasicTranscoderTestCase.java b/test/java/org/apache/fop/AbstractBasicTranscoderTestCase.java new file mode 100644 index 000000000..c43483be3 --- /dev/null +++ b/test/java/org/apache/fop/AbstractBasicTranscoderTestCase.java @@ -0,0 +1,112 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import java.io.File; +import java.io.InputStream; + +import org.apache.batik.transcoder.Transcoder; +import org.apache.batik.transcoder.TranscoderInput; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.commons.io.output.ByteArrayOutputStream; + +/** + * Basic runtime test for FOP's transcoders. It is used to verify that + * nothing obvious is broken after compiling. + * @author Jeremias Maerki + */ +public abstract class AbstractBasicTranscoderTestCase extends AbstractFOPTestCase { + + /** + * @see junit.framework.TestCase#TestCase(String) + */ + public AbstractBasicTranscoderTestCase(String name) { + super(name); + } + + /** + * Creates the transcoder to test. + * @return the newly instantiated transcoder + */ + protected abstract Transcoder createTranscoder(); + + /** + * Runs the PDF transcoder as if it were called by Batik's rasterizer. + * Without special configuration stuff. + * @throws Exception if a problem occurs + */ + public void testGenericPDFTranscoder() throws Exception { + //Create transcoder + Transcoder transcoder = createTranscoder(); + + //Setup input + File svgFile = new File(getBaseDir(), "test/resources/fop/svg/text.svg"); + InputStream in = new java.io.FileInputStream(svgFile); + try { + TranscoderInput input = new TranscoderInput(in); + + //Setup output + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + TranscoderOutput output = new TranscoderOutput(out); + + //Do the transformation + transcoder.transcode(input, output); + } finally { + out.close(); + } + assertTrue("Some output expected", out.size() > 0); + } finally { + in.close(); + } + } + +} diff --git a/test/java/org/apache/fop/AbstractFOPTestCase.java b/test/java/org/apache/fop/AbstractFOPTestCase.java new file mode 100644 index 000000000..db389b547 --- /dev/null +++ b/test/java/org/apache/fop/AbstractFOPTestCase.java @@ -0,0 +1,83 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import java.io.File; + +import junit.framework.TestCase; + +/** + * Abstract base test class for FOP's tests. + * @author Jeremias Maerki + */ +public abstract class AbstractFOPTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#TestCase(String) + */ + public AbstractFOPTestCase(String name) { + super(name); + } + + /** + * Returns the base directory to use for the tests. + * @return the base directory + */ + protected File getBaseDir() { + String basedir = System.getProperty("basedir"); + if (basedir != null) { + return new File(basedir); + } else { + return new File("."); + } + } + +} diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java new file mode 100644 index 000000000..6e3f122b2 --- /dev/null +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -0,0 +1,235 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import java.io.File; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXResult; +import javax.xml.transform.stream.StreamSource; + +import org.xml.sax.InputSource; + +import org.apache.avalon.framework.container.ContainerUtil; +import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.NullLogger; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.fop.apps.Driver; +import org.apache.fop.apps.InputHandler; +import org.apache.fop.apps.TraxInputHandler; +import org.apache.fop.apps.XSLTInputHandler; +import org.w3c.dom.Document; + +/** + * Basic runtime test for the old Driver class. It is used to verify that + * nothing obvious is broken after compiling. + * @author Jeremias Maerki + */ +public class BasicDriverTestCase extends AbstractFOPTestCase { + + private Logger logger = new NullLogger(); + + /** + * @see junit.framework.TestCase#TestCase(String) + */ + public BasicDriverTestCase(String name) { + super(name); + } + + /** + * Tests Driver with its special constructor for FO-->PDF conversion. + * @throws Exception if anything fails + */ + public void testFO2PDFWithConstructorSetup() throws Exception { + File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + Driver driver = new Driver( + new InputSource(foFile.toURL().toExternalForm()), + baout); + //Use deprecated method with purpose to validate backwards-compatibility. + driver.setLogger(this.logger); + driver.setRenderer(Driver.RENDER_PDF); + driver.run(); + assertTrue("Generated PDF has zero length", baout.size() > 0); + } + + /** + * Tests Driver with InputSource and OutputStream. + * @throws Exception if anything fails + */ + public void testFO2PDFWithInputSource() throws Exception { + File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + Driver driver = new Driver(); + //Use deprecated method with purpose to validate backwards-compatibility. + driver.setLogger(this.logger); + driver.setInputSource(new InputSource(foFile.toURL().toExternalForm())); + driver.setOutputStream(baout); + driver.setRenderer(Driver.RENDER_PDF); + driver.run(); + assertTrue("Generated PDF has zero length", baout.size() > 0); + } + + private Document loadDocument(File foFile) + throws TransformerException { + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); + Source src = new StreamSource(foFile); + DOMResult res = new DOMResult(); + transformer.transform(src, res); + return (Document)res.getNode(); + } + + /** + * Tests Driver with Document and OutputStream. + * @throws Exception if anything fails + */ + public void testFO2PDFWithDOM() throws Exception { + File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + Driver driver = new Driver(); + //Use deprecated method with purpose to validate backwards-compatibility. + driver.setLogger(this.logger); + driver.setOutputStream(baout); + driver.setRenderer(Driver.RENDER_PDF); + driver.render(loadDocument(foFile)); + assertTrue("Generated PDF has zero length", baout.size() > 0); + } + + /** + * Tests Driver with XMLReader, InputSource and OutputStream. + * @throws Exception if anything fails + */ + public void testFO2PDFWithXMLReader() throws Exception { + File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + Driver driver = new Driver(); + //Use deprecated method with purpose to validate backwards-compatibility. + driver.setLogger(this.logger); + driver.setOutputStream(baout); + driver.setRenderer(Driver.RENDER_PDF); + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(false); + SAXParser parser = factory.newSAXParser(); + driver.render(parser.getXMLReader(), + new InputSource(foFile.toURL().toExternalForm())); + assertTrue("Generated PDF has zero length", baout.size() > 0); + } + + /** + * Tests Driver with JAXP and OutputStream. + * @throws Exception if anything fails + */ + public void testFO2PDFWithJAXP() throws Exception { + File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + Driver driver = new Driver(); + ContainerUtil.enableLogging(driver, this.logger); + driver.setOutputStream(baout); + driver.setRenderer(Driver.RENDER_PDF); + + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); //Identity transf. + Source src = new StreamSource(foFile); + Result res = new SAXResult(driver.getContentHandler()); + transformer.transform(src, res); + + assertTrue("Generated PDF has zero length", baout.size() > 0); + } + + /** + * Tests Driver with XsltInputHandler and OutputStream. + * @throws Exception if anything fails + */ + public void testFO2PDFWithXSLTInputHandler() throws Exception { + File xmlFile = new File(getBaseDir(), "test/xml/1.xml"); + File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + Driver driver = new Driver(); + ContainerUtil.enableLogging(driver, this.logger); + driver.setOutputStream(baout); + driver.setRenderer(Driver.RENDER_PDF); + + InputHandler handler = new XSLTInputHandler(xmlFile, xsltFile); + handler.run(driver); + + assertTrue("Generated PDF has zero length", baout.size() > 0); + } + + /** + * Tests Driver with TraxInputHandler and OutputStream. + * @throws Exception if anything fails + */ + public void testFO2PDFWithTraxInputHandler() throws Exception { + File xmlFile = new File(getBaseDir(), "test/xml/1.xml"); + File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl"); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + Driver driver = new Driver(); + ContainerUtil.enableLogging(driver, this.logger); + driver.setOutputStream(baout); + driver.setRenderer(Driver.RENDER_PDF); + + InputHandler handler = new TraxInputHandler(xmlFile, xsltFile); + handler.run(driver); + + assertTrue("Generated PDF has zero length", baout.size() > 0); + } + + +} diff --git a/test/java/org/apache/fop/BasicDriverTestSuite.java b/test/java/org/apache/fop/BasicDriverTestSuite.java new file mode 100644 index 000000000..aa78c5583 --- /dev/null +++ b/test/java/org/apache/fop/BasicDriverTestSuite.java @@ -0,0 +1,74 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite for basic functionality of FOP's Driver API. + * @author Jeremias Maerki + */ +public class BasicDriverTestSuite { + + /** + * Builds the test suite + * @return the test suite + */ + public static Test suite() { + TestSuite suite = new TestSuite( + "Basic functionality test suite for FOP's Driver API"); + //$JUnit-BEGIN$ + suite.addTest(new TestSuite(BasicDriverTestCase.class)); + //$JUnit-END$ + return suite; + } +} diff --git a/test/java/org/apache/fop/BasicPDFTranscoderTestCase.java b/test/java/org/apache/fop/BasicPDFTranscoderTestCase.java new file mode 100644 index 000000000..5dc1a6f20 --- /dev/null +++ b/test/java/org/apache/fop/BasicPDFTranscoderTestCase.java @@ -0,0 +1,77 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import org.apache.batik.transcoder.Transcoder; +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. + * @author Jeremias Maerki + */ +public class BasicPDFTranscoderTestCase extends AbstractBasicTranscoderTestCase { + + /** + * @see junit.framework.TestCase#TestCase(String) + */ + public BasicPDFTranscoderTestCase(String name) { + super(name); + } + + /** + * @see org.apache.fop.AbstractBasicTranscoderTestCase#createTranscoder() + */ + protected Transcoder createTranscoder() { + return new PDFTranscoder(); + } + +} diff --git a/test/java/org/apache/fop/BasicPSTranscoderTestCase.java b/test/java/org/apache/fop/BasicPSTranscoderTestCase.java new file mode 100644 index 000000000..67458b9b9 --- /dev/null +++ b/test/java/org/apache/fop/BasicPSTranscoderTestCase.java @@ -0,0 +1,77 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import org.apache.batik.transcoder.Transcoder; +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. + * @author Jeremias Maerki + */ +public class BasicPSTranscoderTestCase extends AbstractBasicTranscoderTestCase { + + /** + * @see junit.framework.TestCase#TestCase(String) + */ + public BasicPSTranscoderTestCase(String name) { + super(name); + } + + /** + * @see org.apache.fop.AbstractBasicTranscoderTestCase#createTranscoder() + */ + protected Transcoder createTranscoder() { + return new PSTranscoder(); + } + +} diff --git a/test/java/org/apache/fop/BasicTranscoderTestSuite.java b/test/java/org/apache/fop/BasicTranscoderTestSuite.java new file mode 100644 index 000000000..a41505cb8 --- /dev/null +++ b/test/java/org/apache/fop/BasicTranscoderTestSuite.java @@ -0,0 +1,75 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite for basic functionality of FOP's transcoders. + * @author Jeremias Maerki + */ +public class BasicTranscoderTestSuite { + + /** + * Builds the test suite + * @return the test suite + */ + public static Test suite() { + TestSuite suite = new TestSuite( + "Basic functionality test suite for FOP's transcoders"); + //$JUnit-BEGIN$ + suite.addTest(new TestSuite(BasicPDFTranscoderTestCase.class)); + suite.addTest(new TestSuite(BasicPSTranscoderTestCase.class)); + //$JUnit-END$ + return suite; + } +} diff --git a/test/java/org/apache/fop/UtilityCodeTestSuite.java b/test/java/org/apache/fop/UtilityCodeTestSuite.java new file mode 100644 index 000000000..016658eeb --- /dev/null +++ b/test/java/org/apache/fop/UtilityCodeTestSuite.java @@ -0,0 +1,78 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop; + +import org.apache.fop.util.ASCII85InputStreamTestCase; +import org.apache.fop.util.ASCII85OutputStreamTestCase; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite for FOP's utility classes. + * @author Jeremias Maerki + */ +public class UtilityCodeTestSuite { + + /** + * 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(ASCII85OutputStreamTestCase.class)); + suite.addTest(new TestSuite(ASCII85InputStreamTestCase.class)); + //$JUnit-END$ + return suite; + } +} diff --git a/test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java b/test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java new file mode 100644 index 000000000..33387894e --- /dev/null +++ b/test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java @@ -0,0 +1,202 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.util; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.io.IOUtil; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.fop.pdf.PDFText; + +import junit.framework.TestCase; + +/** + * Test case for ASCII85InputStream. + *

+ * ATTENTION: Some of the tests here depend on the correct behaviour of + * ASCII85OutputStream. If something fails here make sure + * ASCII85OutputStreamTestCase runs! + * + * @author Jeremias Maerki + */ +public class ASCII85InputStreamTestCase extends TestCase { + + private static final boolean DEBUG = false; + + /** + * @see junit.framework.TestCase#TestCase(String) + */ + public ASCII85InputStreamTestCase(String name) { + super(name); + } + + private byte[] decode(String text) throws Exception { + byte[] ascii85 = text.getBytes("US-ASCII"); + InputStream in = new ByteArrayInputStream(ascii85); + InputStream decoder = new ASCII85InputStream(in); + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + IOUtil.copy(decoder, baout); + baout.close(); + return baout.toByteArray(); + } + + private byte[] getChunk(int count) { + byte[] buf = new byte[count]; + System.arraycopy(ASCII85OutputStreamTestCase.DATA, 0, buf, 0, buf.length); + return buf; + } + + private String encode(byte[] data, int len) throws Exception { + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + java.io.OutputStream out = new ASCII85OutputStream(baout); + out.write(data, 0, len); + out.close(); + return new String(baout.toByteArray(), "US-ASCII"); + } + + + private void innerTestDecode(byte[] data) throws Exception { + String encoded = encode(data, data.length); + if (DEBUG) { + if (data[0] == 0) { + System.out.println("self-encode: " + data.length + " chunk 000102030405..."); + } else { + System.out.println("self-encode: " + new String(data, "US-ASCII") + + " " + PDFText.toHex(data)); + } + System.out.println(" ---> " + encoded); + } + byte[] decoded = decode(encoded); + if (DEBUG) { + if (data[0] == 0) { + System.out.println("decoded: " + data.length + " chunk 000102030405..."); + } else { + System.out.println("decoded: " + new String(decoded, "US-ASCII") + + " " + PDFText.toHex(decoded)); + } + } + assertEquals(PDFText.toHex(data), PDFText.toHex(decoded)); + } + + /** + * Tests the output of ASCII85. + * @throws Exception if an error occurs + */ + public void testDecode() throws Exception { + byte[] buf; + innerTestDecode("1. Bodypart".getBytes("US-ASCII")); + if (DEBUG) { + System.out.println("==========================================="); + } + + innerTestDecode(getChunk(1)); + innerTestDecode(getChunk(2)); + innerTestDecode(getChunk(3)); + innerTestDecode(getChunk(4)); + innerTestDecode(getChunk(5)); + if (DEBUG) { + System.out.println("==========================================="); + } + + innerTestDecode(getChunk(10)); + innerTestDecode(getChunk(62)); + innerTestDecode(getChunk(63)); + innerTestDecode(getChunk(64)); + innerTestDecode(getChunk(65)); + + if (DEBUG) { + System.out.println("==========================================="); + } + String sz; + sz = PDFText.toHex(decode("zz~>")); + assertEquals(PDFText.toHex(new byte[] {0, 0, 0, 0, 0, 0, 0, 0}), sz); + sz = PDFText.toHex(decode("z\t \0z\n~>")); + assertEquals(PDFText.toHex(new byte[] {0, 0, 0, 0, 0, 0, 0, 0}), sz); + if (DEBUG) { + System.out.println("==========================================="); + } + try { + decode("vz~>"); + fail("Illegal character should be detected"); + } catch (IOException ioe) { + //expected + } + /* DISABLED because of try/catch in InputStream.read(byte[], int, int). + * Only the exception happening on the first byte in a block is being + * reported. BUG in JDK??? + * + try { + decode("zv~>"); + fail("Illegal character should be detected"); + } catch (IOException ioe) { + //expected + }*/ + } + + private byte[] getFullASCIIRange() { + java.io.ByteArrayOutputStream baout = new java.io.ByteArrayOutputStream(256); + for (int i = 254; i < 256; i++) { + baout.write(i); + } + return baout.toByteArray(); + } + + /** + * Tests the full 8-bit ASCII range. + * @throws Exception if an error occurs + */ + public void testFullASCIIRange() throws Exception { + innerTestDecode(getFullASCIIRange()); + } + +} diff --git a/test/java/org/apache/fop/util/ASCII85OutputStreamTestCase.java b/test/java/org/apache/fop/util/ASCII85OutputStreamTestCase.java new file mode 100644 index 000000000..dd2a39aa0 --- /dev/null +++ b/test/java/org/apache/fop/util/ASCII85OutputStreamTestCase.java @@ -0,0 +1,133 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.util; + +import java.io.OutputStream; + +import org.apache.commons.io.output.ByteArrayOutputStream; + +import junit.framework.TestCase; + +/** + * Test case for ASCII85OutputStream + * + * @author Jeremias Maerki + */ +public class ASCII85OutputStreamTestCase extends TestCase { + + /** Test data */ + public static final byte[] DATA = new byte[100]; + + static { + //Fill in some data + for (int i = 0; i < 100; i++) { + DATA[i] = (byte)i; + } + } + + /** + * @see junit.framework.TestCase#TestCase(String) + */ + public ASCII85OutputStreamTestCase(String name) { + super(name); + } + + private String encode(int count) throws Exception { + return encode(DATA, count); + } + + private String encode(byte[] data, int len) throws Exception { + ByteArrayOutputStream baout = new ByteArrayOutputStream(); + OutputStream out = new ASCII85OutputStream(baout); + out.write(data, 0, len); + out.close(); + return new String(baout.toByteArray(), "US-ASCII"); + } + + /** + * Tests the output of ASCII85. + * @throws Exception if an error occurs + */ + public void testOutput() throws Exception { + String sz = encode(new byte[] {0, 0, 0, 0, 0, 0, 0, 0}, 8); + assertEquals("zz~>", sz); + + String s3 = encode(3); + //System.out.println(">>>" + s3 + "<<<"); + assertEquals("!!*-~>", s3); + + String s10 = encode(10); + //System.out.println(">>>" + s10 + "<<<"); + assertEquals("!!*-'\"9eu7#RL~>", s10); + + String s62 = encode(62); + //System.out.println(">>>" + s62 + "<<<"); + assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR," + + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?W~>", s62); + + String s63 = encode(63); + //System.out.println(">>>" + s63 + "<<<"); + assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR," + + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Yk\n~>", s63); + + String s64 = encode(64); + //System.out.println(">>>" + s64 + "<<<"); + assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR," + + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Ykm\n~>", s64); + + String s65 = encode(65); + //System.out.println(">>>" + s65 + "<<<"); + assertEquals("!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR," + + "UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Ykm\n5Q~>", s65); + + } + +} -- 2.39.5