Author: tilman
Date: Tue Apr 22 16:54:21 2014
New Revision: 1589204

URL: http://svn.apache.org/r1589204
Log:
PDFBOX-2036: Add test with LZW fail sequence

Added:
    pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/filter/
    
pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/filter/PDFBOX-1777.bin
   (with props)
Modified:
    
pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java

Modified: 
pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java?rev=1589204&r1=1589203&r2=1589204&view=diff
==============================================================================
--- 
pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java
 (original)
+++ 
pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java
 Tue Apr 22 16:54:21 2014
@@ -19,12 +19,14 @@ package org.apache.pdfbox.filter;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Random;
 
 import junit.framework.TestCase;
 
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
 
 
 /**
@@ -115,4 +117,34 @@ public class TestFilters extends TestCas
         }
     }
 
+
+    /**
+     * This will test the LZW filter with the sequence that failed in 
PDFBOX-1777.
+     * To check that the test itself is legit, revert LZWFilter.java to rev 
1571801,
+     * which should fail this test.
+     * 
+     * @throws IOException 
+     */
+    public void testPDFBOX1777() throws IOException
+    {
+        LZWFilter lzwFilter = new LZWFilter();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        InputStream is = 
this.getClass().getResourceAsStream("PDFBOX-1777.bin");
+        int by;
+        while ((by = is.read()) != -1)
+        {
+            baos.write(by);
+        }
+        is.close();
+        ByteArrayOutputStream encoded = new ByteArrayOutputStream();
+        lzwFilter.encode(new ByteArrayInputStream(baos.toByteArray()),
+                encoded, new COSDictionary(), 0);
+        ByteArrayOutputStream decoded = new ByteArrayOutputStream();
+        lzwFilter.decode(new ByteArrayInputStream(encoded.toByteArray()),
+                decoded, new COSDictionary(), 0);
+        assertTrue(
+                "PDFBOX-1777 data that is encoded and then decoded through "
+                + lzwFilter.getClass() + " does not match the original data",
+                Arrays.equals(baos.toByteArray(), decoded.toByteArray()));
+    }
 }

Added: 
pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/filter/PDFBOX-1777.bin
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/filter/PDFBOX-1777.bin?rev=1589204&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
pdfbox/branches/1.8/pdfbox/src/test/resources/org/apache/pdfbox/filter/PDFBOX-1777.bin
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream


Reply via email to