You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/05/31 09:02:54 UTC

svn commit: r1860440 - /pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java

Author: tilman
Date: Fri May 31 09:02:54 2019
New Revision: 1860440

URL: http://svn.apache.org/viewvc?rev=1860440&view=rev
Log:
PDFBOX-3017: add tests of getContents() and getSignedContent()

Modified:
    pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java

Modified: pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java?rev=1860440&r1=1860439&r2=1860440&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java (original)
+++ pdfbox/trunk/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java Fri May 31 09:02:54 2019
@@ -320,6 +320,23 @@ public class TestCreateSignature
 
                 byte[] buf = sig.getSignedContent(new FileInputStream(signedFile));
 
+                // verify that getSignedContent() brings the same content
+                // regardless whether from an InputStream or from a byte array
+                try (FileInputStream fis = new FileInputStream(signedFile))
+                {
+                    byte[] buf2 = sig.getSignedContent(IOUtils.toByteArray(fis));
+                    Assert.assertArrayEquals(buf, buf2);
+                }
+
+                // verify that all getContents() methods returns the same content
+                try (FileInputStream fis = new FileInputStream(signedFile))
+                {
+                    byte[] contents2 = sig.getContents(IOUtils.toByteArray(fis));
+                    Assert.assertArrayEquals(contents.getBytes(), contents2);
+                }
+                byte[] contents3 = sig.getContents(new FileInputStream(signedFile));
+                Assert.assertArrayEquals(contents.getBytes(), contents3);
+
                 // inspiration:
                 // http://stackoverflow.com/a/26702631/535646
                 // http://stackoverflow.com/a/9261365/535646