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/26 15:24:06 UTC

svn commit: r1813420 - /pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java

Author: tilman
Date: Thu Oct 26 15:24:05 2017
New Revision: 1813420

URL: http://svn.apache.org/viewvc?rev=1813420&view=rev
Log:
PDFBOX-3974: don't download the test files, these have been downloaded to target/pdfs subdir in previous build phase

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=1813420&r1=1813419&r2=1813420&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 Thu Oct 26 15:24:05 2017
@@ -28,13 +28,9 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.net.URISyntaxException;
-import java.net.URL;
 
 import org.apache.pdfbox.cos.COSDocument;
-import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
 import org.apache.pdfbox.io.RandomAccessRead;
@@ -48,9 +44,9 @@ import org.junit.Test;
 
 public class TestPDFParser
 {
-
     private static final String PATH_OF_PDF = "src/test/resources/input/yaddatest.pdf";
     private static final File tmpDirectory = new File(System.getProperty("java.io.tmpdir"));
+    private static final File TARGETPDFDIR = new File("target/pdfs");
 
     private int numberOfTmpFiles = 0;
 
@@ -119,7 +115,7 @@ public class TestPDFParser
     public void testPDFParserMissingCatalog() throws IOException, URISyntaxException
     {
         // PDFBOX-3060
-        PDDocument.load(new File(TestPDFParser.class.getResource("MissingCatalog.pdf").toURI())).close();        
+        PDDocument.load(new File(TestPDFParser.class.getResource("MissingCatalog.pdf").toURI())).close();
     }
 
     /**
@@ -127,26 +123,12 @@ public class TestPDFParser
      * file. An incorrect algorithm would result in an outline dictionary being mistaken for an
      * /Info.
      *
-     * @throws MalformedURLException
      * @throws IOException
      */
     @Test
-    public void testPDFBox3208() throws MalformedURLException, IOException
+    public void testPDFBox3208() throws IOException
     {
-        byte[] byteArray;
-        try
-        {
-            InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12784025/PDFBOX-3208-L33MUTT2SVCWGCS6UIYL5TH3PNPXHIS6.pdf").openStream();
-            byteArray = IOUtils.toByteArray(is);
-            is.close();
-        }
-        catch (IOException ex)
-        {
-            System.err.println("URL loading failed, testPDFBox3208 will be skipped");
-            return;
-        }
-
-        PDDocument doc = PDDocument.load(byteArray);
+        PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3208-L33MUTT2SVCWGCS6UIYL5TH3PNPXHIS6.pdf"));
 
         PDDocumentInformation di = doc.getDocumentInformation();
         assertEquals("Liquent Enterprise Services", di.getAuthor());
@@ -165,27 +147,12 @@ public class TestPDFParser
      * Test whether the /Info is retrieved correctly when rebuilding the trailer of a corrupt file,
      * despite the /Info dictionary not having a modification date.
      *
-     * @throws MalformedURLException
      * @throws IOException
      */
     @Test
-    public void testPDFBox3940() throws MalformedURLException, IOException
+    public void testPDFBox3940() throws IOException
     {
-        byte[] byteArray;
-        try
-        {
-            InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12888957/079977.pdf").openStream();
-            byteArray = IOUtils.toByteArray(is);
-            is.close();
-        }
-        catch (IOException ex)
-        {
-            System.err.println("URL loading failed, testPDFBox3940 will be skipped");
-            return;
-        }
-
-        PDDocument doc = PDDocument.load(byteArray);
-
+        PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3940-079977.pdf"));
         PDDocumentInformation di = doc.getDocumentInformation();
         assertEquals("Unknown", di.getAuthor());
         assertEquals("C:REGULA~1IREGSFR_EQ_EM.WP", di.getCreator());
@@ -201,52 +168,24 @@ public class TestPDFParser
     /**
      * PDFBOX-3783: test parsing of file with trash after %%EOF.
      * 
-     * @throws MalformedURLException
      * @throws IOException 
      */
     @Test
-    public void testPDFBox3783() throws MalformedURLException, IOException
+    public void testPDFBox3783() throws 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();
+        PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3783-72GLBIGUC6LB46ELZFBARRJTLN4RBSQM.pdf")).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
+    public void testPDFBox3785() throws 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);
+        PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3785-202097.pdf"));
         assertEquals(11, doc.getNumberOfPages());
         doc.close();
     }
@@ -254,101 +193,45 @@ public class TestPDFParser
     /**
      * PDFBOX-3947: test parsing of file with broken object stream.
      *
-     * @throws MalformedURLException
      * @throws IOException 
      */
     @Test
-    public void testPDFBox3947() throws MalformedURLException, IOException
+    public void testPDFBox3947() throws 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();
+        PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3947-670064.pdf")).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
+    public void testPDFBox3948() throws 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();
+        PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3948-EUWO6SQS5TM4VGOMRD3FLXZHU35V2CP2.pdf")).close();
     }
 
     /**
      * PDFBOX-3949: test parsing of file with incomplete object stream.
      * 
-     * @throws MalformedURLException
      * @throws IOException 
      */
     @Test
-    public void testPDFBox3949() throws MalformedURLException, IOException
+    public void testPDFBox3949() throws 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();
+        PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3949-MKFYUGZWS3OPXLLVU2Z4LWCTVA5WNOGF.pdf")).close();
     }
 
     /**
      * PDFBOX-3950: test parsing and rendering of truncated file with missing pages.
      * 
-     * @throws MalformedURLException
      * @throws IOException 
      */
     @Test
-    public void testPDFBox3950() throws MalformedURLException, IOException
+    public void testPDFBox3950() throws 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);
+        PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf"));
         assertEquals(4, doc.getNumberOfPages());
         PDFRenderer renderer = new PDFRenderer(doc);
         for (int i = 0; i < doc.getNumberOfPages(); ++i)
@@ -372,26 +255,12 @@ public class TestPDFParser
     /**
      * PDFBOX-3951: test parsing of truncated file.
      * 
-     * @throws MalformedURLException
      * @throws IOException 
      */
     @Test
-    public void testPDFBox3951() throws MalformedURLException, IOException
+    public void testPDFBox3951() throws 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);
+        PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3951-FIHUZWDDL2VGPOE34N6YHWSIGSH5LVGZ.pdf"));
         assertEquals(143, doc.getNumberOfPages());
         doc.close();
     }
@@ -399,26 +268,12 @@ public class TestPDFParser
     /**
      * PDFBOX-3964: test parsing of broken file.
      * 
-     * @throws MalformedURLException
      * @throws IOException 
      */
     @Test
-    public void testPDFBox3964() throws MalformedURLException, IOException
+    public void testPDFBox3964() throws 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);
+        PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3964-c687766d68ac766be3f02aaec5e0d713_2.pdf"));
         assertEquals(10, doc.getNumberOfPages());
         doc.close();
     }
@@ -427,26 +282,12 @@ public class TestPDFParser
      * Test whether /Info dictionary is retrieved correctly in brute force search for the
      * Info/Catalog dictionaries.
      *
-     * @throws MalformedURLException
      * @throws IOException
      */
     @Test
-    public void testPDFBox3977() throws MalformedURLException, IOException
+    public void testPDFBox3977() throws IOException
     {
-        byte[] byteArray;
-        try
-        {
-            InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12893582/63NGFQRI44HQNPIPEJH5W2TBM6DJZWMI.pdf").openStream();
-            byteArray = IOUtils.toByteArray(is);
-            is.close();
-        }
-        catch (IOException ex)
-        {
-            System.err.println("URL loading failed, testPDFBox3977 will be skipped");
-            return;
-        }
-
-        PDDocument doc = PDDocument.load(byteArray);
+        PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3977-63NGFQRI44HQNPIPEJH5W2TBM6DJZWMI.pdf"));
         PDDocumentInformation di = doc.getDocumentInformation();
         assertEquals("QuarkXPress(tm) 6.52", di.getCreator());
         assertEquals("Acrobat Distiller 7.0 pour Macintosh", di.getProducer());
@@ -459,25 +300,12 @@ public class TestPDFParser
     /**
      * Test parsing the "genko_oc_shiryo1.pdf" file, which is susceptible to regression.
      * 
-     * @throws Exception 
+     * @throws IOException 
      */
     @Test
-    public void testParseGenko() throws Exception
+    public void testParseGenko() throws IOException
     {
-        byte[] byteArray;
-        try
-        {
-            InputStream is = new URL("https://issues.apache.org/jira/secure/attachment/12867433/genko_oc_shiryo1.pdf").openStream();
-            byteArray = IOUtils.toByteArray(is);
-            is.close();
-        }
-        catch (IOException ex)
-        {
-            System.err.println("URL loading failed, testParseGenko will be skipped");
-            return;
-        }
-
-        PDDocument.load(byteArray).close();
+        PDDocument.load(new File(TARGETPDFDIR, "genko_oc_shiryo1.pdf")).close();
     }
 
     private void executeParserTest(RandomAccessRead source, MemoryUsageSetting memUsageSetting) throws IOException