aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/java/org/apache/fop/UtilityCodeTestSuite.java4
-rw-r--r--test/java/org/apache/fop/util/DataURIResolverTestCase.java116
2 files changed, 120 insertions, 0 deletions
diff --git a/test/java/org/apache/fop/UtilityCodeTestSuite.java b/test/java/org/apache/fop/UtilityCodeTestSuite.java
index f84390518..679e16ce7 100644
--- a/test/java/org/apache/fop/UtilityCodeTestSuite.java
+++ b/test/java/org/apache/fop/UtilityCodeTestSuite.java
@@ -21,6 +21,8 @@ package org.apache.fop;
import org.apache.fop.traits.BorderPropsTestCase;
import org.apache.fop.traits.TraitColorTestCase;
+import org.apache.fop.util.DataURIResolverTestCase;
+import org.apache.fop.util.ElementListUtilsTestCase;
import org.apache.fop.util.PDFNumberTestCase;
import org.apache.fop.util.UnitConvTestCase;
@@ -44,6 +46,8 @@ public class UtilityCodeTestSuite {
suite.addTest(new TestSuite(UnitConvTestCase.class));
suite.addTest(new TestSuite(TraitColorTestCase.class));
suite.addTest(new TestSuite(BorderPropsTestCase.class));
+ suite.addTest(new TestSuite(ElementListUtilsTestCase.class));
+ suite.addTest(new TestSuite(DataURIResolverTestCase.class));
//$JUnit-END$
return suite;
}
diff --git a/test/java/org/apache/fop/util/DataURIResolverTestCase.java b/test/java/org/apache/fop/util/DataURIResolverTestCase.java
new file mode 100644
index 000000000..133d4fcd1
--- /dev/null
+++ b/test/java/org/apache/fop/util/DataURIResolverTestCase.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.util;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.io.IOUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for the RFC 2397 data URL/URI resolver.
+ */
+public class DataURIResolverTestCase extends TestCase {
+
+ private static final byte[] TESTDATA = new byte[] {0, 1, 2, 3, 4, 5};
+
+ /**
+ * Tests DataURLUtil.
+ * @throws Exception if an error occurs
+ */
+ public void testRFC2397Generator() throws Exception {
+ String url = DataURLUtil.createDataURL(new ByteArrayInputStream(TESTDATA), null);
+ assertEquals("Generated data URL is wrong", "data:;base64,AAECAwQF", url);
+
+ url = DataURLUtil.createDataURL(new ByteArrayInputStream(TESTDATA), "application/pdf");
+ assertEquals("Generated data URL is wrong", "data:application/pdf;base64,AAECAwQF", url);
+ }
+
+ /**
+ * Test the URIResolver contract if the protocol doesn't match. Resolver must return null
+ * in this case.
+ * @throws Exception if an error occurs
+ */
+ public void testNonMatchingContract() throws Exception {
+ URIResolver resolver = new DataURIResolver();
+ Source src;
+
+ src = resolver.resolve("http://xmlgraphics.apache.org/fop/index.html", null);
+ assertNull(src);
+
+ src = resolver.resolve("index.html", "http://xmlgraphics.apache.org/fop/");
+ assertNull(src);
+ }
+
+ private static boolean byteCmp(byte[] src, int srcOffset, byte[] cmp) {
+ for (int i = 0, c = cmp.length; i < c; i++) {
+ if (src[srcOffset + i] != cmp[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Test the DataURIResolver with correct values.
+ * @throws Exception if an error occurs
+ */
+ public void testDataURLHandling() throws Exception {
+ URIResolver resolver = new DataURIResolver();
+ Source src;
+
+ src = resolver.resolve("data:;base64,AAECAwQF", null);
+ assertNotNull(src);
+ StreamSource streamSource = (StreamSource)src;
+ byte[] data = IOUtils.toByteArray(streamSource.getInputStream());
+ assertTrue("Decoded data doesn't match the test data", byteCmp(TESTDATA, 0, data));
+
+ src = resolver.resolve(
+ "data:application/octet-stream;interpreter=fop;base64,AAECAwQF", null);
+ assertNotNull(src);
+ streamSource = (StreamSource)src;
+ assertNotNull(streamSource.getInputStream());
+ assertNull(streamSource.getReader());
+ data = IOUtils.toByteArray(streamSource.getInputStream());
+ assertTrue("Decoded data doesn't match the test data", byteCmp(TESTDATA, 0, data));
+
+ src = resolver.resolve("data:,FOP", null);
+ assertNotNull(src);
+ streamSource = (StreamSource)src;
+ assertNull(streamSource.getInputStream());
+ assertNotNull(streamSource.getReader());
+ String text = IOUtils.toString(streamSource.getReader());
+ assertEquals("FOP", text);
+
+ /* TODO Un-escaping of special URL chars like %20 hasn't been implemented, yet.
+ src = resolver.resolve("data:,A%20brief%20note", null);
+ assertNotNull(src);
+ streamSource = (StreamSource)src;
+ text = IOUtils.toString(streamSource.getReader());
+ assertEquals("A brief note", text);
+ */
+ }
+
+}