]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Forgot to include test files in commit 1400890
authorVincent Hennebert <vhennebert@apache.org>
Fri, 2 Nov 2012 20:50:04 +0000 (20:50 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Fri, 2 Nov 2012 20:50:04 +0000 (20:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1405160 13f79535-47bb-0310-9956-ffa450edef68

test/java/org/apache/fop/accessibility/pdf/MissingLanguageWarningTestCase.java [new file with mode: 0644]
test/java/org/apache/fop/accessibility/pdf/missing-language.fo [new file with mode: 0644]

diff --git a/test/java/org/apache/fop/accessibility/pdf/MissingLanguageWarningTestCase.java b/test/java/org/apache/fop/accessibility/pdf/MissingLanguageWarningTestCase.java
new file mode 100644 (file)
index 0000000..c5d1611
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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.pdf;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.LinkedList;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.io.output.NullOutputStream;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.events.Event;
+import org.apache.fop.events.EventListener;
+import org.apache.fop.render.pdf.PDFEventProducer;
+
+public class MissingLanguageWarningTestCase {
+
+    private Fop fop;
+
+    private MissingLanguageEventChecker eventChecker;
+
+    private static class MissingLanguageEventChecker implements EventListener {
+
+        private final String unknownLanguageEventID = PDFEventProducer.class.getName() + ".unknownLanguage";
+
+        private final LinkedList<String> expectedLocations = new LinkedList<String>(
+                Arrays.asList("30:37", "34:40"));
+
+        public void processEvent(Event event) {
+            if (event.getEventID().equals(unknownLanguageEventID)) {
+                assertFalse("Too many unknownLanguage events", expectedLocations.isEmpty());
+                assertEquals(expectedLocations.removeFirst(), event.getParam("location"));
+            }
+        }
+
+        void end() {
+            assertTrue("Expected more unknownLanguage events", expectedLocations.isEmpty());
+        }
+
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
+        FOUserAgent userAgent = fopFactory.newFOUserAgent();
+        userAgent.setAccessibility(true);
+        eventChecker = new MissingLanguageEventChecker();
+        userAgent.getEventBroadcaster().addEventListener(eventChecker);
+        fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, new NullOutputStream());
+    }
+
+    @Test
+    public void testMissingLanguage() throws Exception {
+        Source src = new StreamSource(getClass().getResourceAsStream("missing-language.fo"));
+        SAXResult res = new SAXResult(fop.getDefaultHandler());
+        Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        transformer.transform(src, res);
+        eventChecker.end();
+    }
+
+}
diff --git a/test/java/org/apache/fop/accessibility/pdf/missing-language.fo b/test/java/org/apache/fop/accessibility/pdf/missing-language.fo
new file mode 100644 (file)
index 0000000..a774d3c
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
+  xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="page"
+      page-height="320pt" page-width="420pt" margin="10pt">
+      <fo:region-body/>
+    </fo:simple-page-master>
+  </fo:layout-master-set>
+
+  <fo:page-sequence master-reference="page">
+    <fo:flow flow-name="xsl-region-body" text-align="justify" space-before="10pt">
+
+      <fo:block language="en" country="GB" space-before="inherit">This block of text is written in 
+        British English. The following block is in French and translates as: “This block contains 
+        French text and is tagged as such.”</fo:block>
+
+      <fo:block language="fr" country="FR" space-before="inherit">Ce block contient du texte en 
+        français et est marqué comme tel.</fo:block>
+
+      <fo:block language="en" country="GB" space-before="inherit">The following block has no 
+        language information, but since it contains no text no warning should be issued.</fo:block>
+
+      <fo:block border="0.2pt solid black" space-before="inherit">  </fo:block>
+
+      <fo:block language="en" country="GB" space-before="inherit">The following block has no 
+        language information and contains an image with an alt-text, for which a warning should be 
+        issued.</fo:block>
+
+      <fo:block text-align="center"><fo:external-graphic 
+          src="test/resources/images/fop-logo-color-24bit.png"
+          fox:alt-text="FOP logo"/></fo:block>
+
+      <fo:block space-before="inherit">This block contains no language information. However, only 
+        one warning should be issued for all of its lines.</fo:block>
+
+    </fo:flow>
+  </fo:page-sequence>
+
+</fo:root>