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 2017/10/21 17:28:25 UTC
svn commit: r1812836 -
/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
Author: tilman
Date: Sat Oct 21 17:28:25 2017
New Revision: 1812836
URL: http://svn.apache.org/viewvc?rev=1812836&view=rev
Log:
PDFBOX-3974: add parsing regression tests
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java?rev=1812836&r1=1812835&r2=1812836&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java Sat Oct 21 17:28:25 2017
@@ -41,6 +41,7 @@ import org.apache.pdfbox.io.RandomAccess
import org.apache.pdfbox.io.ScratchFile;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
+import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.util.DateConverter;
import org.junit.Before;
import org.junit.Test;
@@ -197,6 +198,232 @@ public class TestPDFParser
doc.close();
}
+ /**
+ * PDFBOX-3783: test parsing of file with trash after %%EOF.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3783() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12867102/PDFBOX-3783-72GLBIGUC6LB46ELZFBARRJTLN4RBSQM.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3783 will be skipped");
+ return;
+ }
+
+ PDDocument.load(byteArray).close();
+ }
+
+ /**
+ * PDFBOX-3785, PDFBOX-3957:
+ * Test whether truncated file with several revisions has correct page count.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3785() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12867113/202097.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3785 will be skipped");
+ return;
+ }
+
+ PDDocument doc = PDDocument.load(byteArray);
+ assertEquals("Adjust test to 11 when PDFBOX-3785 is fixed", 1, doc.getNumberOfPages());
+ //assertEquals(11, doc.getNumberOfPages());
+ doc.close();
+ }
+
+ /**
+ * PDFBOX-3947: test parsing of file with broken object stream.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3947() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12890031/670064.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3947 will be skipped");
+ return;
+ }
+
+ PDDocument.load(byteArray).close();
+ }
+
+ /**
+ * PDFBOX-3948: test parsing of file with object stream containing some unexpected newlines.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3948() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12890034/EUWO6SQS5TM4VGOMRD3FLXZHU35V2CP2.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3948 will be skipped");
+ return;
+ }
+
+ PDDocument.load(byteArray).close();
+ }
+
+ /**
+ * PDFBOX-3949: test parsing of file with incomplete object stream.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3949() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12890037/MKFYUGZWS3OPXLLVU2Z4LWCTVA5WNOGF.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3949 will be skipped");
+ return;
+ }
+
+ PDDocument.load(byteArray).close();
+ }
+
+ /**
+ * PDFBOX-3950: test parsing and rendering of truncated file with missing pages.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3950() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12890042/23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3950 will be skipped");
+ return;
+ }
+
+ PDDocument doc = PDDocument.load(byteArray);
+ assertEquals(4, doc.getNumberOfPages());
+ PDFRenderer renderer = new PDFRenderer(doc);
+ for (int i = 0; i < doc.getNumberOfPages(); ++i)
+ {
+ try
+ {
+ renderer.renderImage(i);
+ }
+ catch (IOException ex)
+ {
+ if (i == 3 && ex.getMessage().equals("name for 'gs' operator not found in resources: /GS7"))
+ {
+ continue;
+ }
+ throw ex;
+ }
+ }
+ doc.close();
+ }
+
+ /**
+ * PDFBOX-3951: test parsing of truncated file.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3951() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12890047/FIHUZWDDL2VGPOE34N6YHWSIGSH5LVGZ.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3951 will be skipped");
+ return;
+ }
+
+ PDDocument doc = PDDocument.load(byteArray);
+ assertEquals(143, doc.getNumberOfPages());
+ doc.close();
+ }
+
+ /**
+ * PDFBOX-3964: test parsing of broken file.
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test
+ public void testPDFBox3964() throws MalformedURLException, IOException
+ {
+ byte[] byteArray;
+ try
+ {
+ InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12892097/c687766d68ac766be3f02aaec5e0d713_2.pdf").openStream();
+ byteArray = IOUtils.toByteArray(is);
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("URL loading failed, testPDFBox3964 will be skipped");
+ return;
+ }
+
+ PDDocument doc = PDDocument.load(byteArray);
+ assertEquals(10, doc.getNumberOfPages());
+ doc.close();
+ }
+
/**
* Test parsing the "genko_oc_shiryo1.pdf" file, which is susceptible to regression.
*