diff options
author | Mehdi Houshmand <mehdi@apache.org> | 2012-07-04 07:04:03 +0000 |
---|---|---|
committer | Mehdi Houshmand <mehdi@apache.org> | 2012-07-04 07:04:03 +0000 |
commit | 8f37765b5c9b6dbe80d860207802aa4f7f8b1a94 (patch) | |
tree | bc80b6209cc295fb5e2b22b7e52f3813ad04acb7 /test/java/org/apache/fop/afp/AFPResourceUtilTestCase.java | |
parent | fdb801262c8abbf13b12d9df5900a5c4627dda12 (diff) | |
download | xmlgraphics-fop-8f37765b5c9b6dbe80d860207802aa4f7f8b1a94.tar.gz xmlgraphics-fop-8f37765b5c9b6dbe80d860207802aa4f7f8b1a94.zip |
Bugzilla#53502: MODCA end structured field now more conformant with the spec by allowing 0xFFFF match (match any). Submitted by Robert Meyer
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1357110 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop/afp/AFPResourceUtilTestCase.java')
-rw-r--r-- | test/java/org/apache/fop/afp/AFPResourceUtilTestCase.java | 117 |
1 files changed, 88 insertions, 29 deletions
diff --git a/test/java/org/apache/fop/afp/AFPResourceUtilTestCase.java b/test/java/org/apache/fop/afp/AFPResourceUtilTestCase.java index 6ab7f475d..a7cf57ebe 100644 --- a/test/java/org/apache/fop/afp/AFPResourceUtilTestCase.java +++ b/test/java/org/apache/fop/afp/AFPResourceUtilTestCase.java @@ -22,23 +22,34 @@ package org.apache.fop.afp; import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.Arrays; +import org.junit.Test; + import org.apache.commons.io.IOUtils; import org.apache.fop.afp.util.AFPResourceUtil; import org.junit.Test; +import static org.junit.Assert.assertTrue; + /** * Tests the {@link AFPResourceUtil} class. */ public class AFPResourceUtilTestCase { private static final String RESOURCE_FILENAME = "expected_resource.afp"; - private static final String NAMED_RESOURCE_FILENAME = "expected_named_resource.afp"; - private static final String PSEG = "XFEATHER"; + private static final String RESOURCE_ANY_NAME = "resource_any_name.afp"; + private static final String RESOURCE_NAME_MATCH = "resource_name_match.afp"; + private static final String RESOURCE_NAME_MISMATCH = "resource_name_mismatch.afp"; + private static final String RESOURCE_NO_END_NAME = "resource_no_end_name.afp"; + + private static final String PSEG_A = "XFEATHER"; + private static final String PSEG_B = "S1CODEQR"; /** * Tests copyResourceFile() @@ -46,57 +57,105 @@ public class AFPResourceUtilTestCase { */ @Test public void testCopyResourceFile() throws Exception { + compareResources(new ResourceCopier() { + public void copy(InputStream in, OutputStream out) throws IOException { + AFPResourceUtil.copyResourceFile(in, out); + } + }, RESOURCE_FILENAME, RESOURCE_FILENAME); + } - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + /** + * Tests copyNamedResource() + * @throws Exception - + */ + @Test + public void testCopyNamedResource() throws Exception { + compareResources(new ResourceCopier() { + public void copy(InputStream in, OutputStream out) throws IOException { + AFPResourceUtil.copyNamedResource(PSEG_A, in, out); + } + }, RESOURCE_FILENAME, NAMED_RESOURCE_FILENAME); + } - InputStream in = null; + private void compareResources(ResourceCopier copyResource, String resourceA, String resourceB) + throws IOException { + ByteArrayOutputStream baos = copyResource(resourceA, copyResource); + byte[] expectedBytes = resourceAsByteArray(resourceB); + assertTrue(Arrays.equals(expectedBytes, baos.toByteArray())); + } + private ByteArrayOutputStream copyResource(String resource, ResourceCopier resourceCopier) + throws IOException { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + InputStream in = null; try { - in = getClass().getResourceAsStream(RESOURCE_FILENAME); - AFPResourceUtil.copyResourceFile(in, baos); + in = getClass().getResourceAsStream(resource); + resourceCopier.copy(in, baos); } finally { in.close(); } + return baos; + } + private byte[] resourceAsByteArray(String resource) throws IOException { + InputStream in = null; byte[] expectedBytes = null; - try { - in = getClass().getResourceAsStream(RESOURCE_FILENAME); + in = getClass().getResourceAsStream(resource); expectedBytes = IOUtils.toByteArray(in); } finally { in.close(); } - - assertTrue(Arrays.equals(expectedBytes, baos.toByteArray())); - + return expectedBytes; } /** - * Tests copyNamedResource() + * Tests the validity of a closing structured field having an FF FF name which + * allows it to match any existing matching starting field * @throws Exception - */ @Test - public void testCopyNamedResource() throws Exception { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + public void testResourceAnyName() throws Exception { + testResource(RESOURCE_ANY_NAME, PSEG_B); + } - InputStream in = null; + /** + * Tests a matching end structured field name + * @throws Exception - + */ + @Test + public void testResourceNameMatch() throws Exception { + testResource(RESOURCE_NAME_MATCH, PSEG_B); + } - try { - in = getClass().getResourceAsStream(RESOURCE_FILENAME); - AFPResourceUtil.copyNamedResource(PSEG, in, baos); - } finally { - in.close(); - } + /** + * Tests to see whether a matching structured field pair with mismatching + * names fails. + * @throws Exception - + */ + @Test(expected=Exception.class) + public void testResourceNameMismatch() throws Exception { + testResource(RESOURCE_NAME_MISMATCH, PSEG_B); + } - byte[] expectedBytes = null; + /** + * Tests a matching structured end field with no name + * @throws Exception - + */ + @Test + public void testResourceNoEndName() throws Exception { + testResource(RESOURCE_NO_END_NAME, PSEG_B); + } - try { - in = getClass().getResourceAsStream(NAMED_RESOURCE_FILENAME); - expectedBytes = IOUtils.toByteArray(in); - } finally { - in.close(); - } + private void testResource(String resource, final String pseg) throws Exception { + copyResource(resource, new ResourceCopier() { + public void copy(InputStream in, OutputStream out) throws IOException { + AFPResourceUtil.copyNamedResource(pseg, in, out); + } + }); + } - assertTrue(Arrays.equals(expectedBytes, baos.toByteArray())); + private interface ResourceCopier { + public void copy(InputStream in, OutputStream out) throws IOException; } } |