aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2011-11-24 17:15:28 +0000
committerVincent Hennebert <vhennebert@apache.org>2011-11-24 17:15:28 +0000
commitc6fb066a02573904f7ca404605f14c800adf80c5 (patch)
treed73a722e23ae74124b1bcb691d0e6f0b2f0af32f /test/java/org/apache/fop
parentb073a605e44760bcb7add72968a3a2f78cf06d97 (diff)
downloadxmlgraphics-fop-c6fb066a02573904f7ca404605f14c800adf80c5.tar.gz
xmlgraphics-fop-c6fb066a02573904f7ca404605f14c800adf80c5.zip
Removed the DOM representation of the structure tree.
The structure tree is now directly converted into corresponding PDF objects. When going the IF route, the structure tree is stored in the form of SAX events that will be re-played when it's time to stream them into the output. This may still change. * Extracted RFC3066 methods from XMLUtil into new LanguageTags class that can be re-used in a non-XML context. * Dropped support for accessibility in the old Area Tree XML. * Added support for the xml:lang property on fo:root, so that the global language can be set for the document without retrieving the language from the first page-sequence. * Renamed StructureTreeBuilder into more appropriate StructureTreeEventHandler (same for applicable sub-classes) * Renamed StructureTreeBuildingFOEventHandler into FO2StructureTreeConverter and added test case * Added test cases for classes in the StructureTreeEventHandler hierarchy git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ImproveAccessibility@1205935 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop')
-rw-r--r--test/java/org/apache/fop/StandardTestSuite.java3
-rw-r--r--test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java202
-rw-r--r--test/java/org/apache/fop/accessibility/fo2StructureTree.xsl116
-rw-r--r--test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.java19
-rw-r--r--test/java/org/apache/fop/fo/FODocumentParser.java20
-rw-r--r--test/java/org/apache/fop/fo/complete_document.fo (renamed from test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.fo)3
-rw-r--r--test/java/org/apache/fop/fo/extract-events.xsl14
-rw-r--r--test/java/org/apache/fop/fo/properties/CommonAccessibilityHolderTestCase.java3
-rw-r--r--test/java/org/apache/fop/intermediate/IFParserTestCase.java17
-rw-r--r--test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java169
-rw-r--r--test/java/org/apache/fop/render/intermediate/SAXEventRecorderTestCase.java131
-rw-r--r--test/java/org/apache/fop/util/LanguageTagsTestCase.java (renamed from test/java/org/apache/fop/util/XMLUtilTestCase.java)34
12 files changed, 703 insertions, 28 deletions
diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java
index 1dacd9614..840b04917 100644
--- a/test/java/org/apache/fop/StandardTestSuite.java
+++ b/test/java/org/apache/fop/StandardTestSuite.java
@@ -68,7 +68,8 @@ import org.apache.fop.traits.MinOptMaxTest;
CharactersetEncoderTest.class,
org.apache.fop.render.afp.AFPTestSuite.class,
PSTestSuite.class,
- MinOptMaxTest.class
+ MinOptMaxTest.class,
+ org.apache.fop.render.intermediate.IFStructureTreeBuilderTestCase.class
})
public class StandardTestSuite {
}
diff --git a/test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java b/test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java
new file mode 100644
index 000000000..f8719edd6
--- /dev/null
+++ b/test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java
@@ -0,0 +1,202 @@
+/*
+ * 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.accessibility;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+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.StreamSource;
+
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.Difference;
+import org.custommonkey.xmlunit.DifferenceConstants;
+import org.custommonkey.xmlunit.DifferenceListener;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.fop.apps.FOPException;
+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;
+import org.apache.fop.fo.LoadingException;
+import org.apache.fop.fotreetest.DummyFOEventHandler;
+
+public class FO2StructureTreeConverterTestCase {
+
+ private static class IgnoringPtrDifferenceListener implements DifferenceListener {
+
+ public int differenceFound(Difference difference) {
+ switch (difference.getId()) {
+ case DifferenceConstants.ELEMENT_NUM_ATTRIBUTES_ID:
+ return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
+ case DifferenceConstants.ATTR_NAME_NOT_FOUND_ID:
+ String additionalAttribute = difference.getTestNodeDetail().getValue();
+ if (additionalAttribute.equals("ptr")) {
+ return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
+ } else {
+ return RETURN_ACCEPT_DIFFERENCE;
+ }
+ default:
+ return RETURN_ACCEPT_DIFFERENCE;
+ }
+ }
+
+ public void skippedComparison(Node control, Node test) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ }
+
+ private static final String STRUCTURE_TREE_SEQUENCE_NAME = "structure-tree-sequence";
+
+ @Test
+ public void testConverter() throws Exception {
+ DOMResult expectedStructureTree = loadExpectedStructureTree();
+ DOMResult actualStructureTree = buildActualStructureTree();
+ final Diff diff = createDiff(expectedStructureTree, actualStructureTree);
+ assertTrue(diff.toString(), diff.similar());
+ }
+
+ private static DOMResult loadExpectedStructureTree() {
+ DOMResult expectedStructureTree = new DOMResult();
+ runXSLT(getXsltInputStream(), getFoInputStream(), expectedStructureTree);
+ return expectedStructureTree;
+ }
+
+ private static InputStream getXsltInputStream() {
+ return FO2StructureTreeConverterTestCase.class.getResourceAsStream("foToIfStructureTree.xsl");
+ }
+
+ private static InputStream getFoInputStream() {
+ return FO2StructureTreeConverterTestCase.class.getResourceAsStream(
+ "/org/apache/fop/fo/complete_document.fo");
+ }
+
+ private static void runXSLT(InputStream xslt, InputStream doc, Result result) {
+ Source fo = new StreamSource(doc);
+ try {
+ Transformer transformer = TransformerFactory.newInstance()
+ .newTransformer(new StreamSource(xslt));
+ transformer.transform(fo, result);
+ } catch (TransformerConfigurationException e) {
+ throw new RuntimeException(e);
+ } catch (TransformerException e) {
+ throw new RuntimeException(e);
+ } finally {
+ closeStream(xslt);
+ closeStream(doc);
+ }
+ }
+
+ private static void closeStream(InputStream stream) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static DOMResult buildActualStructureTree() throws Exception {
+ DOMResult actualStructureTree = new DOMResult();
+ createStructureTreeFromDocument(getFoInputStream(), actualStructureTree);
+ return actualStructureTree;
+ }
+
+ private static void createStructureTreeFromDocument(InputStream foInputStream,
+ DOMResult domResult) throws Exception {
+ TransformerHandler tHandler = createTransformerHandler(domResult);
+ startStructureTreeSequence(tHandler);
+ StructureTreeEventHandler structureTreeEventHandler
+ = StructureTree2SAXEventAdapter.newInstance(tHandler);
+ FODocumentParser documentParser = createDocumentParser(structureTreeEventHandler);
+ FOUserAgent userAgent = createFOUserAgent(documentParser);
+ parseDocument(foInputStream, documentParser, userAgent);
+ endStructureTreeSequence(tHandler);
+ }
+
+ private static TransformerHandler createTransformerHandler(DOMResult domResult)
+ throws TransformerConfigurationException, TransformerFactoryConfigurationError {
+ SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
+ TransformerHandler transformerHandler = factory.newTransformerHandler();
+ transformerHandler.setResult(domResult);
+ return transformerHandler;
+ }
+
+ private static void startStructureTreeSequence(TransformerHandler tHandler) throws SAXException {
+ tHandler.startDocument();
+ tHandler.startElement("", STRUCTURE_TREE_SEQUENCE_NAME, STRUCTURE_TREE_SEQUENCE_NAME,
+ new AttributesImpl());
+ }
+
+ private static FODocumentParser createDocumentParser(
+ final StructureTreeEventHandler structureTreeEventHandler) {
+ return FODocumentParser.newInstance(new FOEventHandlerFactory() {
+ public FOEventHandler newFOEventHandler(FOUserAgent foUserAgent) {
+ return new FO2StructureTreeConverter(structureTreeEventHandler,
+ new DummyFOEventHandler(foUserAgent));
+ }
+ });
+ }
+
+ private static FOUserAgent createFOUserAgent(FODocumentParser documentParser) {
+ FOUserAgent userAgent = documentParser.createFOUserAgent();
+ userAgent.setAccessibility(true);
+ return userAgent;
+ }
+
+ private static void parseDocument(InputStream foInputStream, FODocumentParser documentParser,
+ FOUserAgent userAgent) throws FOPException, LoadingException {
+ try {
+ documentParser.parse(foInputStream, userAgent);
+ } finally {
+ closeStream(foInputStream);
+ }
+ }
+
+ private static void endStructureTreeSequence(TransformerHandler tHandler) throws SAXException {
+ tHandler.endElement("", STRUCTURE_TREE_SEQUENCE_NAME, STRUCTURE_TREE_SEQUENCE_NAME);
+ tHandler.endDocument();
+ }
+
+ private static Diff createDiff(DOMResult expected, DOMResult actual) {
+ Diff diff = new Diff(getDocument(expected), getDocument(actual));
+ diff.overrideDifferenceListener(new IgnoringPtrDifferenceListener());
+ return diff;
+ }
+
+ private static Document getDocument(DOMResult result) {
+ return (Document) result.getNode();
+ }
+}
diff --git a/test/java/org/apache/fop/accessibility/fo2StructureTree.xsl b/test/java/org/apache/fop/accessibility/fo2StructureTree.xsl
new file mode 100644
index 000000000..5c9c5615c
--- /dev/null
+++ b/test/java/org/apache/fop/accessibility/fo2StructureTree.xsl
@@ -0,0 +1,116 @@
+<?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"
+ xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
+ xmlns:foi="http://xmlgraphics.apache.org/fop/internal">
+
+ <xsl:output method="xml" indent="no"/>
+
+ <xsl:template name="copy">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+ </xsl:template>
+
+
+ <!-- Ignore fo:root -->
+ <xsl:template match="fo:root">
+ <structure-tree-sequence>
+ <xsl:apply-templates/>
+ </structure-tree-sequence>
+ </xsl:template>
+
+ <!-- fo:page-sequence maps to structure-tree -->
+ <xsl:template match="fo:page-sequence">
+ <structure-tree xmlns="http://xmlgraphics.apache.org/fop/intermediate">
+ <xsl:apply-templates/>
+ </structure-tree>
+ </xsl:template>
+
+
+ <!-- Declarations and Pagination and Layout Formatting Objects -->
+ <xsl:template match="fo:static-content|fo:flow">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <!-- Block-level Formatting Objects -->
+ <xsl:template match="fo:block|fo:block-container">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <!-- Inline-level Formatting Objects -->
+ <xsl:template match="fo:character|fo:inline|fo:inline-container">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <xsl:template match="fo:external-graphic|fo:instream-foreign-object">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <xsl:template match="fo:page-number|fo:page-number-citation|fo:page-number-citation-last">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <!-- Formatting Objects for Tables -->
+ <xsl:template match="fo:table-and-caption|fo:table-caption|fo:table">
+ <xsl:call-template name="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>
+
+ <!-- Formatting Objects for Lists -->
+ <xsl:template match="fo:list-block|fo:list-item|fo:list-item-label|fo:list-item-body">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <!-- Dynamic Effects: Link and Multi Formatting Objects -->
+ <xsl:template match="fo:basic-link">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <!-- Out-of-Line Formatting Objects -->
+ <xsl:template match="fo:float|fo:footnote|fo:footnote-body">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+ <!-- Other Formatting Objects -->
+ <xsl:template match="fo:wrapper|fo:marker">
+ <xsl:call-template name="copy"/>
+ </xsl:template>
+
+
+ <!-- Discard descendants of fo:leader -->
+ <xsl:template match="fo:leader"/>
+
+
+ <!-- Keep fox:alt-text and role attributes, discard everything else -->
+ <xsl:template match="@fox:alt-text|@role">
+ <xsl:copy-of select="."/>
+ </xsl:template>
+
+ <xsl:template match="@*"/>
+
+
+ <!-- Discard text -->
+ <xsl:template match="text()"/>
+
+</xsl:stylesheet>
diff --git a/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.java b/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.java
index faa88e38e..313379e02 100644
--- a/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.java
+++ b/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.java
@@ -71,6 +71,7 @@ import org.apache.fop.fo.flow.table.TableHeader;
import org.apache.fop.fo.flow.table.TableRow;
import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.PageSequence;
+import org.apache.fop.fo.pagination.Root;
import org.apache.fop.fo.pagination.StaticContent;
/**
@@ -97,12 +98,22 @@ public class DelegatingFOEventHandlerTestCase {
@Override
public void startDocument() throws SAXException {
- actualEvents.add("start root");
+ actualEvents.add("start document");
}
@Override
public void endDocument() throws SAXException {
- actualEvents.add("end root");
+ actualEvents.add("end document");
+ }
+
+ @Override
+ public void startRoot(Root root) {
+ startElement(root);
+ }
+
+ @Override
+ public void endRoot(Root root) {
+ endElement(root);
}
@Override
@@ -417,9 +428,7 @@ public class DelegatingFOEventHandlerTestCase {
}
private void loadDocument() {
- Class<?> clazz = getClass();
- String documentName = clazz.getSimpleName() + ".fo";
- document = clazz.getResourceAsStream(documentName);
+ document = getClass().getResourceAsStream("complete_document.fo");
}
private void loadExpectedEvents() throws IOException {
diff --git a/test/java/org/apache/fop/fo/FODocumentParser.java b/test/java/org/apache/fop/fo/FODocumentParser.java
index 4706866a4..a7574e49d 100644
--- a/test/java/org/apache/fop/fo/FODocumentParser.java
+++ b/test/java/org/apache/fop/fo/FODocumentParser.java
@@ -108,13 +108,29 @@ public final class FODocumentParser {
* @throws LoadingException if an error occurs when parsing the document
*/
public void parse(InputStream document) throws FOPException, LoadingException {
- FOUserAgent foUserAgent = createFOUserAgent();
+ parse(document, createFOUserAgent());
+ }
+
+ /**
+ * Runs FOP on the given document with the supplied {@link FOUserAgent}.
+ *
+ * @param document XSL-FO document to parse
+ * @param foUserAgent The user agent
+ * @throws FOPException if an error occurs when initializing FOP
+ * @throws LoadingException if an error occurs when parsing the document
+ */
+ public void parse(InputStream document, FOUserAgent foUserAgent)
+ throws FOPException, LoadingException {
fop = FOP_FACTORY.newFop(foUserAgent);
createTransformer();
runTransformer(document);
}
- private FOUserAgent createFOUserAgent() {
+ /**
+ * Creates a new {@link FOUserAgent}.
+ * @return It
+ */
+ public FOUserAgent createFOUserAgent() {
FOUserAgent userAgent = FOP_FACTORY.newFOUserAgent();
FOEventHandler foEventHandler = foEventHandlerFactory.newFOEventHandler(userAgent);
userAgent.setFOEventHandlerOverride(foEventHandler);
diff --git a/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.fo b/test/java/org/apache/fop/fo/complete_document.fo
index 74afd6c16..5a34e9e9a 100644
--- a/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.fo
+++ b/test/java/org/apache/fop/fo/complete_document.fo
@@ -147,7 +147,8 @@
</fo:list-item>
</fo:list-block>
<fo:block id="70" text-align="center"><fo:instream-foreign-object id="71"
- inline-progression-dimension.maximum="50%" content-width="scale-to-fit">
+ inline-progression-dimension.maximum="50%" content-width="scale-to-fit"
+ fox:alt-text="An inline SVG">
<svg xmlns="http://www.w3.org/2000/svg" width="319" height="286.6">
<g style="fill-opacity:0.7; stroke:black; stroke-width:3"
transform="translate(0, 286.6) scale(1, -1) translate(100, 100)">
diff --git a/test/java/org/apache/fop/fo/extract-events.xsl b/test/java/org/apache/fop/fo/extract-events.xsl
index 8edc0ee49..6cf42c984 100644
--- a/test/java/org/apache/fop/fo/extract-events.xsl
+++ b/test/java/org/apache/fop/fo/extract-events.xsl
@@ -6,16 +6,22 @@
<xsl:output indent="yes" omit-xml-declaration="yes"/>
- <xsl:template match="fo:root">
+ <xsl:template match="/">
<event>
- <xsl:text>start root</xsl:text>
+ <xsl:text>start document</xsl:text>
</event>
- <xsl:apply-templates select="fo:page-sequence"/>
+ <xsl:apply-templates/>
<event>
- <xsl:text>end root</xsl:text>
+ <xsl:text>end document</xsl:text>
</event>
</xsl:template>
+ <xsl:template match="fo:root">
+ <event>start root</event>
+ <xsl:apply-templates select="fo:page-sequence"/>
+ <event>end root</event>
+ </xsl:template>
+
<xsl:template match="fo:*">
<xsl:call-template name="process.node">
<xsl:with-param name="id">
diff --git a/test/java/org/apache/fop/fo/properties/CommonAccessibilityHolderTestCase.java b/test/java/org/apache/fop/fo/properties/CommonAccessibilityHolderTestCase.java
index 45f6a61ab..352a39713 100644
--- a/test/java/org/apache/fop/fo/properties/CommonAccessibilityHolderTestCase.java
+++ b/test/java/org/apache/fop/fo/properties/CommonAccessibilityHolderTestCase.java
@@ -34,6 +34,7 @@ import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FONodeMocks;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.expr.PropertyException;
+import org.apache.fop.fo.flow.table.UnimplementedWarningNeutralizer;
/**
* This tests that all the FONodes that implement CommonAccessibilityHolder correctly configure
@@ -51,7 +52,7 @@ public class CommonAccessibilityHolderTestCase {
static {
/* This triggers 'unimplemented feature' FO validation events so that the event system is
* not triggered when testing, avoiding extra convoluted dependency stubbing. */
-// UnimplementedWarningNeutralizer.neutralizeUnimplementedWarning();
+ UnimplementedWarningNeutralizer.neutralizeUnimplementedWarning();
IMPLEMENTATIONS.add(org.apache.fop.fo.flow.BasicLink.class);
IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Block.class);
diff --git a/test/java/org/apache/fop/intermediate/IFParserTestCase.java b/test/java/org/apache/fop/intermediate/IFParserTestCase.java
index 52d322e3e..6ac20c556 100644
--- a/test/java/org/apache/fop/intermediate/IFParserTestCase.java
+++ b/test/java/org/apache/fop/intermediate/IFParserTestCase.java
@@ -48,6 +48,9 @@ import org.apache.fop.render.intermediate.IFSerializer;
@RunWith(Parameterized.class)
public class IFParserTestCase extends AbstractIFTestCase {
+ /** 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
*
@@ -56,7 +59,19 @@ public class IFParserTestCase extends AbstractIFTestCase {
*/
@Parameters
public static Collection<File[]> getParameters() throws IOException {
- return LayoutEngineTestUtils.getLayoutTestFiles();
+ 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]));
+ }
}
/**
diff --git a/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java b/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java
new file mode 100644
index 000000000..d7db7db7f
--- /dev/null
+++ b/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.intermediate;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.InOrder;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.fop.fo.FOElementMapping;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.fo.extensions.InternalElementMapping;
+import org.apache.fop.util.XMLUtil;
+
+public class IFStructureTreeBuilderTestCase {
+
+ private IFStructureTreeBuilder sut;
+
+ @Before
+ public void setUp() {
+ sut = new IFStructureTreeBuilder();
+ }
+
+ @Test
+ public void startAndEndPageSequence() throws SAXException {
+ final ContentHandler handler = mock(ContentHandler.class);
+
+ try {
+ sut.replayEventsForPageSequence(handler, 0);
+ fail("No page sequences created");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ sut.startPageSequence(null);
+ sut.endPageSequence();
+
+ sut.replayEventsForPageSequence(handler, 0);
+
+ InOrder inOrder = inOrder(handler);
+
+ inOrder.verify(handler).startPrefixMapping(
+ InternalElementMapping.STANDARD_PREFIX, InternalElementMapping.URI);
+ inOrder.verify(handler).startPrefixMapping(
+ ExtensionElementMapping.STANDARD_PREFIX, ExtensionElementMapping.URI);
+ inOrder.verify(handler).startElement(eq(IFConstants.NAMESPACE),
+ eq(IFConstants.EL_STRUCTURE_TREE),
+ eq(IFConstants.EL_STRUCTURE_TREE),
+ any(Attributes.class));
+ inOrder.verify(handler).endElement(eq(IFConstants.NAMESPACE),
+ eq(IFConstants.EL_STRUCTURE_TREE),
+ eq(IFConstants.EL_STRUCTURE_TREE));
+ inOrder.verify(handler).endPrefixMapping(ExtensionElementMapping.STANDARD_PREFIX);
+ inOrder.verify(handler).endPrefixMapping(InternalElementMapping.STANDARD_PREFIX);
+ }
+
+ @Test
+ public void startNode() throws Exception {
+ final String[] attributes = {"ptr", "1"};
+ final String nodeName = "block";
+ final ContentHandler handler = mock(ContentHandler.class);
+
+ sut.startPageSequence(null);
+ sut.startNode(nodeName, createSimpleAttributes(attributes));
+ sut.endPageSequence();
+
+ sut.replayEventsForPageSequence(handler, 0);
+
+ verify(handler).startElement(eq(FOElementMapping.URI), eq(nodeName),
+ eq(FOElementMapping.STANDARD_PREFIX + ":" + nodeName),
+ AttributesMatcher.match(createSimpleAttributes(attributes)));
+ }
+
+ @Test
+ public void endNode() throws Exception {
+ final String nodeName = "block";
+ final ContentHandler handler = mock(ContentHandler.class);
+
+ sut.startPageSequence(null);
+ sut.endNode(nodeName);
+ sut.endPageSequence();
+
+ sut.replayEventsForPageSequence(handler, 0);
+
+ verify(handler).endElement(eq(FOElementMapping.URI), eq(nodeName),
+ eq(FOElementMapping.STANDARD_PREFIX + ":" + nodeName));
+ }
+
+ private static Attributes createSimpleAttributes(String... attributes) {
+ assert (attributes.length % 2 == 0);
+ final AttributesImpl atts = new AttributesImpl();
+ for (int i = 0; i < attributes.length; i += 2) {
+ String key = attributes[i];
+ String value = attributes[i + 1];
+ atts.addAttribute("", key, key, XMLUtil.CDATA, value);
+ }
+ return atts;
+ }
+
+ private static final class AttributesMatcher extends ArgumentMatcher<Attributes> {
+
+ private final Attributes expected;
+
+ private AttributesMatcher(Attributes expected) {
+ this.expected = expected;
+ }
+
+ public static Attributes match(Attributes expected) {
+ return argThat(new AttributesMatcher(expected));
+ }
+
+ public boolean matches(Object attributes) {
+ return attributesEqual(expected, (Attributes) attributes);
+ }
+
+ private static boolean attributesEqual(Attributes attributes1, Attributes attributes2) {
+ if (attributes1.getLength() != attributes2.getLength()) {
+ return false;
+ }
+ for (int i = 0; i < attributes1.getLength(); i++) {
+ if (attributes1.getLocalName(i) != attributes2.getLocalName(i)) {
+ return false;
+ }
+ if (attributes1.getQName(i) != attributes2.getQName(i)) {
+ return false;
+ }
+ if (attributes1.getType(i) != attributes2.getType(i)) {
+ return false;
+ }
+ if (attributes1.getURI(i) != attributes2.getURI(i)) {
+ return false;
+ }
+ if (attributes1.getValue(i) != attributes2.getValue(i)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+}
diff --git a/test/java/org/apache/fop/render/intermediate/SAXEventRecorderTestCase.java b/test/java/org/apache/fop/render/intermediate/SAXEventRecorderTestCase.java
new file mode 100644
index 000000000..c5aad66d0
--- /dev/null
+++ b/test/java/org/apache/fop/render/intermediate/SAXEventRecorderTestCase.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.render.intermediate;
+
+
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.fop.render.intermediate.IFStructureTreeBuilder.SAXEventRecorder;
+import org.apache.fop.util.XMLUtil;
+
+/**
+ * Tests {@link SAXEventRecorder}.
+ */
+public class SAXEventRecorderTestCase {
+
+ private static final String URI = "http://www.example.com/";
+
+ private SAXEventRecorder sut;
+
+ @Before
+ public void setUp() {
+ sut = new SAXEventRecorder();
+ }
+
+ @Test
+ public void testStartEvent() throws SAXException {
+ final String localName = "element";
+ final String qName = "prefix:" + localName;
+ final Attributes attributes = new AttributesImpl();
+
+ sut.startElement(URI, localName, qName, attributes);
+ ContentHandler handler = mock(ContentHandler.class);
+ sut.replay(handler);
+ verify(handler).startElement(URI, localName, qName, attributes);
+ }
+
+ @Test
+ public void testEndEvent() throws SAXException {
+ final String localName = "element";
+ final String qName = "prefix:" + localName;
+ sut.endElement(URI, localName, qName);
+ ContentHandler handler = mock(ContentHandler.class);
+ sut.replay(handler);
+ verify(handler).endElement(URI, localName, qName);
+ }
+
+ @Test
+ public void testStartPrefixMapping() throws SAXException {
+ final String prefix = "prefix";
+
+ sut.startPrefixMapping(URI, prefix);
+ ContentHandler handler = mock(ContentHandler.class);
+ sut.replay(handler);
+ verify(handler).startPrefixMapping(URI, prefix);
+ }
+
+ @Test
+ public void testEndPrefixMapping() throws SAXException {
+ final String prefix = "prefix";
+
+ sut.endPrefixMapping(prefix);
+ ContentHandler handler = mock(ContentHandler.class);
+ sut.replay(handler);
+ verify(handler).endPrefixMapping(prefix);
+ }
+
+ @Test
+ public void completeTest() throws SAXException {
+ final String localName1 = "element";
+ final String qName1 = "prefix:" + localName1;
+ final Attributes attributes1 = createAttributes(URI, localName1, qName1, "value-1");
+ final String localName2 = "element2";
+ final String qName2 = "prefix:" + localName2;
+ final Attributes attributes2 = createAttributes(URI, localName2, qName2, "value-2");
+ final ContentHandler handler = mock(ContentHandler.class);
+ final String extensionUrl = "http://www.example.com/extension";
+ final String extensionPrefix = "ext";
+
+ sut.startPrefixMapping(extensionPrefix, extensionUrl);
+ sut.startElement(URI, localName1, qName1, attributes1);
+ sut.startElement(URI, localName2, qName2, attributes2);
+ sut.endElement(URI, localName2, qName2);
+ sut.endElement(URI, localName1, qName1);
+ sut.endPrefixMapping(extensionPrefix);
+
+ sut.replay(handler);
+
+ InOrder inOrder = inOrder(handler);
+ inOrder.verify(handler).startPrefixMapping(extensionPrefix, extensionUrl);
+ inOrder.verify(handler).startElement(URI, localName1, qName1, attributes1);
+ inOrder.verify(handler).startElement(URI, localName2, qName2, attributes2);
+ inOrder.verify(handler).endElement(URI, localName2, qName2);
+ inOrder.verify(handler).endElement(URI, localName1, qName1);
+ inOrder.verify(handler).endPrefixMapping(extensionPrefix);
+ }
+
+ private static Attributes createAttributes(String uri, String localName,
+ String qName, String value) {
+ final AttributesImpl atts = new AttributesImpl();
+ atts.addAttribute(uri, localName, qName, XMLUtil.CDATA, value);
+ return atts;
+ }
+
+}
diff --git a/test/java/org/apache/fop/util/XMLUtilTestCase.java b/test/java/org/apache/fop/util/LanguageTagsTestCase.java
index 4c1b999e1..f7383c720 100644
--- a/test/java/org/apache/fop/util/XMLUtilTestCase.java
+++ b/test/java/org/apache/fop/util/LanguageTagsTestCase.java
@@ -20,31 +20,39 @@
package org.apache.fop.util;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import java.util.Locale;
import org.junit.Test;
/**
- * Tests {@link XMLUtil}.
+ * Tests {@link LanguageTags}.
*/
-public class XMLUtilTestCase {
+public class LanguageTagsTestCase {
+
+ @Test(expected = NullPointerException.class)
+ public void toLanguageTagRejectsNull() {
+ LanguageTags.toLanguageTag(null);
+ }
@Test
- public void testLocaleToRFC3066() throws Exception {
- assertNull(XMLUtil.toRFC3066(null));
- assertEquals("en", XMLUtil.toRFC3066(new Locale("en")));
- assertEquals("en-US", XMLUtil.toRFC3066(new Locale("en", "US")));
- assertEquals("en-US", XMLUtil.toRFC3066(new Locale("EN", "us")));
+ public void testToLanguageTag() throws Exception {
+ assertEquals("", LanguageTags.toLanguageTag(new Locale("")));
+ assertEquals("en", LanguageTags.toLanguageTag(new Locale("en")));
+ assertEquals("en-US", LanguageTags.toLanguageTag(new Locale("en", "US")));
+ assertEquals("en-US", LanguageTags.toLanguageTag(new Locale("EN", "us")));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void toLocaleRejectsNull() {
+ LanguageTags.toLocale(null);
}
@Test
public void testRFC3066ToLocale() throws Exception {
- assertNull(XMLUtil.convertRFC3066ToLocale(null));
- assertNull(XMLUtil.convertRFC3066ToLocale(""));
- assertEquals(new Locale("en"), XMLUtil.convertRFC3066ToLocale("en"));
- assertEquals(new Locale("en", "US"), XMLUtil.convertRFC3066ToLocale("en-US"));
- assertEquals(new Locale("en", "US"), XMLUtil.convertRFC3066ToLocale("EN-us"));
+ assertEquals(new Locale(""), LanguageTags.toLocale(""));
+ assertEquals(new Locale("en"), LanguageTags.toLocale("en"));
+ assertEquals(new Locale("en", "US"), LanguageTags.toLocale("en-US"));
+ assertEquals(new Locale("en", "US"), LanguageTags.toLocale("EN-us"));
}
}