You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ju...@apache.org on 2008/08/05 12:51:26 UTC

svn commit: r682665 [21/21] - in /incubator/pdfbox/trunk/src: org/pdfbox/ org/pdfbox/ant/ org/pdfbox/cos/ org/pdfbox/encoding/ org/pdfbox/encryption/ org/pdfbox/examples/ org/pdfbox/examples/fdf/ org/pdfbox/examples/pdmodel/ org/pdfbox/examples/persist...

Modified: incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/TestFDF.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/TestFDF.java?rev=682665&r1=682664&r2=682665&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/TestFDF.java (original)
+++ incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/TestFDF.java Tue Aug  5 03:51:13 2008
@@ -1,18 +1,18 @@
 /*
- * 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 test.pdfbox.pdmodel;
 
@@ -92,8 +92,8 @@
             PDAcroForm form = fdeb.getDocumentCatalog().getAcroForm();
             PDTextbox field = (PDTextbox)form.getField( "f67_1" );
             field.setValue( "2" );
-            
-            String expected = 
+
+            String expected =
                 "/Tx BMC " +
                 "BT " +
                 "/Helv 9 Tf " +
@@ -103,7 +103,7 @@
                 "(2) Tj " +
                 "ET " +
                 "EMC";
-            
+
             testContentStreams( fdeb, field, expected );
         }
         finally
@@ -113,9 +113,9 @@
                 fdeb.close();
             }
         }
-        
+
     }
-    
+
     /**
      * This will test a pdf with lots of fields.
      *
@@ -130,8 +130,8 @@
             PDAcroForm form = fdeb.getDocumentCatalog().getAcroForm();
             PDTextbox feld2 = (PDTextbox)form.getField( "Feld.2" );
             feld2.setValue( "Benjamin" );
-            
-            String expected = 
+
+            String expected =
             "1 1 0.8000000119 rg " +
             " 0 0 127.5 19.8299999237 re " +
             " f " +
@@ -163,16 +163,16 @@
             " 0 0 0 rg " +
             " 4 4.721 Td " +
             "(Benjamin) Tj " +
-            "ET " + 
+            "ET " +
             "EMC";
-            
+
             testContentStreams( fdeb, feld2, expected );
-            
+
             PDRadioCollection feld3 = (PDRadioCollection)form.getField( "Feld.3" );
             feld3.setValue("RB1");
             assertEquals( "RB1", feld3.getValue() );
             //assertEquals( ((PDCheckbox)feld3.getKids().get( 0 )).getValue(), "RB1" );
-            
+
         }
         finally
         {
@@ -182,10 +182,10 @@
             }
         }
     }
-    
+
     /**
      * This will test the Freedom pdf.
-     * 
+     *
      * @throws Exception If there is an error while testing.
      */
     public void testFDFFreedomExpressions() throws Exception
@@ -204,12 +204,12 @@
             PDField secondKid = (PDField)kids.get( 1 );
             testContentStreamContains( freedom, firstKid, "Steve" );
             testContentStreamContains( freedom, secondKid, "Steve" );
-            
+
             //the appearance stream is suppose to be null because there
             //is an F action in the AA dictionary that populates that field.
             PDField totalAmt = form.getField( "eeSuppTotalAmt" );
             assertTrue( totalAmt.getDictionary().getDictionaryObject( "AP" ) == null );
-            
+
         }
         finally
         {
@@ -223,25 +223,25 @@
             }
         }
     }
-    
+
     private void testContentStreamContains( PDDocument doc, PDField field, String expected ) throws Exception
     {
         PDAnnotationWidget widget = field.getWidget();
         Map normalAppearance = widget.getAppearance().getNormalAppearance();
         PDAppearanceStream appearanceStream = (PDAppearanceStream)normalAppearance.get( "default" );
         COSStream actual = appearanceStream.getStream();
-        
+
         List actualTokens = getStreamTokens( doc, actual );
         assertTrue( actualTokens.contains( new COSString( expected ) ) );
     }
-    
+
     private void testContentStreams( PDDocument doc, PDField field, String expected ) throws Exception
     {
         PDAnnotationWidget widget = field.getWidget();
         Map normalAppearance = widget.getAppearance().getNormalAppearance();
         PDAppearanceStream appearanceStream = (PDAppearanceStream)normalAppearance.get( "default" );
         COSStream actual = appearanceStream.getStream();
-        
+
         List actualTokens = getStreamTokens( doc, actual );
         List expectedTokens = getStreamTokens( doc, expected );
         assertEquals( actualTokens.size(), expectedTokens.size() );
@@ -252,7 +252,7 @@
             assertEquals( actualToken, expectedToken );
         }
     }
-    
+
     private List getStreamTokens( PDDocument doc, String string ) throws IOException
     {
         PDFStreamParser parser;
@@ -267,7 +267,7 @@
         }
         return tokens;
     }
-    
+
     private List getStreamTokens( PDDocument doc, COSStream stream ) throws IOException
     {
         PDFStreamParser parser;
@@ -281,4 +281,4 @@
         }
         return tokens;
     }
-}
\ No newline at end of file
+}

Propchange: incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/TestFDF.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/interactive/form/TestFields.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/interactive/form/TestFields.java?rev=682665&r1=682664&r2=682665&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/interactive/form/TestFields.java (original)
+++ incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/interactive/form/TestFields.java Tue Aug  5 03:51:13 2008
@@ -1,18 +1,18 @@
 /*
- * 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 test.pdfbox.pdmodel.interactive.form;
 
@@ -69,7 +69,7 @@
 
     /**
      * This will test setting field flags on the PDField.
-     * 
+     *
      * @throws IOException If there is an error creating the field.
      */
     public void testFlags() throws IOException
@@ -80,43 +80,43 @@
             doc = new PDDocument();
             PDAcroForm form = new PDAcroForm( doc );
             PDTextbox textBox = new PDTextbox(form);
-            
+
             //assert that default is false.
             assertFalse( textBox.shouldComb() );
-            
+
             //try setting and clearing a single field
             textBox.setComb( true );
             assertTrue( textBox.shouldComb() );
             textBox.setComb( false );
             assertFalse( textBox.shouldComb() );
-            
+
             //try setting and clearing multiple fields
             textBox.setComb( true );
             textBox.setDoNotScroll( true );
             assertTrue( textBox.shouldComb() );
             assertTrue( textBox.doNotScroll() );
-            
+
             textBox.setComb( false );
             textBox.setDoNotScroll( false );
             assertFalse( textBox.shouldComb() );
             assertFalse( textBox.doNotScroll() );
-            
+
             //assert that setting a field to false multiple times works
             textBox.setComb( false );
             assertFalse( textBox.shouldComb() );
             textBox.setComb( false );
             assertFalse( textBox.shouldComb() );
-            
+
             //assert that setting a field to true multiple times works
             textBox.setComb( true );
             assertTrue( textBox.shouldComb() );
             textBox.setComb( true );
             assertTrue( textBox.shouldComb() );
-            
-            
-            
-            
-            
+
+
+
+
+
         }
         finally
         {
@@ -126,5 +126,5 @@
             }
         }
     }
-    
-}
\ No newline at end of file
+
+}

Propchange: incubator/pdfbox/trunk/src/test/pdfbox/pdmodel/interactive/form/TestFields.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/pdfbox/trunk/src/test/pdfbox/util/TestDateUtil.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/pdfbox/util/TestDateUtil.java?rev=682665&r1=682664&r2=682665&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/pdfbox/util/TestDateUtil.java (original)
+++ incubator/pdfbox/trunk/src/test/pdfbox/util/TestDateUtil.java Tue Aug  5 03:51:13 2008
@@ -1,18 +1,18 @@
 /*
- * 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 test.pdfbox.util;
 
@@ -37,7 +37,7 @@
      * Test class constructor.
      *
      * @param name The name of the test class.
-     * 
+     *
      * @throws IOException If there is an error creating the test.
      */
     public TestDateUtil( String name ) throws IOException
@@ -66,10 +66,10 @@
     {
         return new TestSuite( TestDateUtil.class );
     }
-    
+
     /**
      * Command line execution.
-     * 
+     *
      * @param args Command line arguments.
      */
     public static void main( String[] args )
@@ -77,4 +77,4 @@
         String[] arg = {TestDateUtil.class.getName() };
         junit.textui.TestRunner.main( arg );
     }
-}
\ No newline at end of file
+}

Propchange: incubator/pdfbox/trunk/src/test/pdfbox/util/TestDateUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/pdfbox/trunk/src/test/pdfbox/util/TestPDFToImage.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/pdfbox/util/TestPDFToImage.java?rev=682665&r1=682664&r2=682665&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/pdfbox/util/TestPDFToImage.java (original)
+++ incubator/pdfbox/trunk/src/test/pdfbox/util/TestPDFToImage.java Tue Aug  5 03:51:13 2008
@@ -1,283 +1,283 @@
-/*
- * 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 test.pdfbox.util;
-
-import java.io.*; //for BufferedReader
-/*import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
-import java.io.FilenameFilter;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.Writer;
-*/
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.pdfbox.pdmodel.PDDocument;
-import org.pdfbox.util.PDFImageWriter;
-
-/**
- * Test suite for PDFTextStripper.
- *
- * 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 "test/input".  An output file is
- * created in "test/output" with the same name as the PDF file, plus an
- * additional ".jpg" suffix.
- *
- * The output file is then tested against a known good result file from
- * the input directory (again, with the same name as the tested PDF file,
- * but with the additional ".jpg" suffix).
- *
- * Currently, testing against known output is simply a byte-for-byte comparison
- *
- *In the future, testing against the known output may be accomplished using PerceptualDiff
- *  http://sourceforge.net/projects/pdiff
- *
- *
- * @author <a href="mailto:DanielWilson@Users.Sourceforge.net">Daniel Wilson</a>
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.1 $
- */
-public class TestPDFToImage extends TestCase
-{
-    private boolean bFail = false;
-    private PDFImageWriter writer = null;
-    private PrintWriter log = null;
-    private File mdirTest = null;
-    private File mcurFile = null;
-        
-    /**
-     * Test class constructor.
-     *
-     * @param name The name of the test class.
-     * 
-     * @throws IOException If there is an error creating the test.
-     */
-    public TestPDFToImage( String name ) throws IOException
-    {
-        super( name );
-        writer = new PDFImageWriter();
-    }
-
-    /**
-     * Test suite setup.
-     */
-    public void setUp()
-    {
-        // If you want to test a single file using DEBUG logging, from an IDE,
-        // you can do something like this:
-        //
-        // System.setProperty("test.pdfbox.util.TextStripper.file", "FVS318Ref.pdf");
-    }
-
-    /**
-     * Validate text extraction on a single file.
-     *
-     * @param file The file to validate
-     * @param bLogResult Whether to log the extracted text
-     * @throws Exception when there is an exception
-     */
-    public void doTestFile(File file, boolean bLogResult)
-        throws Exception
-    {
-	String sCmd;
-        PDDocument document = null;
-        
-        log.println("\nPreparing to convert " + file.getName());
-        log.flush();
-	
-	try
-      {
-        document =  PDDocument.load(file);
-        writer.WriteImage(document,"png","",1,Integer.MAX_VALUE, "test/output/" + file.getName() + "-");
-      }
-      catch(Exception e)
-      {
-          this.bFail=true;
-         System.err.println("Error converting file " + file.getName());
-         e.printStackTrace();  
-          
-          log.println("Error converting file " + file.getName() + "\n" + e);
-          
-      }
-      finally{
-          document.close();
-      }
-        
-      //Now check the resulting files ... did we get identical PNG(s)?
-      try
-      {
-          mcurFile = file;
-          
-      File[] outFiles = testDir().listFiles(new FilenameFilter()
-            {
-                public boolean accept(File dir, String name)
-                {
-                    return (name.endsWith(".png") && name.startsWith(mcurFile.getName(),0));
-                }
-            });
-            for (int n = 0; n < outFiles.length; n++)
-                {
-                    File outFile = new File("test/output/" + outFiles[n].getName());
-                    if (!outFile.exists() ||
-                        !filesAreIdentical(outFiles[n], outFile)){
-                            this.bFail=true;
-                            log.println("Input and output not identical for file: " + outFile.getName());
-                        }                
-                }
-        }
-    catch(Exception e)
-      {
-          this.bFail=true;
-         System.err.println("Error comparing file output for " + file.getName());
-         e.printStackTrace();  
-      }
-      
-    }
-
-    /**
-     * Test to validate image rendering of file set.
-     *
-     * @throws Exception when there is an exception
-     */
-    public void testRenderImage()
-        throws Exception
-    {
-        String filename = System.getProperty("test.pdfbox.util.TextStripper.file");
-        
-        try
-        {
-            log = new PrintWriter( new FileWriter( "RenderImage.log" ) );
-    
-            if ((filename == null) || (filename.length() == 0))
-            {
-                File[] testFiles = testDir().listFiles(new FilenameFilter()
-                {
-                    public boolean accept(File dir, String name)
-                    {
-                        return (name.endsWith(".pdf") || name.endsWith(".ai"));
-                    }
-                });
-    
-                for (int n = 0; n < testFiles.length; n++)
-                {
-                    doTestFile(testFiles[n], false);
-                }
-            }
-            else
-            {
-                doTestFile(new File(testDir(), filename), true);
-            }
-    
-            if (this.bFail)
-            {
-                fail("One or more failures, see test log for details");
-            }
-        }
-        finally
-        {
-            if( log != null )
-            {
-                log.close();
-            }
-        }
-    }
-
-    /**
-     * 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 );
-    }
-    
-    public static boolean filesAreIdentical(File left, File right) throws IOException
-    {
-	    //http://forum.java.sun.com/thread.jspa?threadID=688105&messageID=4003259
-	    
-	    /* -- I reworked ASSERT's into IF statement -- dwilson
-        assert left != null;
-        assert right != null;
-        assert left.exists();
-        assert right.exists();
-        */
-	if(left != null && right != null && left.exists() && right.exists()){
-		if (left.length() != right.length())
-		    return false;
-		
-		FileInputStream lin = new FileInputStream(left);
-		FileInputStream rin = new FileInputStream(right);
-		try
-		{
-		    byte[] lbuffer = new byte[4096];
-		    byte[] rbuffer = new byte[lbuffer.length];
-		    for (int lcount = 0; (lcount = lin.read(lbuffer)) > 0;)
-		    {
-			int bytesRead = 0;
-			for (int rcount = 0; (rcount = rin.read(rbuffer, bytesRead, lcount - bytesRead)) > 0;)
-			{
-			    bytesRead += rcount;
-			}
-			for (int byteIndex = 0; byteIndex < lcount; byteIndex++)
-			{
-			    if (lbuffer[byteIndex] != rbuffer[byteIndex])
-				return false;
-			}
-		    }
-		}
-		finally
-		{
-		    lin.close();
-		    rin.close();
-		}
-		return true;
-	}else{
-		return false;
-	}
-    }
-    
-    private File testDir(){
-        if (null==mdirTest)
-            mdirTest = new File("test/input/rendering");
-        
-        return mdirTest;
-    }
-}
\ No newline at end of file
+/*
+ * 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 test.pdfbox.util;
+
+import java.io.*; //for BufferedReader
+/*import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+*/
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.pdfbox.pdmodel.PDDocument;
+import org.pdfbox.util.PDFImageWriter;
+
+/**
+ * Test suite for PDFTextStripper.
+ *
+ * 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 "test/input".  An output file is
+ * created in "test/output" with the same name as the PDF file, plus an
+ * additional ".jpg" suffix.
+ *
+ * The output file is then tested against a known good result file from
+ * the input directory (again, with the same name as the tested PDF file,
+ * but with the additional ".jpg" suffix).
+ *
+ * Currently, testing against known output is simply a byte-for-byte comparison
+ *
+ *In the future, testing against the known output may be accomplished using PerceptualDiff
+ *  http://sourceforge.net/projects/pdiff
+ *
+ *
+ * @author <a href="mailto:DanielWilson@Users.Sourceforge.net">Daniel Wilson</a>
+ * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestPDFToImage extends TestCase
+{
+    private boolean bFail = false;
+    private PDFImageWriter writer = null;
+    private PrintWriter log = null;
+    private File mdirTest = null;
+    private File mcurFile = null;
+
+    /**
+     * Test class constructor.
+     *
+     * @param name The name of the test class.
+     *
+     * @throws IOException If there is an error creating the test.
+     */
+    public TestPDFToImage( String name ) throws IOException
+    {
+        super( name );
+        writer = new PDFImageWriter();
+    }
+
+    /**
+     * Test suite setup.
+     */
+    public void setUp()
+    {
+        // If you want to test a single file using DEBUG logging, from an IDE,
+        // you can do something like this:
+        //
+        // System.setProperty("test.pdfbox.util.TextStripper.file", "FVS318Ref.pdf");
+    }
+
+    /**
+     * Validate text extraction on a single file.
+     *
+     * @param file The file to validate
+     * @param bLogResult Whether to log the extracted text
+     * @throws Exception when there is an exception
+     */
+    public void doTestFile(File file, boolean bLogResult)
+        throws Exception
+    {
+	String sCmd;
+        PDDocument document = null;
+
+        log.println("\nPreparing to convert " + file.getName());
+        log.flush();
+
+	try
+      {
+        document =  PDDocument.load(file);
+        writer.WriteImage(document,"png","",1,Integer.MAX_VALUE, "test/output/" + file.getName() + "-");
+      }
+      catch(Exception e)
+      {
+          this.bFail=true;
+         System.err.println("Error converting file " + file.getName());
+         e.printStackTrace();
+
+          log.println("Error converting file " + file.getName() + "\n" + e);
+
+      }
+      finally{
+          document.close();
+      }
+
+      //Now check the resulting files ... did we get identical PNG(s)?
+      try
+      {
+          mcurFile = file;
+
+      File[] outFiles = testDir().listFiles(new FilenameFilter()
+            {
+                public boolean accept(File dir, String name)
+                {
+                    return (name.endsWith(".png") && name.startsWith(mcurFile.getName(),0));
+                }
+            });
+            for (int n = 0; n < outFiles.length; n++)
+                {
+                    File outFile = new File("test/output/" + outFiles[n].getName());
+                    if (!outFile.exists() ||
+                        !filesAreIdentical(outFiles[n], outFile)){
+                            this.bFail=true;
+                            log.println("Input and output not identical for file: " + outFile.getName());
+                        }
+                }
+        }
+    catch(Exception e)
+      {
+          this.bFail=true;
+         System.err.println("Error comparing file output for " + file.getName());
+         e.printStackTrace();
+      }
+
+    }
+
+    /**
+     * Test to validate image rendering of file set.
+     *
+     * @throws Exception when there is an exception
+     */
+    public void testRenderImage()
+        throws Exception
+    {
+        String filename = System.getProperty("test.pdfbox.util.TextStripper.file");
+
+        try
+        {
+            log = new PrintWriter( new FileWriter( "RenderImage.log" ) );
+
+            if ((filename == null) || (filename.length() == 0))
+            {
+                File[] testFiles = testDir().listFiles(new FilenameFilter()
+                {
+                    public boolean accept(File dir, String name)
+                    {
+                        return (name.endsWith(".pdf") || name.endsWith(".ai"));
+                    }
+                });
+
+                for (int n = 0; n < testFiles.length; n++)
+                {
+                    doTestFile(testFiles[n], false);
+                }
+            }
+            else
+            {
+                doTestFile(new File(testDir(), filename), true);
+            }
+
+            if (this.bFail)
+            {
+                fail("One or more failures, see test log for details");
+            }
+        }
+        finally
+        {
+            if( log != null )
+            {
+                log.close();
+            }
+        }
+    }
+
+    /**
+     * 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 );
+    }
+
+    public static boolean filesAreIdentical(File left, File right) throws IOException
+    {
+	    //http://forum.java.sun.com/thread.jspa?threadID=688105&messageID=4003259
+
+	    /* -- I reworked ASSERT's into IF statement -- dwilson
+        assert left != null;
+        assert right != null;
+        assert left.exists();
+        assert right.exists();
+        */
+	if(left != null && right != null && left.exists() && right.exists()){
+		if (left.length() != right.length())
+		    return false;
+
+		FileInputStream lin = new FileInputStream(left);
+		FileInputStream rin = new FileInputStream(right);
+		try
+		{
+		    byte[] lbuffer = new byte[4096];
+		    byte[] rbuffer = new byte[lbuffer.length];
+		    for (int lcount = 0; (lcount = lin.read(lbuffer)) > 0;)
+		    {
+			int bytesRead = 0;
+			for (int rcount = 0; (rcount = rin.read(rbuffer, bytesRead, lcount - bytesRead)) > 0;)
+			{
+			    bytesRead += rcount;
+			}
+			for (int byteIndex = 0; byteIndex < lcount; byteIndex++)
+			{
+			    if (lbuffer[byteIndex] != rbuffer[byteIndex])
+				return false;
+			}
+		    }
+		}
+		finally
+		{
+		    lin.close();
+		    rin.close();
+		}
+		return true;
+	}else{
+		return false;
+	}
+    }
+
+    private File testDir(){
+        if (null==mdirTest)
+            mdirTest = new File("test/input/rendering");
+
+        return mdirTest;
+    }
+}

Propchange: incubator/pdfbox/trunk/src/test/pdfbox/util/TestPDFToImage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripper.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripper.java?rev=682665&r1=682664&r2=682665&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripper.java (original)
+++ incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripper.java Tue Aug  5 03:51:13 2008
@@ -1,18 +1,18 @@
 /*
- * 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 test.pdfbox.util;
 
@@ -89,7 +89,7 @@
      * Test class constructor.
      *
      * @param name The name of the test class.
-     * 
+     *
      * @throws IOException If there is an error creating the test.
      */
     public TestTextStripper( String name ) throws IOException
@@ -207,15 +207,15 @@
     public void doTestFile(File file, boolean bLogResult)
         throws Exception
     {
-        
+
         log.println("Preparing to parse " + file.getName());
-        
+
         OutputStream os = null;
         Writer writer = null;
         PDDocument document = null;
         try
         {
-            
+
             document = PDDocument.load(file);
             File outFile = new File(file.getParentFile().getParentFile(), "output/" + file.getName() + ".txt");
             os = new FileOutputStream(outFile);
@@ -239,7 +239,7 @@
             {
                 this.bFail = true;
                 log.println(
-                    "FAILURE: Input verification file: " + expectedFile.getAbsolutePath() + 
+                    "FAILURE: Input verification file: " + expectedFile.getAbsolutePath() +
                     " did not exist");
                 return;
             }
@@ -309,7 +309,7 @@
         try
         {
             log = new PrintWriter( new FileWriter( "textextract.log" ) );
-    
+
             if ((filename == null) || (filename.length() == 0))
             {
                 File[] testFiles = testDir.listFiles(new FilenameFilter()
@@ -319,7 +319,7 @@
                         return (name.endsWith(".pdf"));
                     }
                 });
-    
+
                 for (int n = 0; n < testFiles.length; n++)
                 {
                     doTestFile(testFiles[n], false);
@@ -329,7 +329,7 @@
             {
                 doTestFile(new File(testDir, filename), true);
             }
-    
+
             if (this.bFail)
             {
                 fail("One or more failures, see test log for details");
@@ -353,10 +353,10 @@
     {
         return new TestSuite( TestTextStripper.class );
     }
-    
+
     /**
      * Command line execution.
-     * 
+     *
      * @param args Command line arguments.
      */
     public static void main( String[] args )
@@ -364,4 +364,4 @@
         String[] arg = {TestTextStripper.class.getName() };
         junit.textui.TestRunner.main( arg );
     }
-}
\ No newline at end of file
+}

Propchange: incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripperPerformance.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripperPerformance.java?rev=682665&r1=682664&r2=682665&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripperPerformance.java (original)
+++ incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripperPerformance.java Tue Aug  5 03:51:13 2008
@@ -1,18 +1,18 @@
 /*
- * 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 test.pdfbox.util;
 
@@ -140,10 +140,10 @@
     {
         return new TestSuite( TestTextStripperPerformance.class );
     }
-    
+
     /**
      * Command line execution.
-     * 
+     *
      * @param args Command line arguments.
      */
     public static void main( String[] args )
@@ -151,4 +151,4 @@
         String[] arg = {TestTextStripperPerformance.class.getName() };
         junit.textui.TestRunner.main( arg );
     }
-}
\ No newline at end of file
+}

Propchange: incubator/pdfbox/trunk/src/test/pdfbox/util/TestTextStripperPerformance.java
------------------------------------------------------------------------------
    svn:eol-style = native