diff options
author | Peter Hancock <phancock@apache.org> | 2011-11-01 12:20:21 +0000 |
---|---|---|
committer | Peter Hancock <phancock@apache.org> | 2011-11-01 12:20:21 +0000 |
commit | fd263a114c84c3756ead9c16b8b088531c5cab2c (patch) | |
tree | 4cd6ba7c8fe3a144629477ac911b2651707bdb03 /test/java/org/apache/fop | |
parent | 54a4751b616ab4e8957b97af4088bd725367ea6f (diff) | |
download | xmlgraphics-fop-fd263a114c84c3756ead9c16b8b088531c5cab2c.tar.gz xmlgraphics-fop-fd263a114c84c3756ead9c16b8b088531c5cab2c.zip |
Bugzilla#52089: Allow JPEG images to be embedded in an AFP document as
is, without being decoded and encoded. It also allows lossy JPEG compression.
Patch by Jeremias Maerki and Mehdi Houshmand.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1195952 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop')
6 files changed, 327 insertions, 4 deletions
diff --git a/test/java/org/apache/fop/afp/AFPObjectAreaInfoTestCase.java b/test/java/org/apache/fop/afp/AFPObjectAreaInfoTestCase.java new file mode 100644 index 000000000..fc5f1825c --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPObjectAreaInfoTestCase.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for {@link AFPObjectAreaInfo}. + */ +public class AFPObjectAreaInfoTestCase { + + private AFPObjectAreaInfo sut; + + /** + * Instantiate the system under test + */ + @Before + public void setUp() { + sut = new AFPObjectAreaInfo(1, 2, 3, 4, 5, 6); + } + + /** + * Test the getter functions with arbitrary data. + */ + @Test + public void testGetters() { + assertEquals(1, sut.getX()); + assertEquals(2, sut.getY()); + assertEquals(3, sut.getWidth()); + assertEquals(4, sut.getHeight()); + assertEquals(5, sut.getWidthRes()); + assertEquals(5, sut.getHeightRes()); + assertEquals(6, sut.getRotation()); + } + + /** + * Test the resolution setters with arbitrary data. + */ + @Test + public void testSetters() { + assertEquals(5, sut.getWidthRes()); + assertEquals(5, sut.getHeightRes()); + + sut.setResolution(20); + assertEquals(20, sut.getWidthRes()); + assertEquals(20, sut.getHeightRes()); + + sut.setHeightRes(10); + assertEquals(20, sut.getWidthRes()); + assertEquals(10, sut.getHeightRes()); + + sut.setWidthRes(9); + assertEquals(9, sut.getWidthRes()); + assertEquals(10, sut.getHeightRes()); + } +} diff --git a/test/java/org/apache/fop/afp/AFPPaintingStateTestCase.java b/test/java/org/apache/fop/afp/AFPPaintingStateTestCase.java new file mode 100644 index 000000000..47c93064c --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPPaintingStateTestCase.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for {@link AFPPaintingState}. + */ +public class AFPPaintingStateTestCase { + private AFPPaintingState sut; + + /** + * Set up the system under test + */ + @Before + public void setUp() { + sut = new AFPPaintingState(); + } + + /** + * Test {get,set}BitmapEncodingQuality() + */ + @Test + public void testGetSetBitmapEncodingQuality() { + sut.setBitmapEncodingQuality(0.5f); + assertEquals(0.5f, sut.getBitmapEncodingQuality(), 0.01f); + + sut.setBitmapEncodingQuality(0.9f); + assertEquals(0.9f, sut.getBitmapEncodingQuality(), 0.01f); + } + + /** + * Test {,set}CanEmbedJpeg + */ + public void testGetSetCanEmbedJpeg() { + assertEquals(false, sut.canEmbedJpeg()); + sut.setCanEmbedJpeg(true); + assertEquals(true, sut.canEmbedJpeg()); + } +} diff --git a/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java b/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java new file mode 100644 index 000000000..c9ea9a5f4 --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import org.apache.xmlgraphics.util.MimeConstants; + +/** + * Test case for {@link AFPResourceManager}. + */ +public class AFPResourceManagerTestCase { + + private AFPResourceManager sut; + + @Before + public void setUp() throws IOException { + sut = new AFPResourceManager(); + AFPPaintingState paintingState = new AFPPaintingState(); + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + DataStream stream = sut.createDataStream(paintingState, outStream); + stream.startPage(0, 0, 0, 10, 10); + } + + /** + * Ensures that if tryIncludeObject() is called with a new object, it returns false suggesting + * that we have to create said object. However, if it is called with an object that has already + * been created, it returns true suggesting that we don't have to create that object again. + * Page-segment is false. + * + * @throws IOException if an I/O error occurs + */ + @Test + public void testTryIncludeObjectWithPageSegFalse() throws IOException { + AFPDataObjectInfo dataInfo = createAFPDataObjectInfo(); + // An empty object needs to be created every time! + assertFalse(sut.tryIncludeObject(dataInfo)); + sut.createObject(dataInfo); + assertTrue(sut.tryIncludeObject(dataInfo)); + } + + /** + * {@code testTryIncludeObjectWithPageSegFalse()} but with page-segment true. + * + * @throws IOException if an I/O error occurs + */ + @Test + public void testTryIncludeObjectWithPageSegTrue() throws IOException { + AFPDataObjectInfo dataInfo = createAFPDataObjectInfo(); + dataInfo.setCreatePageSegment(true); + // An empty object needs to be created every time! + assertFalse(sut.tryIncludeObject(dataInfo)); + sut.createObject(dataInfo); + assertTrue(sut.tryIncludeObject(dataInfo)); + } + + private AFPDataObjectInfo createAFPDataObjectInfo() { + AFPDataObjectInfo dataInfo = new AFPDataObjectInfo(); + dataInfo.setMimeType(MimeConstants.MIME_TIFF); + dataInfo.setData(new byte[1]); + AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo(0, 0, 10, 10, 1, 0); + dataInfo.setObjectAreaInfo(objectAreaInfo); + return dataInfo; + } +} diff --git a/test/java/org/apache/fop/afp/AFPTestSuite.java b/test/java/org/apache/fop/afp/AFPTestSuite.java index 8fa3e819d..32d61cb35 100644 --- a/test/java/org/apache/fop/afp/AFPTestSuite.java +++ b/test/java/org/apache/fop/afp/AFPTestSuite.java @@ -19,18 +19,21 @@ package org.apache.fop.afp; -import org.apache.fop.afp.modca.IncludeObjectTestCase; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; +import org.apache.fop.afp.modca.IncludeObjectTestCase; + /** * Test suite for FOP's AFP classes. */ @RunWith(Suite.class) @SuiteClasses({ - IncludeObjectTestCase.class, - AFPResourceUtilTestCase.class + IncludeObjectTestCase.class, + AFPResourceUtilTestCase.class, + AFPObjectAreaInfoTestCase.class, + AFPPaintingStateTestCase.class }) public class AFPTestSuite { } diff --git a/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java b/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java new file mode 100644 index 000000000..7c08e6d99 --- /dev/null +++ b/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import org.apache.fop.afp.AFPPaintingState; +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; + +/** + * Test case for {@link AFPRendererConfigurator}. + */ +public class AFPRendererConfiguratorTestCase { + private static FOUserAgent userAgent; + + private AFPRendererConfigurator sut; + + /** + * The FOUserAgent only needs to be created once. + */ + @BeforeClass + public static void createUserAgent() { + userAgent = FopFactory.newInstance().newFOUserAgent(); + } + + /** + * Assigns an FOUserAgen with a config file at <code>uri</code> + * + * @param uri the URI of the config file + */ + private void setConfigFile(String uri) { + String confTestsDir = "test/resources/conf/afp/"; + try { + userAgent.getFactory().setUserConfig(confTestsDir + uri); + sut = new AFPRendererConfigurator(userAgent); + } catch (IOException ioe) { + fail("IOException: " + ioe); + } catch (SAXException se) { + fail("SAXException: " + se); + } + } + + /** + * Test several config files relating to JPEG images in AFP. + * + * @throws FOPException if an error is thrown + */ + @Test + public void testJpegImageConfig() throws FOPException { + testJpegSettings("no_image_config.xconf", 1.0f, false); + testJpegSettings("can_embed_jpeg.xconf", 1.0f, true); + testJpegSettings("bitmap_encode_quality.xconf", 0.5f, false); + } + + private void testJpegSettings(String uri, float bitmapEncodingQual, boolean canEmbed) + throws FOPException { + AFPDocumentHandler docHandler = new AFPDocumentHandler(); + + setConfigFile(uri); + sut.configure(docHandler); + + AFPPaintingState paintingState = docHandler.getPaintingState(); + assertEquals(bitmapEncodingQual, paintingState.getBitmapEncodingQuality(), 0.01f); + assertEquals(canEmbed, paintingState.canEmbedJpeg()); + } +} diff --git a/test/java/org/apache/fop/render/afp/AFPTestSuite.java b/test/java/org/apache/fop/render/afp/AFPTestSuite.java index 16b6651a6..117e7efcf 100644 --- a/test/java/org/apache/fop/render/afp/AFPTestSuite.java +++ b/test/java/org/apache/fop/render/afp/AFPTestSuite.java @@ -27,6 +27,8 @@ import org.junit.runners.Suite.SuiteClasses; * Test suite for FOP's AFP output. */ @RunWith(Suite.class) -@SuiteClasses({ NoOperationTestCase.class }) +@SuiteClasses({ + NoOperationTestCase.class, + AFPRendererConfiguratorTestCase.class }) public class AFPTestSuite { } |