pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1695134 - in /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox: ParallelParameterized.java rendering/TestPDFToImage.java
Date Mon, 10 Aug 2015 16:46:37 GMT
Author: tilman
Date: Mon Aug 10 16:46:37 2015
New Revision: 1695134

URL: http://svn.apache.org/r1695134
Log:
PDFBOX-1695: use a parameterized test as suggested by John Hewson, remove unused stuff

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/ParallelParameterized.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/ParallelParameterized.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/ParallelParameterized.java?rev=1695134&r1=1695133&r2=1695134&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/ParallelParameterized.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/ParallelParameterized.java Mon Aug
10 16:46:37 2015
@@ -31,14 +31,14 @@ import java.util.concurrent.TimeUnit;
  */
 public class ParallelParameterized extends Parameterized
 {
-    static final long TIMEOUT_SECS = 120;
-
     private static class FixedThreadPoolScheduler implements RunnerScheduler
     {
-        private ExecutorService executorService;
+        private final ExecutorService executorService;
+        private final long timeoutSeconds;
 
-        FixedThreadPoolScheduler()
+        FixedThreadPoolScheduler(long timeoutSeconds)
         {
+            this.timeoutSeconds = timeoutSeconds;
             int cores = Runtime.getRuntime().availableProcessors();
 
             // for debugging
@@ -55,12 +55,13 @@ public class ParallelParameterized exten
             executorService = Executors.newFixedThreadPool(cores);
         }
 
-        @Override public void finished()
+        @Override 
+        public void finished()
         {
             executorService.shutdown();
             try
             {
-                executorService.awaitTermination(TIMEOUT_SECS, TimeUnit.SECONDS);
+                executorService.awaitTermination(timeoutSeconds, TimeUnit.SECONDS);
             }
             catch (InterruptedException exc)
             {
@@ -77,6 +78,11 @@ public class ParallelParameterized exten
     public ParallelParameterized(Class c) throws Throwable
     {
         super(c);
-        setScheduler(new FixedThreadPoolScheduler());
+        long timeoutSeconds = Long.MAX_VALUE;
+        if (c.getSimpleName().equals("TestRendering"))
+        {
+            timeoutSeconds = 30;
+        }
+        setScheduler(new FixedThreadPoolScheduler(timeoutSeconds));
     }
 }

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java?rev=1695134&r1=1695133&r2=1695134&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java Mon
Aug 10 16:46:37 2015
@@ -24,21 +24,26 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 import javax.imageio.ImageIO;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.ParallelParameterized;
 import org.apache.pdfbox.pdmodel.PDDocument;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  * Test suite for rendering.
  *
  * FILE SET VALIDATION
  *
- * This test suite is designed to test PDFToImage using a set of PDF files and known good
output for
- * each. The default mode of testAll() is to process each *.pdf file in
+ * This test is designed to test PDFToImage using a set of PDF files and known good output
for
+ * each. The default mode is to process all *.pdf and *.ai files in
  * "src/test/resources/input/rendering". An output file is created in "target/test-output/rendering"
  * with the same name as the PDF file, plus an additional page number and ".png" suffix.
  *
@@ -56,7 +61,8 @@ import org.apache.pdfbox.pdmodel.PDDocum
  * @author Ben Litchfield
  * @author Tilman Hausherr
  */
-public class TestPDFToImage extends TestCase
+@RunWith(ParallelParameterized.class)
+public class TestPDFToImage
 {
 
     /**
@@ -64,39 +70,57 @@ public class TestPDFToImage extends Test
      */
     private static final Log LOG = LogFactory.getLog(TestPDFToImage.class);
 
-    String inDir = "src/test/resources/input/rendering";
-    String outDir = "target/test-output/rendering/";
-    String inDirExt = "target/test-input-ext/rendering";
-    String outDirExt = "target/test-output-ext/rendering";
+    static String inDir = "src/test/resources/input/rendering";
+    static String outDir = "target/test-output/rendering/";
+    
+    String filename;
+    
+    @Parameterized.Parameters(name = "{0}")
+    public static Collection<Object[]> data()
+    {
+        File[] testFiles = new File(inDir).listFiles(new FilenameFilter()
+        {
+            @Override
+            public boolean accept(File dir, String name)
+            {
+                return (name.toLowerCase().endsWith(".pdf") || name.toLowerCase().endsWith(".ai"));
+            }
+        });
+
+        List<Object[]> params = new ArrayList<Object[]>();
+        for (File file : testFiles)
+        {
+            params.add(new Object[] { file.getName() });
+        }
+        return params;
+    }
 
     /**
      * Test class constructor.
      *
-     * @param name The name of the test class.
+     * @param filename The name of the test class.
      *
      * @throws IOException If there is an error creating the test.
      */
-    public TestPDFToImage(String name) throws IOException
+    public TestPDFToImage(String filename) throws IOException
     {
-        super(name);
+        this.filename = filename;
     }
-
-    /**
-     * Test suite setup.
+    
+   /**
+     * Test to validate image rendering of file.
+     *
+     * @throws IOException when there is an exception
      */
-    @Override
-    public void setUp()
+    @Test
+    public void testRenderImage() throws IOException
     {
-    }
-
-    public void setInDir(String inDir)
-    {
-        this.inDir = inDir;
-    }
+        new File(outDir).mkdirs();
 
-    public void setOutDir(String outDir)
-    {
-        this.outDir = outDir;
+        if (!doTestFile(new File(inDir, filename), inDir, outDir))
+        {
+            fail("failure, see test log for details");
+        }
     }
 
     /**
@@ -137,7 +161,7 @@ public class TestPDFToImage extends Test
      *
      * @throws IOException
      */
-    BufferedImage diffImages(BufferedImage bim1, BufferedImage bim2) throws IOException
+    private BufferedImage diffImages(BufferedImage bim1, BufferedImage bim2) throws IOException
     {
         int minWidth = Math.min(bim1.getWidth(), bim2.getWidth());
         int minHeight = Math.min(bim1.getHeight(), bim2.getHeight());
@@ -321,100 +345,6 @@ public class TestPDFToImage extends Test
         return !failed;
     }
 
-    /**
-     * Test to validate image rendering of file set.
-     *
-     * @throws Exception when there is an exception
-     */
-    public void testRenderImages()
-            throws Exception
-    {
-        boolean failed = false;
-
-        new File(outDir).mkdirs();
-
-        File[] testFiles = new File(inDir).listFiles(new FilenameFilter()
-        {
-            @Override
-            public boolean accept(File dir, String name)
-            {
-                return (name.endsWith(".pdf") || name.endsWith(".ai"));
-            }
-        });
-        for (File testFile : testFiles)
-        {
-            if (!doTestFile(testFile, inDir, outDir))
-            {
-                failed = true;
-            }
-        }
-        testFiles = new File(inDirExt).listFiles(new FilenameFilter()
-        {
-            @Override
-            public boolean accept(File dir, String name)
-            {
-                return (name.endsWith(".pdf") || name.endsWith(".ai"));
-            }
-        });
-        if (testFiles != null)
-        {
-            for (File testFile : testFiles)
-            {
-                if (!doTestFile(testFile, inDirExt, outDirExt))
-                {
-                    failed = true;
-                }
-            }
-        }
-
-        if (failed)
-        {
-            fail("One or more failures, see test log for details");
-        }
-    }
-
-    /**
-     * Test to validate image rendering of file.
-     *
-     * @param filename the file name to validate.
-     * 
-     * @throws Exception when there is an exception
-     */
-    public void testRenderImage(String filename)
-            throws Exception
-    {
-        new File(outDir).mkdirs();
-
-        if (!doTestFile(new File(inDir, filename), inDir, outDir))
-        {
-            fail("One or more failures, see test log for details");
-        }
-    }
-
-    /**
-     * Set the tests in the suite for this test class.
-     *
-     * @return the Suite.
-     */
-    public static Test suite()
-    {
-        return new TestSuite(TestPDFToImage.class);
-    }
-
-    /**
-     * Command line execution.
-     *
-     * @param args Command line arguments.
-     */
-    public static void main(String[] args)
-    {
-        String[] arg =
-        {
-            TestPDFToImage.class.getName()
-        };
-        junit.textui.TestRunner.main(arg);
-    }
-
     private boolean filesAreIdentical(File left, File right) throws IOException
     {
         //http://forum.java.sun.com/thread.jspa?threadID=688105&messageID=4003259



Mime
View raw message