diff options
author | Peter Hancock <phancock@apache.org> | 2012-08-16 13:31:38 +0000 |
---|---|---|
committer | Peter Hancock <phancock@apache.org> | 2012-08-16 13:31:38 +0000 |
commit | 80e1071780dacf1235c0f31bf20fe6c6df7ff8e8 (patch) | |
tree | 012a241ed426e2d10965ab402f04f84c9827b421 /test/java | |
parent | 3e96fb119fcbd9e6e0644092b0e2376bdbbe6c10 (diff) | |
parent | 726e1ef3093bedfd6671c2e6471e0d62ef605be5 (diff) | |
download | xmlgraphics-fop-80e1071780dacf1235c0f31bf20fe6c6df7ff8e8.tar.gz xmlgraphics-fop-80e1071780dacf1235c0f31bf20fe6c6df7ff8e8.zip |
Merged trunk@1373227
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_RoundedCorners@1373825 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java')
-rw-r--r-- | test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java | 5 | ||||
-rw-r--r-- | test/java/org/apache/fop/afp/util/AFPResourceAccessorTestCase.java | 84 | ||||
-rw-r--r-- | test/java/org/apache/fop/apps/FopConfBuilder.java | 12 | ||||
-rw-r--r-- | test/java/org/apache/fop/apps/FopConfParserTestCase.java | 8 | ||||
-rw-r--r-- | test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java | 2 | ||||
-rw-r--r-- | test/java/org/apache/fop/apps/FopFactoryTestCase.java (renamed from test/java/org/apache/fop/config/SingleFopConfParseTestCase.java) | 9 | ||||
-rw-r--r-- | test/java/org/apache/fop/apps/MutableConfig.java | 133 | ||||
-rw-r--r-- | test/java/org/apache/fop/events/EventChecker.java | 11 | ||||
-rw-r--r-- | test/java/org/apache/fop/events/EventProcessingTestCase.java | 31 | ||||
-rw-r--r-- | test/java/org/apache/fop/fotreetest/FOTreeTestCase.java | 111 | ||||
-rw-r--r-- | test/java/org/apache/fop/intermediate/IFParserTestCase.java | 17 | ||||
-rw-r--r-- | test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java | 7 | ||||
-rw-r--r-- | test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java | 131 |
13 files changed, 422 insertions, 139 deletions
diff --git a/test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java b/test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java index 521deacea..d1b47846b 100644 --- a/test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java +++ b/test/java/org/apache/fop/afp/AFPEventProcessingTestCase.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.apache.xmlgraphics.util.MimeConstants; +import org.apache.fop.apps.FOPException; import org.apache.fop.events.EventProcessingTestCase; @@ -49,12 +50,12 @@ public class AFPEventProcessingTestCase { testInvalidConfigEvent("afp-font-missing.xconf", ".fontConfigMissing"); } - @Test + @Test(expected = FOPException.class) public void testInvalidCharactersetName() throws Exception { testInvalidConfigEvent("afp-invalid-characterset.xconf", ".characterSetNameInvalid"); } - @Test + @Test(expected = FOPException.class) public void testinvalidConfig() throws Exception { testInvalidConfigEvent("afp-invalid-config.xconf", ".invalidConfiguration"); } diff --git a/test/java/org/apache/fop/afp/util/AFPResourceAccessorTestCase.java b/test/java/org/apache/fop/afp/util/AFPResourceAccessorTestCase.java new file mode 100644 index 000000000..d729d336d --- /dev/null +++ b/test/java/org/apache/fop/afp/util/AFPResourceAccessorTestCase.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.fop.afp.util; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.apache.fop.apps.io.InternalResourceResolver; + +public class AFPResourceAccessorTestCase { + + private InternalResourceResolver nullBaseResourceResolver; + private InternalResourceResolver absoluteBaseResourceResolver; + private InternalResourceResolver relativeBaseResourceResolver; + private final URI absoluteBaseURI = URI.create("this:///purely.for.testing"); + private final URI relativeBaseURI = URI.create("./this.is.purely.for.testing"); + private AFPResourceAccessor nullBaseURISut; + private AFPResourceAccessor absoluteBaseURISut; + private AFPResourceAccessor relativeBaseURISut; + + @Before + public void setUp() { + nullBaseResourceResolver = mock(InternalResourceResolver.class); + absoluteBaseResourceResolver = mock(InternalResourceResolver.class); + relativeBaseResourceResolver = mock(InternalResourceResolver.class); + nullBaseURISut = new AFPResourceAccessor(nullBaseResourceResolver); + absoluteBaseURISut = new AFPResourceAccessor(absoluteBaseResourceResolver, + absoluteBaseURI.toASCIIString()); + relativeBaseURISut = new AFPResourceAccessor(relativeBaseResourceResolver, + relativeBaseURI.toASCIIString()); + } + + @Test + public void testCreateInputStream() throws IOException, URISyntaxException { + URI testURI = URI.create("test"); + nullBaseURISut.createInputStream(testURI); + verify(nullBaseResourceResolver).getResource(testURI); + + absoluteBaseURISut.createInputStream(testURI); + verify(absoluteBaseResourceResolver).getResource(getActualURI(absoluteBaseURI, testURI)); + + relativeBaseURISut.createInputStream(testURI); + verify(relativeBaseResourceResolver).getResource(getActualURI(relativeBaseURI, testURI)); + } + + private URI getActualURI(URI baseURI, URI testURI) throws URISyntaxException { + return InternalResourceResolver.getBaseURI(baseURI.toASCIIString()).resolve(testURI); + } + + @Test + public void testResolveURI() throws URISyntaxException { + String testURI = "anotherTestURI"; + assertEquals(URI.create("./" + testURI), nullBaseURISut.resolveURI(testURI)); + + assertEquals(getActualURI(absoluteBaseURI, URI.create(testURI)), + absoluteBaseURISut.resolveURI(testURI)); + + assertEquals(getActualURI(relativeBaseURI, URI.create(testURI)), + relativeBaseURISut.resolveURI(testURI)); + } +} diff --git a/test/java/org/apache/fop/apps/FopConfBuilder.java b/test/java/org/apache/fop/apps/FopConfBuilder.java index 1efb2d698..8dd882d8a 100644 --- a/test/java/org/apache/fop/apps/FopConfBuilder.java +++ b/test/java/org/apache/fop/apps/FopConfBuilder.java @@ -113,7 +113,17 @@ public class FopConfBuilder implements FontConfigurator<FopConfBuilder> { /** * Set the <strict-validation> tag within the fop.xconf. * - * @param validateStrictly true to enforce strict validation + * @param validateStrictly true to enforce strict FO validation + * @return <b>this</b> + */ + public FopConfBuilder setStrictConfiguration(boolean validateStrictly) { + return createElement("strict-configuration", String.valueOf(validateStrictly)); + } + + /** + * Set the <strict-validation> tag within the fop.xconf. + * + * @param validateStrictly true to enforce strict configuration validation * @return <b>this</b> */ public FopConfBuilder setStrictValidation(boolean validateStrictly) { diff --git a/test/java/org/apache/fop/apps/FopConfParserTestCase.java b/test/java/org/apache/fop/apps/FopConfParserTestCase.java index 2fe939f76..3c2930942 100644 --- a/test/java/org/apache/fop/apps/FopConfParserTestCase.java +++ b/test/java/org/apache/fop/apps/FopConfParserTestCase.java @@ -75,8 +75,14 @@ public class FopConfParserTestCase { } @Test - public void testStrictUserConfigValidation() { + public void testStrictFOValidation() { builder.setStrictValidation(false); + assertFalse(buildFactory().validateStrictly()); + } + + @Test + public void testStrictUserValidation() { + builder.setStrictConfiguration(false); assertFalse(buildFactory().validateUserConfigStrictly()); } diff --git a/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java b/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java index f56373218..e504c4bc4 100644 --- a/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java +++ b/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java @@ -162,7 +162,7 @@ public class FopFactoryBuilderTestCase { public void run() { URI nonDefaultURI = URI.create("./test/"); defaultBuilder.setBaseURI(nonDefaultURI); - assertEquals(nonDefaultURI, defaultBuilder.buildConfig().getBaseURI()); + assertEquals(nonDefaultURI, defaultBuilder.buildConfiguration().getBaseURI()); } }); } diff --git a/test/java/org/apache/fop/config/SingleFopConfParseTestCase.java b/test/java/org/apache/fop/apps/FopFactoryTestCase.java index 430de318b..8ac21c994 100644 --- a/test/java/org/apache/fop/config/SingleFopConfParseTestCase.java +++ b/test/java/org/apache/fop/apps/FopFactoryTestCase.java @@ -17,16 +17,15 @@ /* $Id$ */ -package org.apache.fop.config; +package org.apache.fop.apps; import java.io.IOException; import org.junit.Test; import org.xml.sax.SAXException; -import org.apache.fop.apps.FopConfBuilder; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.apps.PDFRendererConfBuilder; +import org.apache.fop.config.BaseConstructiveUserConfigTest; import org.apache.fop.render.RendererConfig.RendererConfigParser; import org.apache.fop.render.pdf.PDFRendererConfig; @@ -35,9 +34,9 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class SingleFopConfParseTestCase extends BaseConstructiveUserConfigTest { +public class FopFactoryTestCase extends BaseConstructiveUserConfigTest { - public SingleFopConfParseTestCase() throws SAXException, IOException { + public FopFactoryTestCase() throws SAXException, IOException { super(new FopConfBuilder().setStrictValidation(true) .startRendererConfig(PDFRendererConfBuilder.class) .startFontsConfig() diff --git a/test/java/org/apache/fop/apps/MutableConfig.java b/test/java/org/apache/fop/apps/MutableConfig.java new file mode 100644 index 000000000..79f038f24 --- /dev/null +++ b/test/java/org/apache/fop/apps/MutableConfig.java @@ -0,0 +1,133 @@ +/* + * 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.apps; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import org.apache.avalon.framework.configuration.Configuration; + +import org.apache.xmlgraphics.image.loader.ImageManager; + +import org.apache.fop.apps.io.ResourceResolver; +import org.apache.fop.fonts.FontManager; +import org.apache.fop.layoutmgr.LayoutManagerMaker; + +/** + * This is a mutable implementation of the {@link FopFactoryConfig} to be used for testing purposes. + * This is also an example of how to make the seemingly immutable {@link FopFactory} mutable should + * a client need to, though this is ill-advised. + */ +public final class MutableConfig implements FopFactoryConfig { + + private final FopFactoryConfig delegate; + + private boolean setBreakInheritance; + private float sourceResolution; + + public MutableConfig(FopFactoryBuilder factoryBuilder) { + delegate = factoryBuilder.buildConfiguration(); + setBreakInheritance = delegate.isBreakIndentInheritanceOnReferenceAreaBoundary(); + sourceResolution = delegate.getSourceResolution(); + } + + public boolean isAccessibilityEnabled() { + return delegate.isAccessibilityEnabled(); + } + + public LayoutManagerMaker getLayoutManagerMakerOverride() { + return delegate.getLayoutManagerMakerOverride(); + } + + public ResourceResolver getResourceResolver() { + return delegate.getResourceResolver(); + } + + public URI getBaseURI() { + return delegate.getBaseURI(); + } + + public boolean validateStrictly() { + return delegate.validateStrictly(); + } + + public boolean validateUserConfigStrictly() { + return delegate.validateUserConfigStrictly(); + } + + public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() { + return setBreakInheritance; + } + + public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) { + setBreakInheritance = value; + } + + public float getSourceResolution() { + return sourceResolution; + } + + public void setSourceResolution(float srcRes) { + sourceResolution = srcRes; + } + + public float getTargetResolution() { + return delegate.getTargetResolution(); + } + + public String getPageHeight() { + return delegate.getPageHeight(); + } + + public String getPageWidth() { + return delegate.getPageWidth(); + } + + public Set<String> getIgnoredNamespaces() { + return delegate.getIgnoredNamespaces(); + } + + public boolean isNamespaceIgnored(String namespace) { + return delegate.isNamespaceIgnored(namespace); + } + + public Configuration getUserConfig() { + return delegate.getUserConfig(); + } + + public boolean preferRenderer() { + return delegate.preferRenderer(); + } + + public FontManager getFontManager() { + return delegate.getFontManager(); + } + + public ImageManager getImageManager() { + return delegate.getImageManager(); + } + + public boolean isComplexScriptFeaturesEnabled() { + return delegate.isComplexScriptFeaturesEnabled(); + } + + public Map<String, String> getHyphenationPatternNames() { + return delegate.getHyphenationPatternNames(); + } +} diff --git a/test/java/org/apache/fop/events/EventChecker.java b/test/java/org/apache/fop/events/EventChecker.java index dac67a8cc..3f0eef6bb 100644 --- a/test/java/org/apache/fop/events/EventChecker.java +++ b/test/java/org/apache/fop/events/EventChecker.java @@ -19,6 +19,9 @@ package org.apache.fop.events; +import java.util.Map; + +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; /** @@ -28,10 +31,13 @@ class EventChecker implements EventListener { private final String expectedEventID; + private final Map<String, Object> expectedParams; + private boolean eventReceived; - EventChecker(String expectedEventID) { + EventChecker(String expectedEventID, Map<String, Object> expectedParams) { this.expectedEventID = expectedEventID; + this.expectedParams = expectedParams; } public void processEvent(Event event) { @@ -39,6 +45,9 @@ class EventChecker implements EventListener { String id = event.getEventID(); if (id.equals(expectedEventID)) { eventReceived = true; + for (Map.Entry<String, Object> param : expectedParams.entrySet()) { + assertEquals(event.getParam(param.getKey()), param.getValue()); + } } } diff --git a/test/java/org/apache/fop/events/EventProcessingTestCase.java b/test/java/org/apache/fop/events/EventProcessingTestCase.java index 9338fc01a..fb17c9c0c 100644 --- a/test/java/org/apache/fop/events/EventProcessingTestCase.java +++ b/test/java/org/apache/fop/events/EventProcessingTestCase.java @@ -22,6 +22,9 @@ package org.apache.fop.events; import java.io.File; import java.io.InputStream; import java.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import javax.xml.transform.Result; import javax.xml.transform.Source; @@ -62,9 +65,10 @@ public class EventProcessingTestCase { CONFIG_BASE_DIR = base.resolve("test/config/"); } - public void doTest(InputStream inStream, URI fopConf, String expectedEventID, String mimeType) - throws Exception { - EventChecker eventChecker = new EventChecker(expectedEventID); + + public void doTest(InputStream inStream, URI fopConf, String expectedEventID, String mimeType, + Map<String, Object> expectedParams) throws Exception { + EventChecker eventChecker = new EventChecker(expectedEventID, expectedParams); FopFactory fopFactory; if (fopConf != null) { fopFactory = FopFactory.newInstance(new File(fopConf)); @@ -81,6 +85,19 @@ public class EventProcessingTestCase { Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); eventChecker.end(); + + } + + public void doTest(InputStream inStream, URI fopConf, String expectedEventID, String mimeType) + throws Exception { + Map<String, Object> noParams = Collections.emptyMap(); + doTest(inStream, fopConf, expectedEventID, mimeType, noParams); + } + + public void doTest(String filename, String expectedEventID, Map<String, Object> expectedParams) + throws Exception { + doTest(BASE_DIR.resolve(filename).toURL().openStream(), null, expectedEventID, + MimeConstants.MIME_PDF, expectedParams); } public void doTest(String filename, String expectedEventID) throws Exception { @@ -133,4 +150,12 @@ public class EventProcessingTestCase { public void testViewportBPDOverflow() throws Exception { doTest("viewport-overflow.fo", BlockLevelEventProducer.class.getName() + ".viewportBPDOverflow"); } + + @Test + public void testPageOverflow() throws Exception { + Map<String, Object> params = new HashMap<String, Object>(); + params.put("page", "1"); + doTest("region-body_overflow.fo", BlockLevelEventProducer.class.getName() + ".regionOverflow", + params); + } } diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java b/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java index ab6411b3a..3d58e7ef0 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java @@ -20,11 +20,8 @@ package org.apache.fop.fotreetest; import java.io.File; -import java.net.URI; import java.util.Collection; import java.util.List; -import java.util.Map; -import java.util.Set; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -38,22 +35,16 @@ import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLFilterImpl; -import org.apache.avalon.framework.configuration.Configuration; - -import org.apache.xmlgraphics.image.loader.ImageManager; - import org.apache.fop.DebugHelper; 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.FopFactoryConfig; -import org.apache.fop.apps.io.ResourceResolver; -import org.apache.fop.fonts.FontManager; +import org.apache.fop.apps.MutableConfig; import org.apache.fop.fotreetest.ext.TestElementMapping; import org.apache.fop.layoutengine.LayoutEngineTestUtils; import org.apache.fop.layoutengine.TestFilesConfiguration; -import org.apache.fop.layoutmgr.LayoutManagerMaker; import org.apache.fop.util.ConsoleEventListenerForTests; /** @@ -123,7 +114,7 @@ public class FOTreeTestCase { FopFactoryConfig.DEFAULT_BREAK_INDENT_INHERITANCE); builder.setSourceResolution(FopFactoryConfig.DEFAULT_SOURCE_RESOLUTION); - MutableConfig mutableConfig = new MutableConfig(builder.buildConfig()); + MutableConfig mutableConfig = new MutableConfig(builder); FopFactory fopFactory = FopFactory.newInstance(mutableConfig); fopFactory.addElementMapping(new TestElementMapping()); @@ -181,102 +172,4 @@ public class FOTreeTestCase { super.processingInstruction(target, data); } } - - private static final class MutableConfig implements FopFactoryConfig { - - private final FopFactoryConfig delegate; - - private boolean setBreakInheritance; - private float sourceResolution; - - private MutableConfig(FopFactoryConfig wrappedConfig) { - delegate = wrappedConfig; - setBreakInheritance = delegate.isBreakIndentInheritanceOnReferenceAreaBoundary(); - sourceResolution = delegate.getSourceResolution(); - } - - public boolean isAccessibilityEnabled() { - return delegate.isAccessibilityEnabled(); - } - - public LayoutManagerMaker getLayoutManagerMakerOverride() { - return delegate.getLayoutManagerMakerOverride(); - } - - public ResourceResolver getResourceResolver() { - return delegate.getResourceResolver(); - } - - public URI getBaseURI() { - return delegate.getBaseURI(); - } - - public boolean validateStrictly() { - return delegate.validateStrictly(); - } - - public boolean validateUserConfigStrictly() { - return delegate.validateUserConfigStrictly(); - } - - public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() { - return setBreakInheritance; - } - - public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) { - setBreakInheritance = value; - } - - public float getSourceResolution() { - return sourceResolution; - } - - public void setSourceResolution(float srcRes) { - sourceResolution = srcRes; - } - - public float getTargetResolution() { - return delegate.getTargetResolution(); - } - - public String getPageHeight() { - return delegate.getPageHeight(); - } - - public String getPageWidth() { - return delegate.getPageWidth(); - } - - public Set<String> getIgnoredNamespaces() { - return delegate.getIgnoredNamespaces(); - } - - public boolean isNamespaceIgnored(String namespace) { - return delegate.isNamespaceIgnored(namespace); - } - - public Configuration getUserConfig() { - return delegate.getUserConfig(); - } - - public boolean preferRenderer() { - return delegate.preferRenderer(); - } - - public FontManager getFontManager() { - return delegate.getFontManager(); - } - - public ImageManager getImageManager() { - return delegate.getImageManager(); - } - - public boolean isComplexScriptFeaturesEnabled() { - return delegate.isComplexScriptFeaturesEnabled(); - } - - public Map<String, String> getHyphenationPatternNames() { - return delegate.getHyphenationPatternNames(); - } - } } diff --git a/test/java/org/apache/fop/intermediate/IFParserTestCase.java b/test/java/org/apache/fop/intermediate/IFParserTestCase.java index 45aa8ab0f..9a08816c6 100644 --- a/test/java/org/apache/fop/intermediate/IFParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/IFParserTestCase.java @@ -48,9 +48,6 @@ import org.apache.fop.render.intermediate.IFSerializer; @RunWith(Parameterized.class) public class IFParserTestCase extends AbstractIFTest { - /** Set this to true to get the correspondence between test number and test file. */ - private static final boolean DEBUG = false; - /** * Gets the parameters for this test * @@ -59,19 +56,7 @@ public class IFParserTestCase extends AbstractIFTest { */ @Parameters public static Collection<File[]> getParameters() throws IOException { - Collection<File[]> testFiles = LayoutEngineTestUtils.getLayoutTestFiles(); - if (DEBUG) { - printFiles(testFiles); - } - return testFiles; - } - - private static void printFiles(Collection<File[]> files) { - int index = 0; - for (File[] file : files) { - assert file.length == 1; - System.out.println(String.format("%3d %s", index++, file[0])); - } + return LayoutEngineTestUtils.getLayoutTestFiles(); } /** diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java index 935b86c3b..fb7f07023 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestUtils.java @@ -51,6 +51,9 @@ import org.apache.commons.io.filefilter.TrueFileFilter; */ public final class LayoutEngineTestUtils { + /** Set this to true to get the correspondence between test number and test file. */ + private static final boolean DEBUG = false; + private LayoutEngineTestUtils() { } @@ -157,8 +160,12 @@ public final class LayoutEngineTestUtils { } Collection<File[]> parametersForJUnit4 = new ArrayList<File[]>(); + int index = 0; for (File f : files) { parametersForJUnit4.add(new File[] { f }); + if (DEBUG) { + System.out.println(String.format("%3d %s", index++, f)); + } } return parametersForJUnit4; diff --git a/test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java b/test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java new file mode 100644 index 000000000..89682628d --- /dev/null +++ b/test/java/org/apache/fop/pdf/TableHeaderScopeTestCase.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.pdf; + +import org.junit.Test; +import org.mockito.ArgumentMatcher; +import org.mockito.verification.VerificationMode; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; +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 org.apache.fop.pdf.StandardStructureAttributes.Table.Scope; +import org.apache.fop.pdf.StandardStructureTypes.Table; + +public class TableHeaderScopeTestCase { + + private static final String ATTRIBUTE_ENTRY = "A"; + + private VersionController controller; + + @Test + public void pdfDocumentDelegatesToVersionController() { + for (Scope scope : Scope.values()) { + testMakeStructureElementWithScope(scope); + } + } + + private void testMakeStructureElementWithScope(Scope scope) { + VersionController controller = mock(VersionController.class); + PDFDocument document = new PDFDocument("Test", controller); + document.makeStructTreeRoot(null); + document.makeStructureElement(Table.TH, null, scope); + verify(controller).addTableHeaderScopeAttribute(any(PDFStructElem.class), eq(scope)); + } + + @Test + public void versionControllerMayDelegateToScope() { + fixedController14doesNotAddAttribute(); + fixedController15addsAttribute(); + dynamicControllerAddsAttribute(); + } + + private void fixedController14doesNotAddAttribute() { + controller = VersionController.getFixedVersionController(Version.V1_4); + scopeMustNotBeAdded(); + } + + private void fixedController15addsAttribute() { + controller = VersionController.getFixedVersionController(Version.V1_5); + scopeMustBeAdded(); + } + + private void dynamicControllerAddsAttribute() { + PDFDocument document = new PDFDocument("Test"); + controller = VersionController.getDynamicVersionController(Version.V1_4, document); + scopeMustBeAdded(); + assertEquals(Version.V1_5, controller.getPDFVersion()); + } + + private void scopeMustBeAdded() { + scopeMustBeAdded(times(1)); + } + + private void scopeMustNotBeAdded() { + scopeMustBeAdded(never()); + } + + private void scopeMustBeAdded(VerificationMode nTimes) { + PDFStructElem structElem = mock(PDFStructElem.class); + controller.addTableHeaderScopeAttribute(structElem, Scope.COLUMN); + verify(structElem, nTimes).put(eq(ATTRIBUTE_ENTRY), any()); + } + + @Test + public void scopeAddsTheAttribute() { + for (Scope scope : Scope.values()) { + scopeAttributeMustBeAdded(scope); + } + } + + private void scopeAttributeMustBeAdded(Scope scope) { + PDFStructElem structElem = mock(PDFStructElem.class); + Scope.addScopeAttribute(structElem, scope); + verify(structElem).put(eq(ATTRIBUTE_ENTRY), scopeAttribute(scope)); + } + + private PDFDictionary scopeAttribute(Scope scope) { + return argThat(new isScopeAttribute(scope)); + } + + private static class isScopeAttribute extends ArgumentMatcher<PDFDictionary> { + + private final Scope expectedScope; + + public isScopeAttribute(Scope expectedScope) { + this.expectedScope = expectedScope; + } + + @Override + public boolean matches(Object argument) { + PDFDictionary attribute = (PDFDictionary) argument; + return "/Table".equals(attribute.get("O").toString()) + && expectedScope.getName().toString().equals(attribute.get("Scope").toString()); + } + + } + +} |