git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196604 13f79535-47bb-0310-9956-ffa450edef68pull/30/head
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
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 <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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(); | |||
} | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package org.apache.fop; | |||
import java.io.File; | |||
import junit.framework.TestCase; | |||
/** | |||
* Abstract base test class for FOP's tests. | |||
* @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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("."); | |||
} | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
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 <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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); | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package org.apache.fop; | |||
import junit.framework.Test; | |||
import junit.framework.TestSuite; | |||
/** | |||
* Test suite for basic functionality of FOP's Driver API. | |||
* @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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; | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
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 <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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(); | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
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 <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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(); | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
package org.apache.fop; | |||
import junit.framework.Test; | |||
import junit.framework.TestSuite; | |||
/** | |||
* Test suite for basic functionality of FOP's transcoders. | |||
* @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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; | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
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 <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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; | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
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. | |||
* <p> | |||
* ATTENTION: Some of the tests here depend on the correct behaviour of | |||
* ASCII85OutputStream. If something fails here make sure | |||
* ASCII85OutputStreamTestCase runs! | |||
* | |||
* @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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()); | |||
} | |||
} |
@@ -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 <jtauber@jtauber.com>. For more information on the Apache | |||
* Software Foundation, please see <http://www.apache.org/>. | |||
*/ | |||
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 <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> | |||
*/ | |||
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); | |||
} | |||
} |