You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2020/09/20 15:56:23 UTC

svn commit: r1881872 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java

Author: lehmi
Date: Sun Sep 20 15:56:22 2020
New Revision: 1881872

URL: http://svn.apache.org/viewvc?rev=1881872&view=rev
Log:
PDFBOX-4836: remove some tests as ScratchFile isn't no longer used when reading a file, added some fail statements to complete existing test cases

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java?rev=1881872&r1=1881871&r2=1881872&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java Sun Sep 20 15:56:22 2020
@@ -1,112 +1,55 @@
-/*****************************************************************************
- * 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * 
- ****************************************************************************/
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 package org.apache.pdfbox.pdfparser;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.net.URISyntaxException;
 
 import org.apache.pdfbox.Loader;
-import org.apache.pdfbox.io.MemoryUsageSetting;
-import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
-import org.apache.pdfbox.io.RandomAccessRead;
-import org.apache.pdfbox.io.ScratchFile;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDDocumentInformation;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
 import org.apache.pdfbox.rendering.PDFRenderer;
 import org.apache.pdfbox.util.DateConverter;
-import org.junit.Before;
 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;
-
-    /**
-     * Initialize the number of tmp file before the test
-     * 
-     * @throws Exception
-     */
-    @Before
-    public void setUp() throws Exception
-    {
-        numberOfTmpFiles = getNumberOfTempFile();
-    }
-
-    /**
-     * Count the number of temporary files
-     * 
-     * @return
-     */
-    private int getNumberOfTempFile()
-    {
-        int result = 0;
-        File[] tmpPdfs = tmpDirectory.listFiles(new FilenameFilter()
-        {
-            @Override
-            public boolean accept(File dir, String name)
-            {
-                return name.startsWith(COSParser.TMP_FILE_PREFIX)
-                        && name.endsWith("pdf");
-            }
-        });
-
-        if (tmpPdfs != null)
-        {
-            result = tmpPdfs.length;
-        }
-
-        return result;
-    }
-
-    @Test
-    public void testPDFParserFile() throws IOException
-    {
-        executeParserTest(new RandomAccessReadBufferedFile(new File(PATH_OF_PDF)), MemoryUsageSetting.setupMainMemoryOnly());
-    }
-
     @Test
-    public void testPDFParserFileScratchFile() throws IOException
-    {
-        executeParserTest(new RandomAccessReadBufferedFile(new File(PATH_OF_PDF)), MemoryUsageSetting.setupTempFileOnly());
-    }
-
-    @Test
-    public void testPDFParserMissingCatalog() throws IOException, URISyntaxException
+    public void testPDFParserMissingCatalog() throws URISyntaxException
     {
         // PDFBOX-3060
-        Loader.loadPDF(new File(TestPDFParser.class.getResource("MissingCatalog.pdf").toURI()))
+        try
+        {
+            Loader.loadPDF(new File(TestPDFParser.class.getResource("MissingCatalog.pdf").toURI()))
                 .close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected Exception");
+        }
     }
 
     /**
@@ -158,14 +101,21 @@ public class TestPDFParser
 
     /**
      * PDFBOX-3783: test parsing of file with trash after %%EOF.
-     * 
-     * @throws IOException 
      */
     @Test
-    public void testPDFBox3783() throws IOException
+    public void testPDFBox3783()
     {
-        Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-3783-72GLBIGUC6LB46ELZFBARRJTLN4RBSQM.pdf"))
-                .close();
+        try
+        {
+            Loader.loadPDF(
+                    new File(TARGETPDFDIR, "PDFBOX-3783-72GLBIGUC6LB46ELZFBARRJTLN4RBSQM.pdf"))
+                    .close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected IOException");
+        }
+
     }
 
     /**
@@ -185,37 +135,54 @@ public class TestPDFParser
 
     /**
      * PDFBOX-3947: test parsing of file with broken object stream.
-     *
-     * @throws IOException 
      */
     @Test
-    public void testPDFBox3947() throws IOException
+    public void testPDFBox3947()
     {
-        Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-3947-670064.pdf")).close();
+        try
+        {
+            Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-3947-670064.pdf")).close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected Exception");
+        }
     }
 
     /**
      * PDFBOX-3948: test parsing of file with object stream containing some unexpected newlines.
-     * 
-     * @throws IOException 
      */
     @Test
-    public void testPDFBox3948() throws IOException
+    public void testPDFBox3948()
     {
-        Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-3948-EUWO6SQS5TM4VGOMRD3FLXZHU35V2CP2.pdf"))
-                .close();
+        try
+        {
+            Loader.loadPDF(
+                    new File(TARGETPDFDIR, "PDFBOX-3948-EUWO6SQS5TM4VGOMRD3FLXZHU35V2CP2.pdf"))
+                    .close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected Exception");
+        }
     }
 
     /**
      * PDFBOX-3949: test parsing of file with incomplete object stream.
-     * 
-     * @throws IOException 
      */
     @Test
-    public void testPDFBox3949() throws IOException
+    public void testPDFBox3949()
     {
-        Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-3949-MKFYUGZWS3OPXLLVU2Z4LWCTVA5WNOGF.pdf"))
-                .close();
+        try
+        {
+            Loader.loadPDF(
+                    new File(TARGETPDFDIR, "PDFBOX-3949-MKFYUGZWS3OPXLLVU2Z4LWCTVA5WNOGF.pdf"))
+                    .close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected Exception");
+        }
     }
 
     /**
@@ -302,37 +269,52 @@ public class TestPDFParser
 
     /**
      * Test parsing the "genko_oc_shiryo1.pdf" file, which is susceptible to regression.
-     * 
-     * @throws IOException 
      */
     @Test
-    public void testParseGenko() throws IOException
+    public void testParseGenko()
     {
-        Loader.loadPDF(new File(TARGETPDFDIR, "genko_oc_shiryo1.pdf")).close();
+        try
+        {
+            Loader.loadPDF(new File(TARGETPDFDIR, "genko_oc_shiryo1.pdf")).close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected Exception");
+        }
     }
 
     /**
      * Test parsing the file from PDFBOX-4338, which brought an
      * ArrayIndexOutOfBoundsException before the bug was fixed.
-     *
-     * @throws IOException
      */
     @Test
-    public void testPDFBox4338() throws IOException
+    public void testPDFBox4338()
     {
-        Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-4338.pdf")).close();
+        try
+        {
+            Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-4338.pdf")).close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected Exception");
+        }
     }
 
     /**
      * Test parsing the file from PDFBOX-4339, which brought a
      * NullPointerException before the bug was fixed.
-     *
-     * @throws IOException
      */
     @Test
-    public void testPDFBox4339() throws IOException
+    public void testPDFBox4339()
     {
-        Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-4339.pdf")).close();
+        try
+        {
+            Loader.loadPDF(new File(TARGETPDFDIR, "PDFBOX-4339.pdf")).close();
+        }
+        catch (Exception exception)
+        {
+            fail("Unexpected Exception");
+        }
     }
 
     /**
@@ -366,17 +348,4 @@ public class TestPDFParser
         }
     }
 
-    private void executeParserTest(RandomAccessRead source, MemoryUsageSetting memUsageSetting) throws IOException
-    {
-        ScratchFile scratchFile = new ScratchFile(memUsageSetting);
-        PDFParser pdfParser = new PDFParser(source, scratchFile);
-        try (PDDocument doc = pdfParser.parse())
-        {
-            assertNotNull(doc);
-        }
-        source.close();
-        // number tmp file must be the same
-        assertEquals(numberOfTmpFiles, getNumberOfTempFile());
-    }
-
 }