You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by tc...@apache.org on 2013/12/09 23:36:03 UTC

svn commit: r1549697 - /pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java

Author: tchojecki
Date: Mon Dec  9 22:36:03 2013
New Revision: 1549697

URL: http://svn.apache.org/r1549697
Log:
PDFBOX-1792: Some parser tests. Ignored at the moment, because we have no fix yet.

Modified:
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java

Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java?rev=1549697&r1=1549696&r2=1549697&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java Mon Dec  9 22:36:03 2013
@@ -14,56 +14,87 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.pdfbox.pdmodel;
 
+import java.io.File;
 import java.util.Arrays;
 import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.pdfbox.io.RandomAccessBuffer;
+
 /**
  * This class tests the extraction of document-level metadata.
  * @author Neil McErlean
  * @since 1.3.0
  */
-public class TestPDDocumentInformation extends TestCase {
+public class TestPDDocumentInformation extends TestCase
+{
+
+  // skipping this test, we have no fix yet.
+  public void XXXtestMetadataSequentialNonSequentialEquality() throws Exception
+  {
+    File dir = new File("src/test/resources/input");
+    for (File f : dir.listFiles()) {
+      if (f.getName().toLowerCase().endsWith(".pdf")) {
+        testSingleFileEquality(f);
+      }
+    }
+  }
+
+  private void testSingleFileEquality(File f) throws Exception
+  {
+    PDDocument seqDoc = PDDocument.load(f);
+    PDDocument nonSeqDoc = PDDocument.loadNonSeq(f, new RandomAccessBuffer());
+    PDDocumentInformation seqInfo = seqDoc.getDocumentInformation();
+    PDDocumentInformation nonSeqInfo = nonSeqDoc.getDocumentInformation();
+    assertEquals("Metadata item count", seqInfo.getMetadataKeys().size(), nonSeqInfo.getMetadataKeys().size());
+    for (String name : seqInfo.getMetadataKeys()) {
+      assertEquals(f.getName() + " :: " + name, seqInfo.getCustomMetadataValue(name),
+          nonSeqInfo.getCustomMetadataValue(name));
+    }
+    seqDoc.close();
+    nonSeqDoc.close();
+  }
 
     public void testMetadataExtraction() throws Exception {
-        PDDocument doc = null;
+    PDDocument doc = null;
         try
         {
-           // This document has been selected for this test as it contains custom metadata.
-           doc = PDDocument.load( "src/test/resources/input/hello3.pdf");
-           PDDocumentInformation info = doc.getDocumentInformation();
-           
-           assertEquals("Wrong author",            "Brian Carrier", info.getAuthor());
-           assertNotNull("Wrong creationDate",        info.getCreationDate());
-           assertEquals("Wrong creator",           "Acrobat PDFMaker 8.1 for Word", info.getCreator());
-           assertNull  ("Wrong keywords",             info.getKeywords());
-           assertNotNull("Wrong modificationDate",    info.getModificationDate());
-           assertEquals("Wrong producer",          "Acrobat Distiller 8.1.0 (Windows)", info.getProducer());
-           assertNull  ("Wrong subject",              info.getSubject());
-           assertNull  ("Wrong trapped",              info.getTrapped());
+      // This document has been selected for this test as it contains custom metadata.
+      doc = PDDocument.load("src/test/resources/input/hello3.pdf");
+      PDDocumentInformation info = doc.getDocumentInformation();
+
+      assertEquals("Wrong author", "Brian Carrier", info.getAuthor());
+      assertNotNull("Wrong creationDate", info.getCreationDate());
+      assertEquals("Wrong creator", "Acrobat PDFMaker 8.1 for Word", info.getCreator());
+      assertNull("Wrong keywords", info.getKeywords());
+      assertNotNull("Wrong modificationDate", info.getModificationDate());
+      assertEquals("Wrong producer", "Acrobat Distiller 8.1.0 (Windows)", info.getProducer());
+      assertNull("Wrong subject", info.getSubject());
+      assertNull("Wrong trapped", info.getTrapped());
 
            List<String> expectedMetadataKeys = Arrays.asList(new String[] {"CreationDate", "Author", "Creator",
                                                                            "Producer", "ModDate", "Company",
                                                                            "SourceModified", "Title"});
            assertEquals("Wrong metadata key count", expectedMetadataKeys.size(),
                                                     info.getMetadataKeys().size());
-           for (String key : expectedMetadataKeys) {
-               assertTrue("Missing metadata key:" + key, info.getMetadataKeys().contains(key));
-           }
-           
-           // Custom metadata fields.
-           assertEquals("Wrong company",           "Basis Technology Corp.", info.getCustomMetadataValue("Company"));
-           assertEquals("Wrong sourceModified",    "D:20080819181502", info.getCustomMetadataValue("SourceModified"));
+      for (String key : expectedMetadataKeys) {
+        assertTrue("Missing metadata key:" + key, info.getMetadataKeys().contains(key));
+      }
+
+      // Custom metadata fields.
+      assertEquals("Wrong company", "Basis Technology Corp.", info.getCustomMetadataValue("Company"));
+      assertEquals("Wrong sourceModified", "D:20080819181502", info.getCustomMetadataValue("SourceModified"));
         }
         finally
         {
             if( doc != null )
             {
-                doc.close();
-            }
-        }
+        doc.close();
+      }
     }
+  }
 }