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 2015/02/07 23:32:26 UTC

svn commit: r1658113 - in /pdfbox/trunk/preflight/src/test: java/org/apache/pdfbox/preflight/TestIsartor.java resources/expected_errors.txt

Author: tilman
Date: Sat Feb  7 22:32:26 2015
New Revision: 1658113

URL: http://svn.apache.org/r1658113
Log:
PDFBOX-2610: verify a set of errors instead of one

Modified:
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java
    pdfbox/trunk/preflight/src/test/resources/expected_errors.txt

Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java?rev=1658113&r1=1658112&r2=1658113&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java (original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java Sat Feb  7 22:32:26 2015
@@ -26,6 +26,7 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
@@ -46,7 +47,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -79,14 +79,16 @@ public class TestIsartor
         if (isartor.isDirectory())
         {
             Collection<?> pdfFiles = FileUtils.listFiles(isartor, new String[] {"pdf","PDF"}, true);
-            for (Object  pdfFile : pdfFiles)
+            for (Object pdfFile : pdfFiles)
             {
                 String fn = ((File)pdfFile).getName();
                 if (filter == null || fn.contains(filter))
                 {
                     String path = props.getProperty(fn);
                     String error = new StringTokenizer(path, "//").nextToken().trim();
-                    data.add(new Object[] { (File)pdfFile, error });
+                    String[] errTab = error.split(",");
+                    Set<String> errorSet = new HashSet<String>(Arrays.asList(errTab));
+                    data.add(new Object[] { (File) pdfFile, errorSet } );
                 }
             }
         }
@@ -100,31 +102,20 @@ public class TestIsartor
             File bavaria = new File("target/pdfs/Bavaria testsuite");
             if (bavaria.isDirectory())
             {
-                Collection<?> pdfFiles = FileUtils.listFiles(bavaria, new String[]
-                {
-                    "pdf", "PDF"
-                }, true);
+                Collection<?> pdfFiles = FileUtils.listFiles(bavaria, new String[] {"pdf","PDF"}, true);
                 for (Object pdfFile : pdfFiles)
                 {
                     String fn = ((File) pdfFile).getName();
                     if (filter == null || fn.contains(filter))
                     {
                         String path = props.getProperty(fn);
-                        if (path.isEmpty())
-                        {
-                            data.add(new Object[]
-                            {
-                                (File) pdfFile, ""
-                            });
-                        }
-                        else
+                        Set<String> errorSet = new HashSet<String>();
+                        if (!path.isEmpty())
                         {
                             String error = new StringTokenizer(path, "//").nextToken().trim();
-                            data.add(new Object[]
-                            {
-                                (File) pdfFile, error
-                            });
+                            errorSet.addAll(Arrays.asList(error.split(",")));
                         }
+                        data.add(new Object[] { (File) pdfFile, errorSet } );
                     }
                 }
             }
@@ -173,14 +164,14 @@ public class TestIsartor
         }
     }
 
-    private final String expectedError;
+    private final Set<String> expectedErrorSet;
     private final File file;
 
-    public TestIsartor(File path, String error)
+    public TestIsartor(File path, Set<String> errorSet)
     {
         System.out.println("  " + path.getName());
         this.file = path;
-        this.expectedError = error;
+        this.expectedErrorSet = errorSet;
     }
 
     @Test()
@@ -208,7 +199,7 @@ public class TestIsartor
                 result = e.getResult();
             }
             
-            if (this.expectedError.isEmpty())
+            if (this.expectedErrorSet.isEmpty())
             {
                 Set<String> errorSet = new HashSet<String>();
                 for (ValidationError error : result.getErrorsList())
@@ -234,56 +225,59 @@ public class TestIsartor
             else
             {
                 assertFalse(file.getName() + " : Isartor file should be invalid (expected " +
-                        this.expectedError + ")", result.isValid());
+                        this.expectedErrorSet + ")", result.isValid()); //TODO
 
                 assertTrue(file.getName() + " : Should find at least one error",
                         result.getErrorsList().size() > 0);
 
-                // could contain more than one error
-                boolean found = false;
-                for (ValidationError error : result.getErrorsList())
+                // each expected error should occur
+                boolean logged = false;
+                boolean allFound = true;
+                for (String expectedError : this.expectedErrorSet)
                 {
-                    if (error.getErrorCode().equals(this.expectedError))
+                    boolean oneFound = false;
+                    for (ValidationError error : result.getErrorsList())
                     {
-                        found = true;
-                        if (isartorResultFile == null)
+                        if (error.getErrorCode().equals(expectedError))
+                        {
+                            oneFound = true;
+                        }
+                        if (isartorResultFile != null && !logged)
                         {
-                            break;
+                            String log = file.getName().replace(".pdf", "") + "#" + error.getErrorCode() +
+                                    "#" + error.getDetails() + "\n";
+                            isartorResultFile.write(log.getBytes());
                         }
                     }
-                    if (isartorResultFile != null)
+                    if (!oneFound)
                     {
-                        String log = file.getName().replace(".pdf", "") + "#" + error.getErrorCode() +
-                                "#" + error.getDetails() + "\n";
-                        isartorResultFile.write(log.getBytes());
+                        allFound = false;
+                        break;
                     }
+                    
+                    // log only in the first inner loop
+                    logged = true;
                 }
-
-                if (result.getErrorsList().size() > 1)
+                if (!allFound)
                 {
-                    if (!found)
+                    Set<String> errorSet = new HashSet<String>();
+                    for (ValidationError error : result.getErrorsList())
                     {
-                        Set<String> errorSet = new HashSet<String>();
-                        for (ValidationError error : result.getErrorsList())
-                        {
-                            errorSet.add(error.getErrorCode());
-                        }
-                        StringBuilder message = new StringBuilder();
-                        for (String errMsg : errorSet)
+                        errorSet.add(error.getErrorCode());
+                    }
+                    StringBuilder message = new StringBuilder();
+                    for (String errMsg : errorSet)
+                    {
+                        if (message.length() > 0)
                         {
-                            message.append(errMsg);
-                            message.append(' ');
+                            message.append(", ");
                         }
-                        fail(String.format("%s : Invalid error code returned. Expected %s, found [%s]",
-                                file.getName(), expectedError, message.toString().trim()));
+                        message.append(errMsg);
                     }
-                    // if one of the error code of the list is the expected one, we consider test valid
-                }
-                else
-                {
-                    assertEquals(file.getName() + " : Invalid error code returned.", this.expectedError,
-                            result.getErrorsList().get(0).getErrorCode());
+                    fail(String.format("%s : Invalid error code returned. Expected %s, found [%s]",
+                            file.getName(), expectedErrorSet, message.toString().trim()));
                 }
+                // if each of the expected errors are found, we consider test valid
             }
         }
         finally

Modified: pdfbox/trunk/preflight/src/test/resources/expected_errors.txt
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/resources/expected_errors.txt?rev=1658113&r1=1658112&r2=1658113&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/resources/expected_errors.txt (original)
+++ pdfbox/trunk/preflight/src/test/resources/expected_errors.txt Sat Feb  7 22:32:26 2015
@@ -17,7 +17,7 @@
 # under the License.
 # 
 #-------------------------------------------------------------------------------
-# filename=param1,param2...
+# filename=param1,param2... // comment
 
 isartor-6-1-2-t01-fail-a.pdf=1.1
 isartor-6-1-2-t02-fail-a.pdf=1.1
@@ -292,38 +292,27 @@ good0015.pdf=
 Pardes13_Art02.pdf=1.2.3
 hopf1971.pdf=3.1.2
 ide_diss_p1.pdf=1.0.1
-
-# also has 6.1.3
-laschewsky_1.pdf=2.3.2
-
+laschewsky_1.pdf=2.3.2,1.2.3
 laschewsky_2.pdf=1.2.3
 modules_acrobat9.pdf=2.1.2
 pardes14_Jid02_reduced.pdf=1.0.3
 stat_dis_30_fixed.pdf=3.1.2
-Funktionale_Varietaeten.pdf=3.1.4
-Funktionale_Varietaeten.pdf=3.1.11
-Funktionale_Varietaeten.pdf=7.3
-Funktionale_Varietaeten.pdf=2.4.2
+Funktionale_Varietaeten.pdf=3.1.4,3.1.11,7.3,2.4.2
 apogee.pdf=3.3.1
 
-# also has 2.1.2 (conflicting N information for OutputIntent)
-bug1771.pdf=7.1
+# operator "g" without profile not detected by PDF-Tools validator, maybe because it aborts after the conflicting N.
+bug1771.pdf=7.1,2.1.2,1.2.1,1.2.5,2.4.3
 
 empty_word.pdf=7.2
-
-literat.pdf=7.11
-literat.pdf=1.2.5
-nesrin.pdf=1.2.1
-nesrin.pdf=1.2.2
-nesrin.pdf=1.2.5
+literat.pdf=1.2.5,7.11
+nesrin.pdf=1.2.1,1.2.2,1.2.5
 paper56.pdf=7.3
 
-#also has 3.1.4 2.2.1
-validierung_von_pdfa.pdf=1.4.9
-
-vwdb_95.pdf=1.2.5
-vwdb_95.pdf=7.3
+# Bavaria.xml contradicts itself about transparency groups; PDFTools reports them
+# According to http://www.pdfa.org/2011/08/pdfa-%E2%80%93-a-look-at-the-technical-side/ transparency is not permitted
+validierung_von_pdfa.pdf=1.4.9,3.1.4,2.2.1
 
+vwdb_95.pdf=1.2.5,7.3
 2001_28.pdf=7.1
 
 # See PDFBOX-2643 - Property stRef:instanceID is correct!
@@ -334,8 +323,7 @@ UCC.pdf=7.1
 
 # also has schema description missing for cc:license (http://creativecommons.org/ns#)
 # is not displayed because of other error that aborts XMP
-# also has 6.1.3 (Destination contains invalid page reference 'null')
-rolfs_diss_A1b.pdf=7.1
+rolfs_diss_A1b.pdf=1.2.3,7.1
 
 terminanschreiben.pdf=7.1