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 2009/07/12 14:08:06 UTC
svn commit: r793340 - in
/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox:
filter/TestFilters.java util/TestPDFToImage.java
Author: lehmi
Date: Sun Jul 12 12:08:05 2009
New Revision: 793340
URL: http://svn.apache.org/viewvc?rev=793340&view=rev
Log:
PDFBOX-391: added support for optional processing of a directory named input-ext/output-ext to TestPDFToImage, adjusted directory in TestFilters
Modified:
incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/filter/TestFilters.java
incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestPDFToImage.java
Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/filter/TestFilters.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/filter/TestFilters.java?rev=793340&r1=793339&r2=793340&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/filter/TestFilters.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/filter/TestFilters.java Sun Jul 12 12:08:05 2009
@@ -31,11 +31,6 @@
import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.filter.DCTFilter;
-import org.apache.pdfbox.filter.CCITTFaxDecodeFilter;
-import org.apache.pdfbox.filter.Filter;
-import org.apache.pdfbox.filter.FilterManager;
-import org.apache.pdfbox.filter.RunLengthDecodeFilter;
/**
* This will test all of the filters in the PDFBox system.
@@ -47,7 +42,8 @@
{
private static final int BUFFER_SIZE = 2048;
private static final COSDictionary EMPTY_DICTIONARY = new COSDictionary();
-
+ private static final String CLASSES_DIR = "target/classes";
+
/**
* Constructor.
*
@@ -87,7 +83,7 @@
filter instanceof CCITTFaxDecodeFilter ||
filter instanceof RunLengthDecodeFilter))
{
- checkFilter( new File( "classes" ), filter );
+ checkFilter( new File( CLASSES_DIR ), filter );
long stop = System.currentTimeMillis();
System.out.println( "Time for filter " + filter.getClass().getName() + "=" + (stop-start) );
}
Modified: incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestPDFToImage.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestPDFToImage.java?rev=793340&r1=793339&r2=793340&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestPDFToImage.java (original)
+++ incubator/pdfbox/trunk/src/test/java/org/apache/pdfbox/util/TestPDFToImage.java Sun Jul 12 12:08:05 2009
@@ -59,7 +59,6 @@
private boolean bFail = false;
private PDFImageWriter writer = null;
private PrintWriter log = null;
- private File mdirTest = null;
private File mcurFile = null;
/**
@@ -91,20 +90,21 @@
*
* @param file The file to validate
* @param bLogResult Whether to log the extracted text
+ * @param inDir Name of the input directory
+ * @param outDir Name of the output directory
* @throws Exception when there is an exception
*/
- public void doTestFile(File file, boolean bLogResult)
+ public void doTestFile(File file, boolean bLogResult, String inDir, String outDir)
throws Exception
{
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() + "-");
+ writer.writeImage(document, "png", "", 1, Integer.MAX_VALUE, outDir + file.getName() + "-");
}
catch(Exception e)
{
@@ -124,7 +124,7 @@
{
mcurFile = file;
- File[] outFiles = testDir().listFiles(new FilenameFilter()
+ File[] outFiles = new File(outDir).listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
@@ -133,12 +133,12 @@
});
for (int n = 0; n < outFiles.length; n++)
{
- File outFile = new File("test/output/" + outFiles[n].getName());
- if (!outFile.exists() ||
- !filesAreIdentical(outFiles[n], outFile))
+ File inFile = new File(inDir + outFiles[n].getName());
+ if (!inFile.exists() ||
+ !filesAreIdentical(outFiles[n], inFile))
{
this.bFail=true;
- log.println("Input and output not identical for file: " + outFile.getName());
+ log.println("Input and output not identical for file: " + inFile.getName());
}
}
}
@@ -160,6 +160,10 @@
throws Exception
{
String filename = System.getProperty("org.apache.pdfbox.util.TextStripper.file");
+ String inDir = new String("test/input/rendering/");
+ String outDir = new String("test/output/rendering/");
+ String inDirExt = new String("test/input-ext/rendering/");
+ String outDirExt = new String("test/output-ext/rendering/");
try
{
@@ -167,7 +171,7 @@
if ((filename == null) || (filename.length() == 0))
{
- File[] testFiles = testDir().listFiles(new FilenameFilter()
+ File[] testFiles = new File(inDir).listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
@@ -177,12 +181,24 @@
for (int n = 0; n < testFiles.length; n++)
{
- doTestFile(testFiles[n], false);
+ doTestFile(testFiles[n], false, inDir, outDir);
+ }
+ testFiles = new File(inDirExt).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, inDirExt, outDirExt);
}
}
else
{
- doTestFile(new File(testDir(), filename), true);
+ doTestFile(new File(inDir, filename), true, inDir, outDir);
}
if (this.bFail)
@@ -220,7 +236,7 @@
junit.textui.TestRunner.main( arg );
}
- private static boolean filesAreIdentical(File left, File right) throws IOException
+ private boolean filesAreIdentical(File left, File right) throws IOException
{
//http://forum.java.sun.com/thread.jspa?threadID=688105&messageID=4003259
@@ -272,12 +288,4 @@
}
}
- private File testDir()
- {
- if (null==mdirTest)
- {
- mdirTest = new File("test/input/rendering");
- }
- return mdirTest;
- }
}