diff options
author | Peter Hancock <phancock@apache.org> | 2012-10-04 14:46:01 +0000 |
---|---|---|
committer | Peter Hancock <phancock@apache.org> | 2012-10-04 14:46:01 +0000 |
commit | af57408966c6e9a525475f52bdc96add31cb0e51 (patch) | |
tree | 7aec6fd97d2d6c501be6b2473aa399b236e37a51 /test/java/org/apache/fop | |
parent | 118f9d4f0f6aeed4971ea9cc61fd4d63198c9a84 (diff) | |
parent | d261730a4f7be752ae12a5ec52e6bad8ee4fa5c1 (diff) | |
download | xmlgraphics-fop-af57408966c6e9a525475f52bdc96add31cb0e51.tar.gz xmlgraphics-fop-af57408966c6e9a525475f52bdc96add31cb0e51.zip |
Merged trunk@1391502
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_RoundedCorners@1394098 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop')
34 files changed, 1566 insertions, 144 deletions
diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index f1dd89725..e1015306e 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.java @@ -46,14 +46,15 @@ import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.xpath.XPathAPI; import org.apache.xpath.objects.XObject; +import org.apache.xmlgraphics.io.Resource; +import org.apache.xmlgraphics.io.ResourceResolver; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FopFactoryBuilder; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.apps.io.Resource; -import org.apache.fop.apps.io.ResourceResolver; import org.apache.fop.apps.io.ResourceResolverFactory; import org.apache.fop.render.xml.XMLRenderer; diff --git a/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java index 863bfe797..87b970576 100644 --- a/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java +++ b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java @@ -19,8 +19,6 @@ package org.apache.fop.accessibility.fo; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -34,7 +32,6 @@ import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.custommonkey.xmlunit.Diff; @@ -57,9 +54,17 @@ import org.apache.fop.fotreetest.DummyFOEventHandler; public class FO2StructureTreeConverterTestCase { - private interface FOLoader { + private static class FOLoader { - InputStream getFoInputStream(); + private final String resourceName; + + FOLoader(String resourceName) { + this.resourceName = resourceName; + } + + public InputStream getFoInputStream() { + return getResource(resourceName); + } } private static final String STRUCTURE_TREE_SEQUENCE_NAME = "structure-tree-sequence"; @@ -68,62 +73,35 @@ public class FO2StructureTreeConverterTestCase { @Test public void testCompleteDocument() throws Exception { - foLoader = new FOLoader() { - public InputStream getFoInputStream() { - return getResource("/org/apache/fop/fo/complete_document.fo"); - } - }; - testConverter(); + testConverter("/org/apache/fop/fo/complete_document.fo"); } @Test public void testTableFooters() throws Exception { - foLoader = new FOLoader() { - public InputStream getFoInputStream() { - return getResource("table-footers.fo"); - } - }; - testConverter(); + testConverter("table-footers.fo"); } @Test - public void testCompleteContentWrappedInTableFooter() throws Exception { - Source xslt = new StreamSource(getResource("wrapCompleteDocumentInTableFooter.xsl")); - Transformer transformer = createTransformer(xslt); - InputStream originalFO = getResource("/org/apache/fop/fo/complete_document.fo"); - ByteArrayOutputStream transformedFoOutput = new ByteArrayOutputStream(); - transformer.transform(new StreamSource(originalFO), new StreamResult(transformedFoOutput)); - final byte[] transformedFoOutputBytes = transformedFoOutput.toByteArray(); - foLoader = new FOLoader() { - public InputStream getFoInputStream() { - return new ByteArrayInputStream(transformedFoOutputBytes); - } - }; - testConverter(); + public void testArtifact() throws Exception { + testConverter("artifact.fo"); } @Test - public void testArtifact() throws Exception { - foLoader = new FOLoader() { - - public InputStream getFoInputStream() { - return getResource("artifact.fo"); - } - }; - testConverter(); + public void testSideRegions() throws Exception { + testConverter("/org/apache/fop/fo/pagination/side-regions.fo"); } - private Transformer createTransformer(Source xslt) throws TransformerFactoryConfigurationError, - TransformerConfigurationException { - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - return transformerFactory.newTransformer(xslt); + @Test + public void headerTableCellMustPropagateScope() throws Exception { + testConverter("table-header_scope.fo"); } private static InputStream getResource(String name) { return FO2StructureTreeConverterTestCase.class.getResourceAsStream(name); } - private void testConverter() throws Exception { + private void testConverter(String foResourceName) throws Exception { + foLoader = new FOLoader(foResourceName); DOMResult expectedStructureTree = loadExpectedStructureTree(); DOMResult actualStructureTree = buildActualStructureTree(); final Diff diff = createDiff(expectedStructureTree, actualStructureTree); diff --git a/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl index db0dffb14..90d74a7c4 100644 --- a/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl +++ b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl @@ -21,7 +21,7 @@ xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" xmlns:foi="http://xmlgraphics.apache.org/fop/internal"> - <xsl:output method="xml" indent="no"/> + <xsl:output method="xml" indent="yes"/> <xsl:template name="copy"> <xsl:copy> @@ -50,6 +50,25 @@ <xsl:call-template name="copy"/> </xsl:template> + <xsl:template match="fo:static-content/@flow-name|fo:flow/@flow-name"> + <xsl:choose> + <xsl:when test=". = 'xsl-region-body' or + . = 'xsl-region-before' or + . = 'xsl-region-after' or + . = 'xsl-region-start' or + . = 'xsl-region-end' or + . = 'xsl-before-float-separator' or + . = 'xsl-footnote-separator'"> + <xsl:copy/> + </xsl:when> + <xsl:otherwise> + <xsl:attribute name="{local-name()}"> + <xsl:value-of select="concat('xsl-', local-name(//*[@region-name = current()]))"/> + </xsl:attribute> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <!-- Block-level Formatting Objects --> <xsl:template match="fo:block|fo:block-container"> <xsl:call-template name="copy"/> @@ -73,16 +92,35 @@ <xsl:call-template name="copy"/> </xsl:template> - <xsl:template match="fo:table"> + <xsl:template match="fo:table|fo:table-header|fo:table-footer|fo:table-body|fo:table-row"> + <xsl:call-template name="copy"/> + </xsl:template> + + <xsl:template name="get.column.header"> + <xsl:value-of select="ancestor::fo:table/fo:table-column[ + count(preceding-sibling::fo:table-column) = count(current()/preceding-sibling::fo:table-cell)]/@fox:header"/> + </xsl:template> + + <xsl:template match="fo:table-cell"> + <xsl:variable name="header"><xsl:call-template name="get.column.header"/></xsl:variable> <xsl:copy> - <xsl:apply-templates select="@*"/> - <xsl:apply-templates select="*[name() != 'fo:table-footer']"/> - <xsl:apply-templates select="fo:table-footer"/> + <xsl:if test="$header = 'true'"> + <xsl:attribute name="role">TH</xsl:attribute> + <xsl:attribute name="scope" namespace="http://xmlgraphics.apache.org/fop/internal">Row</xsl:attribute> + </xsl:if> + <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> - <xsl:template match="fo:table-header|fo:table-footer|fo:table-body|fo:table-row|fo:table-cell"> - <xsl:call-template name="copy"/> + <xsl:template match="fo:table-header/fo:table-cell|fo:table-header/fo:table-row/fo:table-cell"> + <xsl:variable name="header"><xsl:call-template name="get.column.header"/></xsl:variable> + <xsl:copy> + <xsl:attribute name="role">TH</xsl:attribute> + <xsl:if test="$header = 'true'"> + <xsl:attribute name="scope" namespace="http://xmlgraphics.apache.org/fop/internal">Both</xsl:attribute> + </xsl:if> + <xsl:apply-templates select="@*|node()"/> + </xsl:copy> </xsl:template> <!-- Formatting Objects for Lists --> diff --git a/test/java/org/apache/fop/accessibility/fo/table-header_scope.fo b/test/java/org/apache/fop/accessibility/fo/table-header_scope.fo new file mode 100644 index 000000000..c6272d546 --- /dev/null +++ b/test/java/org/apache/fop/accessibility/fo/table-header_scope.fo @@ -0,0 +1,57 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" + xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" + font-family="sans-serif"> + <fo:layout-master-set> + <fo:simple-page-master master-name="page" + page-height="120pt" page-width="220pt" margin="10pt"> + <fo:region-body display-align="center"/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="page"> + <fo:flow flow-name="xsl-region-body" line-height="10pt" font-size="8pt"> + <fo:table width="100%" table-layout="fixed"> + <fo:table-column fox:header="true" column-width="proportional-column-width(1)"/> + <fo:table-column column-width="proportional-column-width(1)"/> + <fo:table-column column-width="proportional-column-width(1)"/> + <fo:table-header font-weight="bold"> + <fo:table-row> + <fo:table-cell border="1pt solid black" padding-left="1pt"> + <fo:block>Table Header</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black" padding-left="1pt"> + <fo:block>Column 1</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black" padding-left="1pt"> + <fo:block>Column 2</fo:block> + </fo:table-cell> + </fo:table-row> + </fo:table-header> + <fo:table-body> + <fo:table-row> + <fo:table-cell id="Row1" border="1pt solid black" padding-left="1pt" font-weight="bold"> + <fo:block>Row 1</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black" padding-left="1pt"> + <fo:block>Cell 1.1</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black" padding-left="1pt"> + <fo:block>Cell 1.2</fo:block> + </fo:table-cell> + </fo:table-row> + <fo:table-row> + <fo:table-cell border="1pt solid black" padding-left="1pt" font-weight="bold" role="TH"> + <fo:block>Row 2</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black" padding-left="1pt"> + <fo:block>Cell 2.1</fo:block> + </fo:table-cell> + <fo:table-cell border="1pt solid black" padding-left="1pt"> + <fo:block>Cell 2.2</fo:block> + </fo:table-cell> + </fo:table-row> + </fo:table-body> + </fo:table> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/java/org/apache/fop/accessibility/fo/wrapCompleteDocumentInTableFooter.xsl b/test/java/org/apache/fop/accessibility/fo/wrapCompleteDocumentInTableFooter.xsl deleted file mode 100644 index 9608b2fb9..000000000 --- a/test/java/org/apache/fop/accessibility/fo/wrapCompleteDocumentInTableFooter.xsl +++ /dev/null @@ -1,66 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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$ --> -<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" - xmlns:fo="http://www.w3.org/1999/XSL/Format"> - - <xsl:template match="@*|node()" name="copy"> - <xsl:copy> - <xsl:apply-templates select="@*|node()"/> - </xsl:copy> - </xsl:template> - - - <xsl:template match="/"> - <fo:root> - <fo:layout-master-set> - <fo:simple-page-master master-name="page" - page-height="500pt" page-width="300pt" margin="20pt"> - <fo:region-body margin-top="20pt"/> - </fo:simple-page-master> - </fo:layout-master-set> - <xsl:apply-templates select="//fo:page-sequence"/> - </fo:root> - </xsl:template> - - <xsl:template match="fo:page-sequence"> - <fo:page-sequence master-reference="page"> - <xsl:apply-templates select="fo:flow"/> - </fo:page-sequence> - </xsl:template> - - <xsl:template match="fo:flow"> - <xsl:copy> - <xsl:apply-templates select="@*[not(starts-with(name(), 'space-before'))]"/> - <fo:table width="100%" table-layout="fixed"> - <fo:table-footer> - <fo:table-cell background-color="#F0F0F0"> - <xsl:apply-templates select="@*[starts-with(name(), 'space-before')]"/> - <xsl:apply-templates select="*"/> - </fo:table-cell> - </fo:table-footer> - <fo:table-body> - <fo:table-cell> - <fo:block>The content below is in the table footer.</fo:block> - </fo:table-cell> - </fo:table-body> - </fo:table> - </xsl:copy> - </xsl:template> - -</xsl:stylesheet> diff --git a/test/java/org/apache/fop/apps/EnvironmentalProfileFactoryTestCase.java b/test/java/org/apache/fop/apps/EnvironmentalProfileFactoryTestCase.java index 7b033969b..e94403e71 100644 --- a/test/java/org/apache/fop/apps/EnvironmentalProfileFactoryTestCase.java +++ b/test/java/org/apache/fop/apps/EnvironmentalProfileFactoryTestCase.java @@ -21,11 +21,12 @@ import java.net.URI; import org.junit.Test; -import org.apache.fop.apps.io.ResourceResolver; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; +import org.apache.xmlgraphics.io.ResourceResolver; + public class EnvironmentalProfileFactoryTestCase { private final URI testURI = URI.create("this.is.purely.for.test.purposes"); diff --git a/test/java/org/apache/fop/apps/MutableConfig.java b/test/java/org/apache/fop/apps/MutableConfig.java index 79f038f24..3ff3c10fa 100644 --- a/test/java/org/apache/fop/apps/MutableConfig.java +++ b/test/java/org/apache/fop/apps/MutableConfig.java @@ -24,8 +24,9 @@ import java.util.Set; import org.apache.avalon.framework.configuration.Configuration; import org.apache.xmlgraphics.image.loader.ImageManager; +import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver; +import org.apache.xmlgraphics.io.ResourceResolver; -import org.apache.fop.apps.io.ResourceResolver; import org.apache.fop.fonts.FontManager; import org.apache.fop.layoutmgr.LayoutManagerMaker; @@ -130,4 +131,8 @@ public final class MutableConfig implements FopFactoryConfig { public Map<String, String> getHyphenationPatternNames() { return delegate.getHyphenationPatternNames(); } + + public FallbackResolver getFallbackResolver() { + return delegate.getFallbackResolver(); + } } diff --git a/test/java/org/apache/fop/apps/TIFFRendererConfBuilder.java b/test/java/org/apache/fop/apps/TIFFRendererConfBuilder.java index 8b72a558d..f39df2988 100644 --- a/test/java/org/apache/fop/apps/TIFFRendererConfBuilder.java +++ b/test/java/org/apache/fop/apps/TIFFRendererConfBuilder.java @@ -20,7 +20,7 @@ package org.apache.fop.apps; import static org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererOption.COMPRESSION; - +import static org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererOption.SINGLE_STRIP; public class TIFFRendererConfBuilder extends BitmapRendererConfBuilder { public TIFFRendererConfBuilder() { @@ -31,4 +31,9 @@ public class TIFFRendererConfBuilder extends BitmapRendererConfBuilder { createTextElement(COMPRESSION, mode); return this; } + + public TIFFRendererConfBuilder setSingleStrip(boolean single) { + createTextElement(SINGLE_STRIP, String.valueOf(single)); + return this; + } } diff --git a/test/java/org/apache/fop/apps/io/BaseURIResolutionTest.java b/test/java/org/apache/fop/apps/io/BaseURIResolutionTest.java index ee337c39d..2131407c1 100644 --- a/test/java/org/apache/fop/apps/io/BaseURIResolutionTest.java +++ b/test/java/org/apache/fop/apps/io/BaseURIResolutionTest.java @@ -37,6 +37,8 @@ import org.xml.sax.SAXException; import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.xmlgraphics.io.ResourceResolver; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; diff --git a/test/java/org/apache/fop/apps/io/FontURIResolver.java b/test/java/org/apache/fop/apps/io/FontURIResolver.java index d6f836783..40d6c7402 100644 --- a/test/java/org/apache/fop/apps/io/FontURIResolver.java +++ b/test/java/org/apache/fop/apps/io/FontURIResolver.java @@ -39,6 +39,8 @@ import org.apache.fop.apps.PDFRendererConfBuilder; import static org.junit.Assert.assertTrue; +import org.apache.xmlgraphics.io.Resource; + public class FontURIResolver extends BaseURIResolutionTest { public enum Event { diff --git a/test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java b/test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java index b6b2eea00..6ae34b4f9 100644 --- a/test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java +++ b/test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java @@ -36,6 +36,10 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import org.apache.xmlgraphics.io.Resource; +import org.apache.xmlgraphics.io.ResourceResolver; +import org.apache.xmlgraphics.io.TempResourceResolver; + public class ResourceResolverFactoryTestCase { private static final byte[] DATA = new byte[]{(byte) 0, (byte) 1, (byte) 2}; @@ -193,10 +197,10 @@ public class ResourceResolverFactoryTestCase { final ResourceResolver sut; TestCreateSchemaAwareResourceResolverBuilderHelper() { - ResourceResolverFactory.SchemaAwareResourceResolverBuilder builder - = ResourceResolverFactory.createSchemaAwareResourceResolverBuilder( + ResourceResolverFactory.SchemeAwareResourceResolverBuilder builder + = ResourceResolverFactory.createSchemeAwareResourceResolverBuilder( defaultResourceResolver); - builder.registerResourceResolverForSchema(SCHEMA, registedResourceResolver); + builder.registerResourceResolverForScheme(SCHEMA, registedResourceResolver); sut = builder.build(); } diff --git a/test/java/org/apache/fop/apps/io/TestingResourceResolver.java b/test/java/org/apache/fop/apps/io/TestingResourceResolver.java index 532353337..f1cd06138 100644 --- a/test/java/org/apache/fop/apps/io/TestingResourceResolver.java +++ b/test/java/org/apache/fop/apps/io/TestingResourceResolver.java @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.apache.xmlgraphics.io.ResourceResolver; + abstract class TestingResourceResolver implements ResourceResolver { private final Map<URI, Object> checker; diff --git a/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java b/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java index 440b16abb..b2044e3b9 100644 --- a/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java +++ b/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java @@ -35,6 +35,8 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import org.apache.xmlgraphics.io.ResourceResolver; + public class URIResolverWrapperTestCase { private static final List<String> BASE_URIS = Collections.unmodifiableList(Arrays.asList( diff --git a/test/java/org/apache/fop/fo/FONodeMocks.java b/test/java/org/apache/fop/fo/FONodeMocks.java index 001173179..ba969b9fa 100644 --- a/test/java/org/apache/fop/fo/FONodeMocks.java +++ b/test/java/org/apache/fop/fo/FONodeMocks.java @@ -19,19 +19,22 @@ package org.apache.fop.fo; +import java.io.IOException; + import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.io.IOException; - import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.ImageSessionContext; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; +import org.apache.fop.events.EventBroadcaster; +import org.apache.fop.fo.flow.table.ColumnNumberManager; +import org.apache.fop.fo.flow.table.ColumnNumberManagerHolder; /** * A helper class for creating mocks of {@link FONode} and its descendants. @@ -51,27 +54,36 @@ public final class FONodeMocks { public static FONode mockFONode() { FONode mockFONode = mock(FONode.class); mockGetFOEventHandler(mockFONode); + mockGetImageManager(mockFONode.getFOEventHandler().getUserAgent()); return mockFONode; } - private static void mockGetFOEventHandler(FONode mockFONode) { + public static FOEventHandler mockGetFOEventHandler(FONode mockFONode) { FOEventHandler mockFOEventHandler = mock(FOEventHandler.class); mockGetUserAgent(mockFOEventHandler); when(mockFONode.getFOEventHandler()).thenReturn(mockFOEventHandler); + return mockFOEventHandler; } - private static void mockGetUserAgent(FOEventHandler mockFOEventHandler) { + public static FOUserAgent mockGetUserAgent(FOEventHandler mockFOEventHandler) { FOUserAgent mockFOUserAgent = mock(FOUserAgent.class); - mockGetImageManager(mockFOUserAgent); when(mockFOEventHandler.getUserAgent()).thenReturn(mockFOUserAgent); + return mockFOUserAgent; } - private static void mockGetImageManager(FOUserAgent mockFOUserAgent) { + public static EventBroadcaster mockGetEventBroadcaster(FOUserAgent mockFOUserAgent) { + EventBroadcaster mockBroadcaster = mock(EventBroadcaster.class); + when(mockFOUserAgent.getEventBroadcaster()).thenReturn(mockBroadcaster); + return mockBroadcaster; + } + + public static ImageManager mockGetImageManager(FOUserAgent mockFOUserAgent) { try { ImageManager mockImageManager = mock(ImageManager.class); when(mockImageManager.getImageInfo(anyString(), any(ImageSessionContext.class))) .thenReturn(null); when(mockFOUserAgent.getImageManager()).thenReturn(mockImageManager); + return mockImageManager; } catch (ImageException e) { throw new RuntimeException(e); } catch (IOException e) { @@ -79,4 +91,10 @@ public final class FONodeMocks { } } + public static ColumnNumberManager mockGetColumnNumberManager(ColumnNumberManagerHolder mock) { + ColumnNumberManager mockColumnNumberManager = mock(ColumnNumberManager.class); + when(mock.getColumnNumberManager()).thenReturn(mockColumnNumberManager); + return mockColumnNumberManager; + } + } diff --git a/test/java/org/apache/fop/fo/flow/MarkersTestCase.java b/test/java/org/apache/fop/fo/flow/MarkersTestCase.java new file mode 100644 index 000000000..983a531b0 --- /dev/null +++ b/test/java/org/apache/fop/fo/flow/MarkersTestCase.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id:$ */ + +package org.apache.fop.fo.flow; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.flow.Marker; +import org.apache.fop.fo.flow.Markers; +import org.apache.fop.fo.flow.RetrieveMarker; +import org.apache.fop.fo.flow.RetrieveTableMarker; + +public class MarkersTestCase { + + @Test + public void testRegisterAndResolve() { + // consider 3 regions, and a boundary; the first region starts before the boundary and ends inside + // the boundary, the second region is fully inside the boundary, and the third region starts inside + // the boundary and ends after the boundary. in every region there are 2 markers, A and B. + // ======== region 1 + Map<String, Marker> markers_region_1 = new HashMap<String, Marker>(); + Marker marker_1A = mock(Marker.class); + Marker marker_1B = mock(Marker.class); + markers_region_1.put("A", marker_1A); + markers_region_1.put("B", marker_1B); + // ======== region 2 + Map<String, Marker> markers_region_2 = new HashMap<String, Marker>(); + Marker marker_2A = mock(Marker.class); + Marker marker_2B = mock(Marker.class); + markers_region_2.put("A", marker_2A); + markers_region_2.put("B", marker_2B); + // ======== region 3 + Map<String, Marker> markers_region_3 = new HashMap<String, Marker>(); + Marker marker_3A = mock(Marker.class); + Marker marker_3B = mock(Marker.class); + markers_region_3.put("A", marker_3A); + markers_region_3.put("B", marker_3B); + // instantiate markers for the boundary + Markers markers = new Markers(); + // register the markers for the different regions + // region 1 + markers.register(markers_region_1, true, false, true); + markers.register(markers_region_1, false, false, true); + // region 2 + markers.register(markers_region_2, true, true, true); + markers.register(markers_region_2, false, true, true); + // region 3 + markers.register(markers_region_3, true, true, false); + markers.register(markers_region_3, false, true, false); + // now prepare a RetrieveMarker + RetrieveMarker rm = mock(RetrieveMarker.class); + when(rm.getRetrieveClassName()).thenReturn("A"); + when(rm.getLocalName()).thenReturn("retrieve-marker"); + when(rm.getPositionLabel()).thenReturn("position-label"); // not relevant for the test + // and resolve the marker for different positions + // EN_FSWP + when(rm.getPosition()).thenReturn(Constants.EN_FSWP); + // expect marker_2A + assertEquals(marker_2A, markers.resolve(rm)); + // EN_LSWP + when(rm.getPosition()).thenReturn(Constants.EN_LSWP); + // expect marker_3A + assertEquals(marker_3A, markers.resolve(rm)); + // EN_LEWP + when(rm.getPosition()).thenReturn(Constants.EN_LEWP); + // expect marker_2A + assertEquals(marker_2A, markers.resolve(rm)); + // EN_FIC + when(rm.getPosition()).thenReturn(Constants.EN_FIC); + // expect marker_1A + assertEquals(marker_1A, markers.resolve(rm)); + // now prepare a RetrieveTableMarker + RetrieveTableMarker rtm = mock(RetrieveTableMarker.class); + when(rtm.getRetrieveClassName()).thenReturn("B"); + when(rtm.getLocalName()).thenReturn("retrieve-table-marker"); + when(rtm.getPositionLabel()).thenReturn("position-label"); // not relevant for the test + // and resolve the marker for different positions + // EN_FIRST_STARTING + when(rtm.getPosition()).thenReturn(Constants.EN_FIRST_STARTING); + // expect marker_2B + assertEquals(marker_2B, markers.resolve(rtm)); + // EN_LAST_STARTING + when(rtm.getPosition()).thenReturn(Constants.EN_LAST_STARTING); + // expect marker_3B + assertEquals(marker_3B, markers.resolve(rtm)); + // EN_LAST_ENDING + when(rtm.getPosition()).thenReturn(Constants.EN_LAST_ENDING); + // expect marker_2B + assertEquals(marker_2B, markers.resolve(rtm)); + // EN_FIRST_INCLUDING_CARRYOVER + when(rtm.getPosition()).thenReturn(Constants.EN_FIRST_INCLUDING_CARRYOVER); + // expect marker_1B + assertEquals(marker_1B, markers.resolve(rtm)); + // test also an invalid position + when(rm.getPosition()).thenReturn(Constants.EN_ABSOLUTE); + try { + Marker m = markers.resolve(rm); + fail("Expected an exception... instead got:" + m.toString()); + } catch (RuntimeException re) { + // do nothing + } + } +} diff --git a/test/java/org/apache/fop/fo/flow/table/HeaderColumnTestCase.java b/test/java/org/apache/fop/fo/flow/table/HeaderColumnTestCase.java new file mode 100644 index 000000000..4cc94b5e0 --- /dev/null +++ b/test/java/org/apache/fop/fo/flow/table/HeaderColumnTestCase.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fo.flow.table; + +import org.junit.Test; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.helpers.AttributesImpl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.events.EventBroadcaster; +import org.apache.fop.fo.ElementMappingRegistry; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.FONodeMocks; +import org.apache.fop.fo.FOValidationEventProducer; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.StaticPropertyList; +import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.extensions.ExtensionElementMapping; +import org.apache.fop.util.XMLUtil; + +/** + * Tests that the fox:header property is correctly parsed and set up at the FO tree level. + */ +public class HeaderColumnTestCase { + + @Test + public void testWrongValue() throws ValidationException { + Table parent = createTableParent(); + EventBroadcaster mockEventBroadcaster = FONodeMocks.mockGetEventBroadcaster( + parent.getFOEventHandler().getUserAgent()); + FOValidationEventProducer eventProducer = mockGetEventProducerFor(mockEventBroadcaster); + TableColumn column = new TableColumn(parent); + PropertyList propertyList = new StaticPropertyList(column, null); + Attributes atts = createScopeAttribute("blah"); + propertyList.addAttributesToList(atts); + verify(eventProducer).invalidPropertyValue(any(), eq("fo:table-column"), + eq("fox:header"), eq("blah"), any(PropertyException.class), any(Locator.class)); + } + + @Test + public void testCorrectValue() throws Exception { + testCorrectValue(true); + testCorrectValue(false); + } + + private void testCorrectValue(boolean expectedValue) throws Exception { + Table parent = createTableParent(); + FONodeMocks.mockGetColumnNumberManager(parent); + TableColumn column = new TableColumn(parent, true); + PropertyList propertyList = new StaticPropertyList(column, null); + Attributes atts = createScopeAttribute(String.valueOf(expectedValue)); + propertyList.addAttributesToList(atts); + column.bind(propertyList); + assertEquals(expectedValue, column.isHeader()); + } + + private Table createTableParent() { + Table parent = mock(Table.class); + FOEventHandler mockFOEventHandler = FONodeMocks.mockGetFOEventHandler(parent); + FOUserAgent mockUserAgent = mockFOEventHandler.getUserAgent(); + mockGetElementMappingRegistry(mockUserAgent); + return parent; + } + + private Attributes createScopeAttribute(String value) { + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute(ExtensionElementMapping.URI, "header", "fox:header", XMLUtil.CDATA, value); + return atts; + } + + private ElementMappingRegistry mockGetElementMappingRegistry(FOUserAgent mockUserAgent) { + ElementMappingRegistry mockRegistry = mock(ElementMappingRegistry.class); + when(mockRegistry.getElementMapping(anyString())).thenReturn(new ExtensionElementMapping()); + when(mockUserAgent.getElementMappingRegistry()).thenReturn(mockRegistry); + return mockRegistry; + } + + private FOValidationEventProducer mockGetEventProducerFor(EventBroadcaster mockEventBroadcaster) { + FOValidationEventProducer mockEventProducer = mock(FOValidationEventProducer.class); + when(mockEventBroadcaster.getEventProducerFor(eq(FOValidationEventProducer.class))) + .thenReturn(mockEventProducer); + return mockEventProducer; + } + +} diff --git a/test/java/org/apache/fop/fo/pagination/LayoutMasterSetTestCase.java b/test/java/org/apache/fop/fo/pagination/LayoutMasterSetTestCase.java new file mode 100644 index 000000000..cfe71f529 --- /dev/null +++ b/test/java/org/apache/fop/fo/pagination/LayoutMasterSetTestCase.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fo.pagination; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.FODocumentParser; +import org.apache.fop.fo.FODocumentParser.FOEventHandlerFactory; +import org.apache.fop.fo.FOEventHandler; + +public class LayoutMasterSetTestCase { + + private static class FlowMappingTester extends FOEventHandler { + + private static final String[][] FLOW_MAPPINGS = { + + {"first-page-before", "xsl-region-before"}, + {"first-page-after", "xsl-region-after"}, + {"first-page-start", "xsl-region-start"}, + {"first-page-end", "xsl-region-end"}, + + {"odd-page-before", "xsl-region-before"}, + {"odd-page-after", "xsl-region-after"}, + {"odd-page-start", "xsl-region-start"}, + {"odd-page-end", "xsl-region-end"}, + + {"odd-page-before", "xsl-region-before"}, + {"odd-page-after", "xsl-region-after"}, + {"odd-page-start", "xsl-region-start"}, + {"odd-page-end", "xsl-region-end"}, + + {"blank-page-before", "xsl-region-before"}, + {"blank-page-after", "xsl-region-after"}, + {"blank-page-start", "xsl-region-start"}, + {"blank-page-end", "xsl-region-end"}, + + {"last-page-before", "xsl-region-before"}, + {"last-page-after", "xsl-region-after"}, + {"last-page-start", "xsl-region-start"}, + {"last-page-end", "xsl-region-end"}, + + {"xsl-footnote-separator", "xsl-footnote-separator"} + + }; + + FlowMappingTester(FOUserAgent userAgent) { + super(userAgent); + } + + @Override + public void startPageSequence(PageSequence pageSeq) { + super.startPageSequence(pageSeq); + LayoutMasterSet layoutMasterSet = pageSeq.getRoot().getLayoutMasterSet(); + for (String[] mapping : FLOW_MAPPINGS) { + assertEquals(mapping[1], layoutMasterSet.getDefaultRegionNameFor(mapping[0])); + } + } + + } + + /** + * Tests the {@link LayoutMasterSet#getDefaultRegionNameFor(String)} method. + */ + @Test + public void testFlowMapping() throws Exception { + FODocumentParser foDocumentParser = FODocumentParser.newInstance(new FOEventHandlerFactory() { + + public FOEventHandler newFOEventHandler(FOUserAgent foUserAgent) { + return new FlowMappingTester(foUserAgent); + } + }); + foDocumentParser.parse(getClass().getResourceAsStream("side-regions.fo")); + } + +} diff --git a/test/java/org/apache/fop/fo/pagination/side-regions.fo b/test/java/org/apache/fop/fo/pagination/side-regions.fo new file mode 100644 index 000000000..8a0fba2ec --- /dev/null +++ b/test/java/org/apache/fop/fo/pagination/side-regions.fo @@ -0,0 +1,181 @@ +<?xml version="1.0" standalone="no"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="first-page" + page-height="100pt" page-width="150pt"> + <fo:region-body margin="12pt" display-align="center" background-color="#FFF0F0"/> + <fo:region-before region-name="first-page-before" extent="10pt" precedence="true" + display-align="after"/> + <fo:region-after region-name="first-page-after" extent="10pt" precedence="true"/> + <fo:region-start region-name="first-page-start" extent="10pt" reference-orientation="90" + display-align="after"/> + <fo:region-end region-name="first-page-end" extent="10pt" reference-orientation="-90" + display-align="after"/> + </fo:simple-page-master> + <fo:simple-page-master master-name="odd-page" + page-height="100pt" page-width="150pt"> + <fo:region-body margin="12pt" display-align="center" background-color="#FFFFF0"/> + <fo:region-before region-name="odd-page-before" extent="10pt" precedence="true" + display-align="after"/> + <fo:region-after region-name="odd-page-after" extent="10pt" precedence="true"/> + <fo:region-start region-name="odd-page-start" extent="10pt" reference-orientation="90" + display-align="after"/> + <fo:region-end region-name="odd-page-end" extent="10pt" reference-orientation="-90" + display-align="after"/> + </fo:simple-page-master> + <fo:simple-page-master master-name="even-page" + page-height="100pt" page-width="150pt"> + <fo:region-body margin="12pt" display-align="center" background-color="#F0FFF0"/> + <fo:region-before region-name="even-page-before" extent="10pt" precedence="true" + display-align="after"/> + <fo:region-after region-name="even-page-after" extent="10pt" precedence="true"/> + <fo:region-start region-name="even-page-start" extent="10pt" reference-orientation="90" + display-align="after"/> + <fo:region-end region-name="even-page-end" extent="10pt" reference-orientation="-90" + display-align="after"/> + </fo:simple-page-master> + <fo:simple-page-master master-name="blank-page" + page-height="100pt" page-width="150pt"> + <fo:region-body margin="12pt" display-align="center" background-color="#F0F0F0"/> + <fo:region-before region-name="blank-page-before" extent="10pt" precedence="true" + display-align="after"/> + <fo:region-after region-name="blank-page-after" extent="10pt" precedence="true"/> + <fo:region-start region-name="blank-page-start" extent="10pt" reference-orientation="90" + display-align="after"/> + <fo:region-end region-name="blank-page-end" extent="10pt" reference-orientation="-90" + display-align="after"/> + </fo:simple-page-master> + <fo:simple-page-master master-name="last-page" + page-height="100pt" page-width="150pt"> + <fo:region-body margin="45pt 12pt" display-align="center" background-color="#F0F0FF"/> + <fo:region-before region-name="last-page-before" extent="10pt" precedence="true" + display-align="after"/> + <fo:region-after region-name="last-page-after" extent="10pt" precedence="true"/> + <fo:region-start region-name="last-page-start" extent="10pt" reference-orientation="90" + display-align="after"/> + <fo:region-end region-name="last-page-end" extent="10pt" reference-orientation="-90" + display-align="after"/> + </fo:simple-page-master> + <fo:page-sequence-master master-name="pages"> + <fo:repeatable-page-master-alternatives> + <fo:conditional-page-master-reference page-position="first" master-reference="first-page"/> + <fo:conditional-page-master-reference page-position="last" master-reference="last-page"/> + <fo:conditional-page-master-reference blank-or-not-blank="blank" + master-reference="blank-page"/> + <fo:conditional-page-master-reference odd-or-even="odd" master-reference="odd-page"/> + <fo:conditional-page-master-reference odd-or-even="even" master-reference="even-page"/> + </fo:repeatable-page-master-alternatives> + </fo:page-sequence-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="pages" force-page-count="even" font-size="4pt" + text-align="center"> + + <fo:static-content flow-name="first-page-before"> + <fo:block start-indent="12pt" end-indent="12pt" border-bottom="0.5pt solid red" + padding-bottom="0.5pt">First Page Before.</fo:block> + </fo:static-content> + <fo:static-content flow-name="first-page-after"> + <fo:block start-indent="12pt" end-indent="12pt" border-top="0.5pt solid red" + padding-top="0.5pt">First Page After.</fo:block> + </fo:static-content> + <fo:static-content flow-name="first-page-start"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid red" + padding-bottom="0.5pt">First Page Start.</fo:block> + </fo:static-content> + <fo:static-content flow-name="first-page-end"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid red" + padding-bottom="0.5pt">First Page End.</fo:block> + </fo:static-content> + + <fo:static-content flow-name="odd-page-after"> + <fo:block start-indent="12pt" end-indent="12pt" border-top="0.5pt solid orange" + padding-top="0.5pt">Odd Page After.</fo:block> + </fo:static-content> + <fo:static-content flow-name="odd-page-end"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid orange" + padding-bottom="0.5pt">Odd Page End.</fo:block> + </fo:static-content> + <fo:static-content flow-name="odd-page-start"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid orange" + padding-bottom="0.5pt">Odd Page Start.</fo:block> + </fo:static-content> + <fo:static-content flow-name="odd-page-before"> + <fo:block start-indent="12pt" end-indent="12pt" border-bottom="0.5pt solid orange" + padding-bottom="0.5pt">Odd Page Before.</fo:block> + </fo:static-content> + + <fo:static-content flow-name="even-page-end"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid green" + padding-bottom="0.5pt">Even Page End.</fo:block> + </fo:static-content> + <fo:static-content flow-name="even-page-start"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid green" + padding-bottom="0.5pt">Even Page Start.</fo:block> + </fo:static-content> + <fo:static-content flow-name="even-page-after"> + <fo:block start-indent="12pt" end-indent="12pt" border-top="0.5pt solid green" + padding-top="0.5pt">Even Page After.</fo:block> + </fo:static-content> + <fo:static-content flow-name="even-page-before"> + <fo:block start-indent="12pt" end-indent="12pt" border-bottom="0.5pt solid green" + padding-bottom="0.5pt">Even Page Before.</fo:block> + </fo:static-content> + + <fo:static-content flow-name="blank-page-start"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid black" + padding-bottom="0.5pt">Blank Page Start.</fo:block> + </fo:static-content> + <fo:static-content flow-name="blank-page-after"> + <fo:block start-indent="12pt" end-indent="12pt" border-top="0.5pt solid black" + padding-top="0.5pt">Blank Page After.</fo:block> + </fo:static-content> + <fo:static-content flow-name="blank-page-before"> + <fo:block start-indent="12pt" end-indent="12pt" border-bottom="0.5pt solid black" + padding-bottom="0.5pt">Blank Page Before.</fo:block> + </fo:static-content> + <fo:static-content flow-name="blank-page-end"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid black" + padding-bottom="0.5pt">Blank Page End.</fo:block> + </fo:static-content> + + <fo:static-content flow-name="last-page-before"> + <fo:block start-indent="12pt" end-indent="12pt" border-bottom="0.5pt solid blue" + padding-bottom="0.5pt">Last Page Before.</fo:block> + </fo:static-content> + <fo:static-content flow-name="last-page-end"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid blue" + padding-bottom="0.5pt">Last Page End.</fo:block> + </fo:static-content> + <fo:static-content flow-name="last-page-after"> + <fo:block start-indent="12pt" end-indent="12pt" border-top="0.5pt solid blue" + padding-top="0.5pt">Last Page After.</fo:block> + </fo:static-content> + <fo:static-content flow-name="last-page-start"> + <fo:block start-indent="2pt" end-indent="2pt" border-bottom="0.5pt solid blue" + padding-bottom="0.5pt">Last Page Start.</fo:block> + </fo:static-content> + + <fo:static-content flow-name="xsl-footnote-separator"> + <fo:block> + <fo:leader leader-pattern="rule" leader-length="40%" rule-thickness="0.5pt"/> + </fo:block> + </fo:static-content> + + <fo:flow flow-name="xsl-region-body" font-size="8pt" line-height="10pt"> + <fo:block>Apacheâ„¢ FOP (Formatting Objects Processor) is a print formatter driven by XSL + formatting objects (XSL-FO) and an output independent formatter.</fo:block> + <fo:block break-before="page">It is an application<fo:footnote><fo:inline>*</fo:inline> + <fo:footnote-body><fo:block font-size="80%">* written in + Java</fo:block></fo:footnote-body></fo:footnote> that reads a formatting object (FO) + tree and renders the resulting pages to a specified output.</fo:block> + <fo:block break-before="page">The FOP project is part of the Apache Software Foundation, which + is a wider community of users and developers of open source projects.</fo:block> + <fo:block break-before="page">Apacheâ„¢ FOP (Formatting Objects Processor) is a print formatter + driven by XSL formatting objects (XSL-FO) and an output independent formatter.</fo:block> + <fo:block break-before="page">It is a Java application that reads a formatting object (FO) + tree and renders the resulting pages to a specified output.</fo:block> + <fo:block break-before="page">The FOP project is part of the Apache Software Foundation, which + is a wider community of users and developers of open source projects.</fo:block> + </fo:flow> + </fo:page-sequence> +</fo:root> diff --git a/test/java/org/apache/fop/fonts/CIDFullTestCase.java b/test/java/org/apache/fop/fonts/CIDFullTestCase.java new file mode 100644 index 000000000..7df6cc25b --- /dev/null +++ b/test/java/org/apache/fop/fonts/CIDFullTestCase.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fonts; + +import java.util.BitSet; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.fop.util.CharUtilities; + +public class CIDFullTestCase { + + private CIDFull cidFull; + private MultiByteFont mbFont; + private BitSet bs; + private char[] chars; + private int[] widths; + private Map<Integer, Integer> glyphs; + + @Before + public void setup() { + bs = new BitSet(); + glyphs = new HashMap<Integer, Integer>(); + chars = new char[18]; + widths = new int[18]; + int i = 0; + for (int j = 0; j < 20; j++) { + if (j == 10 || j == 11) { + continue; + } + bs.set(j); + glyphs.put(Integer.valueOf(j), Integer.valueOf(j)); + chars[i] = (char) j; + widths[i] = 100; + i++; + } + mbFont = mock(MultiByteFont.class); + when(mbFont.getGlyphIndices()).thenReturn(bs); + when(mbFont.getChars()).thenReturn(chars); + when(mbFont.getWidths()).thenReturn(widths); + cidFull = new CIDFull(mbFont); + } + + @Test + public void testGetOriginalGlyphIndex() { + // index 5 exists + assertEquals(cidFull.getOriginalGlyphIndex(5), 5); + } + + @Test + public void testGetUnicode() { + // index 9 exists + assertEquals(cidFull.getUnicode(9), (char) 9); + // index 10 does not + assertEquals(cidFull.getUnicode(10), CharUtilities.NOT_A_CHARACTER); + } + + @Test + public void testMapChar() { + // index 9 exists + char c = 'a'; + assertEquals(cidFull.mapChar(9, c), (char) 9); + } + + @Test + public void testGetGlyphs() { + Map<Integer, Integer> fontGlyphs = cidFull.getGlyphs(); + for (Integer key : fontGlyphs.keySet()) { + assertEquals(fontGlyphs.get(key), glyphs.get(key)); + } + assertTrue(fontGlyphs.size() == glyphs.size()); + } + + @Test + public void testGetChars() { + assertArrayEquals(cidFull.getChars(), chars); + } + + @Test + public void testGetNumberOfGlyphs() { + assertTrue(cidFull.getNumberOfGlyphs() == 20); + } + + @Test + public void testGetGlyphIndices() { + assertEquals(bs, cidFull.getGlyphIndices()); + } + + @Test + public void testGetWidths() { + assertArrayEquals(cidFull.getWidths(), widths); + } + +} diff --git a/test/java/org/apache/fop/fonts/FontManagerTestCase.java b/test/java/org/apache/fop/fonts/FontManagerTestCase.java new file mode 100644 index 000000000..9012f843b --- /dev/null +++ b/test/java/org/apache/fop/fonts/FontManagerTestCase.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.fop.fonts; + +import java.net.URI; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InOrder; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.io.InternalResourceResolver; + +public class FontManagerTestCase { + + private FontManager sut; + private FontCacheManager fontCacheManager; + private FontDetector fontDetector; + private InternalResourceResolver resolver; + + @Before + public void setUp() { + resolver = mock(InternalResourceResolver.class); + fontCacheManager = mock(FontCacheManager.class); + fontDetector = mock(FontDetector.class); + + sut = new FontManager(resolver, fontDetector, fontCacheManager); + } + + @Test + public void testSetCacheFile() { + URI testURI = URI.create("test/uri"); + sut.setCacheFile(testURI); + + InOrder inOrder = inOrder(resolver, fontCacheManager); + inOrder.verify(resolver).resolveFromBase(testURI); + inOrder.verify(fontCacheManager).setCacheFile(any(URI.class)); + } + + @Test + public void testGetFontCache() { + sut.getFontCache(); + verify(fontCacheManager).load(); + } + + @Test + public void testSaveCache() throws FOPException { + sut.saveCache(); + verify(fontCacheManager).save(); + } + + @Test + public void testDeleteCache() throws FOPException { + sut.deleteCache(); + verify(fontCacheManager).delete(); + } +} diff --git a/test/java/org/apache/fop/intermediate/TestAssistant.java b/test/java/org/apache/fop/intermediate/TestAssistant.java index 2be41dca1..2b138de55 100644 --- a/test/java/org/apache/fop/intermediate/TestAssistant.java +++ b/test/java/org/apache/fop/intermediate/TestAssistant.java @@ -42,8 +42,11 @@ import org.w3c.dom.Element; import org.apache.xpath.XPathAPI; import org.apache.xpath.objects.XObject; +import org.apache.fop.apps.EnvironmentProfile; +import org.apache.fop.apps.EnvironmentalProfileFactory; import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FopFactoryBuilder; +import org.apache.fop.apps.io.ResourceResolverFactory; /** * Helper class for running FOP tests. @@ -115,7 +118,10 @@ public class TestAssistant { public FopFactory getFopFactory(Document testDoc) { boolean base14KerningEnabled = isBase14KerningEnabled(testDoc); boolean strictValidation = isStrictValidation(testDoc); - FopFactoryBuilder builder = new FopFactoryBuilder(testDir.getParentFile().toURI()); + EnvironmentProfile envProfile = EnvironmentalProfileFactory.createRestrictedIO( + testDir.getParentFile().toURI(), + ResourceResolverFactory.createDefaultResourceResolver()); + FopFactoryBuilder builder = new FopFactoryBuilder(envProfile); builder.setStrictFOValidation(strictValidation); builder.getFontManager().setBase14KerningEnabled(base14KerningEnabled); return builder.build(); diff --git a/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java b/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java new file mode 100644 index 000000000..c836bce7c --- /dev/null +++ b/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.fop.layoutmgr; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import org.apache.fop.fo.Constants; + +public class BreakElementTestCase { + + /** + * Tests that the constructor sets the break class to a valid default value. + */ + @Test + public void breakClassMustBeValid() { + LayoutContext context = LayoutContext.newInstance(); + BreakElement breakElement = new BreakElement(new Position(null), 0, context); + assertEquals(Constants.EN_AUTO, breakElement.getBreakClass()); + } +} diff --git a/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java b/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java index eb2a4fc92..e810f80c5 100644 --- a/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java +++ b/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java @@ -19,6 +19,8 @@ package org.apache.fop.layoutmgr; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.mock; @@ -31,7 +33,6 @@ import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.Region; import org.apache.fop.fo.pagination.Root; import org.apache.fop.fo.pagination.SimplePageMaster; -import org.junit.Test; public class PageSequenceLayoutManagerTestCase { diff --git a/test/java/org/apache/fop/layoutmgr/RetrieveTableMarkerLayoutManagerMakerTestCase.java b/test/java/org/apache/fop/layoutmgr/RetrieveTableMarkerLayoutManagerMakerTestCase.java new file mode 100644 index 000000000..6a37de33c --- /dev/null +++ b/test/java/org/apache/fop/layoutmgr/RetrieveTableMarkerLayoutManagerMakerTestCase.java @@ -0,0 +1,56 @@ +/* + * 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.layoutmgr; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FObj.FObjIterator; +import org.apache.fop.fo.flow.RetrieveTableMarker; +import org.apache.fop.layoutmgr.LayoutManagerMapping.RetrieveTableMarkerLayoutManagerMaker; + +public class RetrieveTableMarkerLayoutManagerMakerTestCase { + + @Test + public void testMake() throws FOPException { + // mock + FObjIterator foi = mock(FObjIterator.class); + when(foi.hasNext()).thenReturn(true).thenReturn(false); + // mock + RetrieveTableMarker rtm = mock(RetrieveTableMarker.class); + // real RTMLMM, not mock + List l = new ArrayList(); + LayoutManagerMapping lmm = new LayoutManagerMapping(); + RetrieveTableMarkerLayoutManagerMaker rtmlmm = lmm.new RetrieveTableMarkerLayoutManagerMaker(); + // test the case rtm has no child nodes + when(rtm.getChildNodes()).thenReturn(null); + rtmlmm.make(rtm, l); + assertTrue(l.size() == 1); + assertTrue(l.get(0) instanceof RetrieveTableMarkerLayoutManager); + } + +} diff --git a/test/java/org/apache/fop/layoutmgr/RetrieveTableMarkerLayoutManagerTestCase.java b/test/java/org/apache/fop/layoutmgr/RetrieveTableMarkerLayoutManagerTestCase.java new file mode 100644 index 000000000..fda9cbccb --- /dev/null +++ b/test/java/org/apache/fop/layoutmgr/RetrieveTableMarkerLayoutManagerTestCase.java @@ -0,0 +1,82 @@ +/* + * 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.layoutmgr; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.flow.RetrieveTableMarker; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.layoutmgr.inline.TextLayoutManager; +import org.apache.fop.layoutmgr.table.TableLayoutManager; + +public class RetrieveTableMarkerLayoutManagerTestCase { + + @Test + public void testGetNextKnuthElementsLayoutContextInt() { + LayoutContext lc = LayoutContext.newInstance(); + // mock + Table t = mock(Table.class); + // mock + RetrieveTableMarker rtm = mock(RetrieveTableMarker.class); + when(rtm.getRetrieveClassName()).thenReturn("A"); + when(rtm.getPosition()).thenReturn(Constants.EN_FIRST_STARTING); + when(rtm.getBoundary()).thenReturn(Constants.EN_TABLE_FRAGMENT); + // mock + TextLayoutManager tlm = mock(TextLayoutManager.class); + // mock + LayoutManagerMapping lmm = mock(LayoutManagerMapping.class); + when(lmm.makeLayoutManager(rtm)).thenReturn(tlm); + // mock + PageSequenceLayoutManager pslm = mock(PageSequenceLayoutManager.class); + when(pslm.getPSLM()).thenReturn(pslm); + when(pslm.getLayoutManagerMaker()).thenReturn(lmm); + // mock + TableLayoutManager tablelm = mock(TableLayoutManager.class); + when(tablelm.getTable()).thenReturn(t); + // mock + BlockLayoutManager blm = mock(BlockLayoutManager.class); + when(blm.getPSLM()).thenReturn(pslm); + when(blm.getParent()).thenReturn(tablelm); + // real RTMLM, not mock + RetrieveTableMarkerLayoutManager rtmlm = new RetrieveTableMarkerLayoutManager(rtm); + rtmlm.setParent(blm); + // test the case where resolution returns null + when(tablelm.resolveRetrieveTableMarker(rtm)).thenReturn(null); + assertNull(rtmlm.getNextKnuthElements(lc, 0)); + // test the case where resolution returns non null + List l = new ArrayList(); + when(tablelm.resolveRetrieveTableMarker(rtm)).thenReturn(rtm); + when(tlm.getNextKnuthElements(lc, 0)).thenReturn(l); + assertEquals(l, rtmlm.getNextKnuthElements(lc, 0)); + verify(tlm).setParent(blm); + verify(tlm).initialize(); + } + +} diff --git a/test/java/org/apache/fop/layoutmgr/table/TableCellLayoutManagerTestCase.java b/test/java/org/apache/fop/layoutmgr/table/TableCellLayoutManagerTestCase.java new file mode 100644 index 000000000..c2fc84551 --- /dev/null +++ b/test/java/org/apache/fop/layoutmgr/table/TableCellLayoutManagerTestCase.java @@ -0,0 +1,116 @@ +/* + * 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.layoutmgr.table; + +import java.awt.Color; + +import org.junit.Test; + +import org.apache.fop.fo.flow.table.PrimaryGridUnit; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.fo.flow.table.TableCell; +import org.apache.fop.fo.flow.table.TableColumn; +import org.apache.fop.fo.flow.table.TableHeader; +import org.apache.fop.fo.flow.table.TableRow; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo; +import org.apache.fop.fo.properties.CondLengthProperty; +import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.PageSequenceLayoutManager; +import org.apache.fop.layoutmgr.PositionIterator; +import org.apache.fop.layoutmgr.RetrieveTableMarkerLayoutManager; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class TableCellLayoutManagerTestCase { + + // this test aims to check that the first call to addAreas() calls + // TLM.saveTableHeaderTableCellLayoutManagers() but the second call, through repeatAddAreas() + // does not call it again; there are a lot of mocks here, but just the necessary so that the + // addAreas() call can run to completion without NPE; also, the mocking needs to be done so + // the methods isDecendantOfTableHeaderOrFooter() and hasRetrieveTableMarker() return true. + @Test + public void testRepeatAddAreas() { + LayoutContext lc = LayoutContext.newInstance(); + // mock background + CommonBorderPaddingBackground cbpb = mock(CommonBorderPaddingBackground.class); + // mock conditional length property + CondLengthProperty clp = mock(CondLengthProperty.class); + when(clp.getLengthValue()).thenReturn(0); + // real border info + BorderInfo bi = BorderInfo.getInstance(0, clp, Color.BLACK, clp, clp); + // mock column + TableColumn tcol = mock(TableColumn.class); + when(tcol.getCommonBorderPaddingBackground()).thenReturn(cbpb); + // mock table + Table t = mock(Table.class); + when(t.getColumn(0)).thenReturn(tcol); + // mock header + TableHeader th = mock(TableHeader.class); + when(th.getCommonBorderPaddingBackground()).thenReturn(cbpb); + // mock row + TableRow tr = mock(TableRow.class); + when(tr.getParent()).thenReturn(th); + // mock cell + TableCell tc = mock(TableCell.class); + when(tc.hasRetrieveTableMarker()).thenReturn(true); + when(tc.getTable()).thenReturn(t); + when(tc.getId()).thenReturn("cellId"); + when(tc.getCommonBorderPaddingBackground()).thenReturn(cbpb); + when(tc.getParent()).thenReturn(tr); + // mock PGU + PrimaryGridUnit pgu = mock(PrimaryGridUnit.class); + when(pgu.getCell()).thenReturn(tc); + when(pgu.getColIndex()).thenReturn(0); + when(pgu.getBorderBefore(0)).thenReturn(bi); + when(pgu.getBorderAfter(0)).thenReturn(bi); + when(pgu.getBorderEnd()).thenReturn(bi); + when(pgu.getBorderStart()).thenReturn(bi); + when(pgu.getTablePart()).thenReturn(th); + // mock RTMLM + RetrieveTableMarkerLayoutManager rtmlm = mock(RetrieveTableMarkerLayoutManager.class); + when(rtmlm.isFinished()).thenReturn(true); // avoids infinite loop + // mock PSLM + PageSequenceLayoutManager pslm = mock(PageSequenceLayoutManager.class); + // mock TLM + TableLayoutManager tlm = mock(TableLayoutManager.class); + when(tlm.getPSLM()).thenReturn(pslm); + // mock PI + PositionIterator pi = mock(PositionIterator.class); + // mock RP + RowPainter rp = mock(RowPainter.class); + + // real TCLM, not a mock! + TableCellLayoutManager tclm = new TableCellLayoutManager(tc, pgu); + tclm.addChildLM(rtmlm); + tclm.setParent(tlm); + // lets call addAreas + int[] n = {}; + tclm.addAreas(pi, lc, n, 0, 0, 0, 0, true, true, rp, 0); + // check the TCLM is added to the TLM + verify(tlm).saveTableHeaderTableCellLayoutManagers(tclm); + // call the repeat + tclm.repeatAddAreas(); + // check the TCLM was not added again + verify(tlm).saveTableHeaderTableCellLayoutManagers(tclm); + } +} diff --git a/test/java/org/apache/fop/layoutmgr/table/TableContentLayoutManagerTestCase.java b/test/java/org/apache/fop/layoutmgr/table/TableContentLayoutManagerTestCase.java new file mode 100644 index 000000000..2bc41979c --- /dev/null +++ b/test/java/org/apache/fop/layoutmgr/table/TableContentLayoutManagerTestCase.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.layoutmgr.table; + +import org.junit.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.fop.fo.FONode.FONodeIterator; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.layoutmgr.LayoutContext; +import org.apache.fop.layoutmgr.PositionIterator; + +public class TableContentLayoutManagerTestCase { + + @Test + public void testAddAreas() { + LayoutContext lc = LayoutContext.newInstance(); + // mock + ColumnSetup cs = mock(ColumnSetup.class); + when(cs.getColumnCount()).thenReturn(3); + // mock + FONodeIterator foni = mock(FONodeIterator.class); + when(foni.hasNext()).thenReturn(false); + // mock + Table t = mock(Table.class); + when(t.getChildNodes()).thenReturn(foni); + when(t.getMarkers()).thenReturn(null); + // mock + TableLayoutManager tlm = mock(TableLayoutManager.class); + when(tlm.getTable()).thenReturn(t); + when(tlm.getColumns()).thenReturn(cs); + // mock + PositionIterator pi = mock(PositionIterator.class); + when(pi.hasNext()).thenReturn(false); + // real TCLM, not a mock + TableContentLayoutManager tclm = new TableContentLayoutManager(tlm); + // check that addAreas() calls the clearTableFragments() on the table and the + // repeatAddAreasForSavedTableHeaderTableCellLayoutManagers on the TLM + tclm.addAreas(pi, lc); + verify(tlm).clearTableFragmentMarkers(); + verify(tlm).repeatAddAreasForSavedTableHeaderTableCellLayoutManagers(); + } + +} diff --git a/test/java/org/apache/fop/layoutmgr/table/TableLayoutManagerTestCase.java b/test/java/org/apache/fop/layoutmgr/table/TableLayoutManagerTestCase.java new file mode 100644 index 000000000..46a394eb7 --- /dev/null +++ b/test/java/org/apache/fop/layoutmgr/table/TableLayoutManagerTestCase.java @@ -0,0 +1,119 @@ +/* + * 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.layoutmgr.table; + +import java.util.HashMap; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.fop.area.PageViewport; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.flow.Marker; +import org.apache.fop.fo.flow.RetrieveTableMarker; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.layoutmgr.BlockLayoutManager; +import org.apache.fop.layoutmgr.Page; +import org.apache.fop.layoutmgr.PageSequenceLayoutManager; + +public class TableLayoutManagerTestCase { + + @Test + public void testSavedTableCellLayoutManagersFunctionality() { + Table t = mock(Table.class); + TableCellLayoutManager tclm1 = mock(TableCellLayoutManager.class); + TableLayoutManager tlm = new TableLayoutManager(t); + tlm.saveTableHeaderTableCellLayoutManagers(tclm1); + tlm.repeatAddAreasForSavedTableHeaderTableCellLayoutManagers(); + verify(tclm1).repeatAddAreas(); // called once + // test that after the first repeatAddAreas() call the list closes to new additions + TableCellLayoutManager tclm2 = mock(TableCellLayoutManager.class); + tlm.saveTableHeaderTableCellLayoutManagers(tclm2); + tlm.repeatAddAreasForSavedTableHeaderTableCellLayoutManagers(); + verify(tclm1, times(2)).repeatAddAreas(); // called twice + verify(tclm2, never()).repeatAddAreas(); // never called + } + + @Test + public void testResolveRetrieveTableMarker() { + // mock + Table t = mock(Table.class); + // mock + Marker m = mock(Marker.class); + // mock + RetrieveTableMarker rtm = mock(RetrieveTableMarker.class); + when(rtm.getRetrieveClassName()).thenReturn("A"); + when(rtm.getPosition()).thenReturn(Constants.EN_FIRST_STARTING); + // mock + PageViewport pv = mock(PageViewport.class); + when(pv.resolveMarker(rtm)).thenReturn(m); + // mock + Page p = mock(Page.class); + when(p.getPageViewport()).thenReturn(pv); + // mock + PageSequenceLayoutManager pslm = mock(PageSequenceLayoutManager.class); + when(pslm.getPSLM()).thenReturn(pslm); + when(pslm.getCurrentPage()).thenReturn(p); + // mock + BlockLayoutManager blm = mock(BlockLayoutManager.class); + blm.setParent(pslm); + when(blm.getPSLM()).thenReturn(pslm); + // real TLM, not mock + TableLayoutManager tlm = new TableLayoutManager(t); + tlm.setParent(blm); + // register a marker + HashMap<String, Marker> markers1 = new HashMap<String, Marker>(); + Marker m1 = mock(Marker.class); + markers1.put("A", m1); + tlm.registerMarkers(markers1, true, true, true); + tlm.registerMarkers(markers1, false, true, true); + // check that if there is a marker at table fragment level the RTM is returned + assertEquals(rtm, tlm.resolveRetrieveTableMarker(rtm)); + verify(rtm, never()).getBoundary(); + // check that if there is no marker at table fragment level and that is the boundary + // we get a null return value + when(rtm.getBoundary()).thenReturn(Constants.EN_TABLE_FRAGMENT); + when(rtm.getRetrieveClassName()).thenReturn("B"); + assertNull(tlm.resolveRetrieveTableMarker(rtm)); + verify(rtm).getBoundary(); + verify(rtm, never()).changePositionTo(Constants.EN_LAST_ENDING); + // check that if there is no marker at table fragment level and the boundary is page + // then we try to do the resolution at page level; test the case a marker is found + when(rtm.getBoundary()).thenReturn(Constants.EN_PAGE); + assertEquals(rtm, tlm.resolveRetrieveTableMarker(rtm)); + verify(rtm).changePositionTo(Constants.EN_LAST_ENDING); + verify(rtm).changePositionTo(Constants.EN_FIRST_STARTING); + verify(pv).resolveMarker(rtm); + // test the same situation but in this case the marker is not found + when(pv.resolveMarker(rtm)).thenReturn(null); + assertNull(tlm.resolveRetrieveTableMarker(rtm)); + // test the situation where the marker is not found at page level but the boundary is table + when(rtm.getBoundary()).thenReturn(Constants.EN_TABLE); + assertNull(tlm.resolveRetrieveTableMarker(rtm)); + } + +} diff --git a/test/java/org/apache/fop/pdf/PDFEncodingTestCase.java b/test/java/org/apache/fop/pdf/PDFEncodingTestCase.java new file mode 100644 index 000000000..34e48f1a6 --- /dev/null +++ b/test/java/org/apache/fop/pdf/PDFEncodingTestCase.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. + */ + +package org.apache.fop.pdf; + +import org.junit.Test; + +import org.apache.fop.fonts.CodePointMapping; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +public class PDFEncodingTestCase { + + /** + * Tests the createPDFEncoding method to ensure a null encoding type + * is handled correctly. + */ + @Test + public void testCreatePDFEncodingForNull() { + Object encoding = PDFEncoding.createPDFEncoding(null, "Test"); + assertEquals(encoding, null); + } + + /** + * Tests that when a PDFEncoding object is created, if the encoding type is + * that of StandardEncoding, the baseEncoding tag is omitted. + */ + @Test + public void testStandardEncodingDiffs() { + Object encoding = PDFEncoding.createPDFEncoding(CodePointMapping.getMapping( + CodePointMapping.SYMBOL_ENCODING), "Test"); + if (encoding instanceof PDFEncoding) { + PDFEncoding pdfEncoding = (PDFEncoding) encoding; + assertFalse(pdfEncoding.entries.containsKey("BaseEncoding")); + } + } + + /** + * Tests that when the StandardEncoding type is provided and there are no + * differences, the returned encoding object is null. + */ + @Test + public void testStandardEncodingNoDiff() { + Object encoding = PDFEncoding.createPDFEncoding(CodePointMapping.getMapping( + CodePointMapping.STANDARD_ENCODING), "Test"); + assertEquals(encoding, null); + } + + /** + * Tests that when the SymbolEncoding type is provided and there are no + * differences, the returned encoding string is that of SymbolEncoding. + */ + @Test + public void testCreatePDFEncodingSymbol() { + Object encoding = PDFEncoding.createPDFEncoding(CodePointMapping.getMapping( + CodePointMapping.SYMBOL_ENCODING), "Symbol"); + assert (encoding instanceof String); + String pdfEncoding = (String) encoding; + assertEquals(pdfEncoding, "SymbolEncoding"); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java b/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java index ac9df4046..5e4b9e2e4 100644 --- a/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java @@ -24,14 +24,17 @@ import java.net.URI; import org.junit.Test; +import static org.junit.Assert.assertEquals; + +import org.apache.xmlgraphics.io.ResourceResolver; + import org.apache.fop.apps.io.InternalResourceResolver; -import org.apache.fop.apps.io.ResourceResolver; import org.apache.fop.apps.io.ResourceResolverFactory; +import org.apache.fop.fonts.CIDSet; import org.apache.fop.fonts.CIDSubset; +import org.apache.fop.fonts.EmbeddingMode; import org.apache.fop.fonts.MultiByteFont; -import static org.junit.Assert.assertEquals; - /** * Test case for {@link PDFFactory}. */ @@ -45,7 +48,7 @@ public class PDFFactoryTestCase { public void testSubsetFontNamePrefix() { class MockedFont extends MultiByteFont { public MockedFont(InternalResourceResolver resolver) { - super(resolver); + super(resolver, EmbeddingMode.AUTO); } @Override @@ -54,8 +57,8 @@ public class PDFFactoryTestCase { } @Override - public CIDSubset getCIDSubset() { - return new CIDSubset(); + public CIDSet getCIDSet() { + return new CIDSubset(this); } } PDFDocument doc = new PDFDocument("Test"); diff --git a/test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java b/test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java index 89682628d..a1d581402 100644 --- a/test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java +++ b/test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java @@ -52,7 +52,8 @@ public class TableHeaderScopeTestCase { VersionController controller = mock(VersionController.class); PDFDocument document = new PDFDocument("Test", controller); document.makeStructTreeRoot(null); - document.makeStructureElement(Table.TH, null, scope); + PDFStructElem th = new PDFStructElem(null, Table.TH); + document.registerStructureElement(th, scope); verify(controller).addTableHeaderScopeAttribute(any(PDFStructElem.class), eq(scope)); } diff --git a/test/java/org/apache/fop/render/bitmap/TIFFCompressionValueTestCase.java b/test/java/org/apache/fop/render/bitmap/TIFFCompressionValueTestCase.java new file mode 100644 index 000000000..c4285f034 --- /dev/null +++ b/test/java/org/apache/fop/render/bitmap/TIFFCompressionValueTestCase.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.fop.render.bitmap; + +import java.awt.image.BufferedImage; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T4; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T6; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.DEFLATE; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.JPEG; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.LZW; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.NONE; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.PACKBITS; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.ZLIB; + +public class TIFFCompressionValueTestCase { + + @Test + public void testGetName() { + testCompressionName("NONE", NONE); + testCompressionName("JPEG", JPEG); + testCompressionName("PackBits", PACKBITS); + testCompressionName("Deflate", DEFLATE); + testCompressionName("LZW", LZW); + testCompressionName("ZLib", ZLIB); + testCompressionName("CCITT T.4", CCITT_T4); + testCompressionName("CCITT T.6", CCITT_T6); + } + + private void testCompressionName(String name, TIFFCompressionValue expected) { + assertEquals(name, expected.getName()); + assertEquals(expected, TIFFCompressionValue.getType(name)); + } + + @Test + public void testGetImageType() { + for (TIFFCompressionValue value : TIFFCompressionValue.values()) { + if (value == CCITT_T4 || value == CCITT_T6) { + assertEquals(BufferedImage.TYPE_BYTE_BINARY, value.getImageType()); + } else { + assertEquals(BufferedImage.TYPE_INT_ARGB, value.getImageType()); + } + } + } + + @Test + public void testHasCCITTCompression() { + for (TIFFCompressionValue value : TIFFCompressionValue.values()) { + if (value == CCITT_T4 || value == CCITT_T6) { + assertTrue(value.hasCCITTCompression()); + } else { + assertFalse(value.hasCCITTCompression()); + } + } + } +} diff --git a/test/java/org/apache/fop/render/bitmap/TIFFRendererConfigParserTestCase.java b/test/java/org/apache/fop/render/bitmap/TIFFRendererConfigParserTestCase.java index d938d094d..69326559e 100644 --- a/test/java/org/apache/fop/render/bitmap/TIFFRendererConfigParserTestCase.java +++ b/test/java/org/apache/fop/render/bitmap/TIFFRendererConfigParserTestCase.java @@ -26,9 +26,11 @@ import org.apache.fop.apps.TIFFRendererConfBuilder; import org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererConfigParser; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class TIFFRendererConfigParserTestCase - extends AbstractBitmapRendererConfigParserTester { +extends AbstractBitmapRendererConfigParserTester { public TIFFRendererConfigParserTestCase() { super(new TIFFRendererConfigParser()); @@ -47,9 +49,17 @@ public class TIFFRendererConfigParserTestCase @Test public void testCompression() throws Exception { - for (TIFFCompressionValues value : TIFFCompressionValues.values()) { + for (TIFFCompressionValue value : TIFFCompressionValue.values()) { parseConfig(createRenderer().setCompressionMode(value.getName())); assertEquals(value, getConfig().getCompressionType()); } } + + @Test + public void testSingleStrip() throws Exception { + parseConfig(createRenderer().setSingleStrip(true)); + assertTrue(getConfig().isSingleStrip()); + parseConfig(createRenderer().setSingleStrip(false)); + assertFalse(getConfig().isSingleStrip()); + } } diff --git a/test/java/org/apache/fop/render/bitmap/TIFFRendererConfiguratorTestCase.java b/test/java/org/apache/fop/render/bitmap/TIFFRendererConfiguratorTestCase.java index 9dd40e030..3e6c951a6 100644 --- a/test/java/org/apache/fop/render/bitmap/TIFFRendererConfiguratorTestCase.java +++ b/test/java/org/apache/fop/render/bitmap/TIFFRendererConfiguratorTestCase.java @@ -23,14 +23,17 @@ import java.awt.image.BufferedImage; import org.junit.Test; + import org.apache.fop.apps.FopConfBuilder; import org.apache.fop.apps.MimeConstants; import org.apache.fop.apps.TIFFRendererConfBuilder; import org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererConfigParser; -import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T4; -import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T6; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T4; +import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T6; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class TIFFRendererConfiguratorTestCase extends AbstractBitmapRendererConfiguratorTest { @@ -51,7 +54,7 @@ public class TIFFRendererConfiguratorTestCase extends AbstractBitmapRendererConf @Test @Override public void testColorModes() throws Exception { - for (TIFFCompressionValues value : TIFFCompressionValues.values()) { + for (TIFFCompressionValue value : TIFFCompressionValue.values()) { parseConfig(createBuilder().setCompressionMode(value.getName())); if (value == CCITT_T6 || value == CCITT_T4) { assertEquals(BufferedImage.TYPE_BYTE_BINARY, settings.getBufferedImageType()); @@ -60,4 +63,13 @@ public class TIFFRendererConfiguratorTestCase extends AbstractBitmapRendererConf } } } + + @Test + public void testSingleStrip() throws Exception { + parseConfig(createBuilder().setSingleStrip(true)); + assertTrue(settings.getWriterParams().isSingleStrip()); + parseConfig(createBuilder().setSingleStrip(false)); + assertFalse(settings.getWriterParams().isSingleStrip()); + } + } |