diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java index 0357c5a23..1864c7311 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java @@ -55,10 +55,16 @@ package org.apache.poi.hpsf.basic; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileFilter; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import junit.framework.Assert; import junit.framework.TestCase; @@ -66,11 +72,14 @@ import junit.framework.TestCase; import org.apache.poi.hpsf.DocumentSummaryInformation; import org.apache.poi.hpsf.HPSFException; import org.apache.poi.hpsf.MarkUnsupportedException; +import org.apache.poi.hpsf.MutablePropertySet; import org.apache.poi.hpsf.NoPropertySetStreamException; import org.apache.poi.hpsf.PropertySet; import org.apache.poi.hpsf.PropertySetFactory; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hpsf.UnexpectedPropertySetTypeException; +import org.apache.poi.poifs.filesystem.DocumentEntry; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; @@ -223,8 +232,53 @@ public class TestBasic extends TestCase + /** + *

This test methods reads all property set streams from all POI + * filesystems in the "data" directory.

+ */ + public void testReadAllFiles() + { + final File dataDir = + new File(System.getProperty("HPSF.testdata.path")); + final File[] fileList = dataDir.listFiles(new FileFilter() + { + public boolean accept(final File f) + { + return f.isFile(); + } + }); + try + { + for (int i = 0; i < fileList.length; i++) + { + File f = fileList[i]; + System.out.println("Reading file " + f); + /* Read the POI filesystem's property set streams: */ + final POIFile[] psf1 = Util.readPropertySets(f); + + for (int j = 0; j < psf1.length; j++) + { + final InputStream in = + new ByteArrayInputStream(psf1[j].getBytes()); + final PropertySet psIn = PropertySetFactory.create(in); + } + } + } + catch (Throwable t) + { + final String s = Util.toString(t); + System.err.println(s); + } + } + + + /** *

Runs the test cases stand-alone.

+ * + * @param args Command-line arguments (ignored) + * + * @exception Throwable if any sort of exception or error occurs */ public static void main(final String[] args) throws Throwable { diff --git a/src/testcases/org/apache/poi/hpsf/basic/Util.java b/src/testcases/org/apache/poi/hpsf/basic/Util.java index 7c30fd9f0..fffefe996 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/Util.java +++ b/src/testcases/org/apache/poi/hpsf/basic/Util.java @@ -62,6 +62,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -69,11 +71,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Properties; -import org.apache.poi.hpsf.MarkUnsupportedException; -import org.apache.poi.hpsf.NoPropertySetStreamException; import org.apache.poi.hpsf.PropertySet; -import org.apache.poi.hpsf.PropertySetFactory; -import org.apache.poi.hpsf.UnexpectedPropertySetTypeException; import org.apache.poi.poifs.eventfilesystem.POIFSReader; import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent; import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener; @@ -186,7 +184,8 @@ public class Util f.setName(event.getName()); f.setPath(event.getPath()); final InputStream in = event.getStream(); - final ByteArrayOutputStream out = new ByteArrayOutputStream(); + final ByteArrayOutputStream out = + new ByteArrayOutputStream(); Util.copy(in, out); out.close(); f.setBytes(out.toByteArray()); @@ -300,4 +299,36 @@ public class Util System.getProperty("user.dir")); } + + + /** + *

Returns a textual representation of a {@link Throwable}, including a + * stacktrace.

+ * + * @param t The {@link Throwable} + * + * @return a string containing the output of a call to + * t.printStacktrace(). + */ + public static String toString(final Throwable t) + { + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + pw.close(); + try + { + sw.close(); + return sw.toString(); + } + catch (IOException e) + { + final StringBuffer b = new StringBuffer(t.getMessage()); + b.append("\n"); + b.append("Could not create a stacktrace. Reason: "); + b.append(e.getMessage()); + return b.toString(); + } + } + }