poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r806959 [4/4] - in /poi/trunk: ./ src/documentation/content/xdocs/ src/ooxml/testcases/org/apache/poi/ src/ooxml/testcases/org/apache/poi/extractor/ src/ooxml/testcases/org/apache/poi/ooxml/data/ src/ooxml/testcases/org/apache/poi/openxml4j...
Date Sun, 23 Aug 2009 12:34:42 GMT
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java Sun Aug
23 12:34:24 2009
@@ -20,29 +20,12 @@
 
 import java.io.*;
 
-public class HWPFTestDataSamples extends POIDataSamples {
-
-    private static final HWPFTestDataSamples _inst = new HWPFTestDataSamples("HWPF.testdata.path",
"SampleDoc.doc");
-
-
-    private HWPFTestDataSamples(String dir, String classPathTestFile){
-        super(dir, classPathTestFile);
-    }
-
-    public static POIDataSamples getInstance(){
-        return _inst;
-    }
-
-    public static InputStream openSampleFileStream(String sampleFileName) {
-        return _inst.openResourceAsStream(sampleFileName);
-    }
-    public static byte[] getTestDataFileContent(String fileName) {
-        return _inst.readFile(fileName);
-    }
+public class HWPFTestDataSamples {
 
     public static HWPFDocument openSampleFile(String sampleFileName) {
         try {
-            return new HWPFDocument(_inst.openResourceAsStream(sampleFileName));
+            InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName);
+            return new HWPFDocument(is);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java Sun Aug 23
12:34:24 2009
@@ -23,6 +23,7 @@
 
 import org.apache.poi.hwpf.model.PicturesTable;
 import org.apache.poi.hwpf.usermodel.Picture;
+import org.apache.poi.POIDataSamples;
 
 /**
  * Test picture support in HWPF
@@ -154,6 +155,6 @@
 	}
 
 	private static byte[] readFile(String file) {
-		return HWPFTestDataSamples.getTestDataFileContent(file);
+		return POIDataSamples.getDocumentInstance().readFile(file);
 	}
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
Sun Aug 23 12:34:24 2009
@@ -23,6 +23,7 @@
 import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.POIDataSamples;
 
 import java.io.FileInputStream;
 
@@ -65,17 +66,16 @@
 	private String filename6;
 
 	protected void setUp() throws Exception {
-		String pdirname = System.getProperty("POIFS.testdata.path");
 
 		String filename = "test2.doc";
 		String filename2 = "test.doc";
-		filename3 = pdirname + "/excel_with_embeded.xls";
+		filename3 = "excel_with_embeded.xls";
 		filename4 = "ThreeColHeadFoot.doc";
 		filename5 = "HeaderFooterUnicode.doc";
 		filename6 = "footnote.doc";
-
-		extractor = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename));
-		extractor2 = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename2));
+        POIDataSamples docTests = POIDataSamples.getDocumentInstance();
+		extractor = new WordExtractor(docTests.openResourceAsStream(filename));
+		extractor2 = new WordExtractor(docTests.openResourceAsStream(filename2));
 
 		// Build splat'd out text version
 		for(int i=0; i<p_text1.length; i++) {
@@ -123,7 +123,7 @@
 	 * @throws Exception
 	 */
 	public void testExtractFromEmbeded() throws Exception {
-		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3));
+		POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream(filename3));
 		HWPFDocument doc;
 		WordExtractor extractor3;
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java
Sun Aug 23 12:34:24 2009
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.POIDataSamples;
 
 /**
  * Tests for bugs with the WordExtractor
@@ -30,7 +31,7 @@
 
 	public void testProblemMetadata() throws Exception {
 		WordExtractor extractor =
-			new WordExtractor(HWPFTestDataSamples.openSampleFileStream("ProblemExtracting.doc"));
+			new WordExtractor(POIDataSamples.getDocumentInstance().openResourceAsStream("ProblemExtracting.doc"));
 
 		// Check it gives text without error
 		extractor.getText();

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java Sun
Aug 23 12:34:24 2009
@@ -24,6 +24,7 @@
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.POIDataSamples;
 
 /**
  * Test the picture handling
@@ -98,7 +99,7 @@
 		assertTrue(pic.getSize() > 128);
 
 		// Check right contents
-		byte[] emf = HWPFTestDataSamples.getTestDataFileContent("vector_image.emf");
+		byte[] emf = POIDataSamples.getDocumentInstance().readFile("vector_image.emf");
 		byte[] pemf = pic.getContent();
 		assertEquals(emf.length, pemf.length);
 		for(int i=0; i<emf.length; i++) {

Modified: poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java Sun Aug 23 12:34:24 2009
@@ -20,26 +20,89 @@
 
 /**
  * Centralises logic for finding/opening sample files
- *
  */
-public abstract class POIDataSamples {
+public final class POIDataSamples {
+
+    /**
+     * Name of the system property that defined path to the test data.
+     */
+    public static final String TEST_PROPERTY = "POI.testdata.path";
+
+    private static POIDataSamples _instSlideshow;
+    private static POIDataSamples _instSpreadsheet;
+    private static POIDataSamples _instDocument;
+    private static POIDataSamples _instDiagram;
+    private static POIDataSamples _instOpenxml4j;
+    private static POIDataSamples _instPOIFS;
+    private static POIDataSamples _instDDF;
+    private static POIDataSamples _instHPSF;
+    private static POIDataSamples _instHPBF;
+    private static POIDataSamples _instHSMF;
 
     private File _resolvedDataDir;
     /** <code>true</code> if standard system propery is not set,
      * but the data is available on the test runtime classpath */
     private boolean _sampleDataIsAvaliableOnClassPath;
-    private String _testDataDir;
+    private String _moduleDir;
 
     /**
      *
-     * @param dir   the name of the system property that defines  path to the test files
-     * @param classPathTestFile the name of the test file to check if resources are available
from the classpath
+     * @param moduleDir   the name of the directory containing the test files
      */
-    public POIDataSamples(String dir, String classPathTestFile){
-        _testDataDir = dir;
-        initialise(classPathTestFile);
+    private POIDataSamples(String moduleDir){
+        _moduleDir = moduleDir;
+        initialise();
+    }
+
+    public static POIDataSamples getSpreadSheetInstance(){
+        if(_instSpreadsheet == null) _instSpreadsheet = new POIDataSamples("spreadsheet");
+        return _instSpreadsheet;
+    }
+
+    public static POIDataSamples getDocumentInstance(){
+        if(_instDocument == null) _instDocument = new POIDataSamples("document");
+        return _instDocument;
+    }
+
+    public static POIDataSamples getSlideShowInstance(){
+        if(_instSlideshow == null) _instSlideshow = new POIDataSamples("slideshow");
+        return _instSlideshow;
+    }
+
+    public static POIDataSamples getDiagramInstance(){
+        if(_instOpenxml4j == null) _instOpenxml4j = new POIDataSamples("diagram");
+        return _instOpenxml4j;
+    }
+
+    public static POIDataSamples getOpenXML4JInstance(){
+        if(_instDiagram == null) _instDiagram = new POIDataSamples("openxml4j");
+        return _instDiagram;
+    }
+
+    public static POIDataSamples getPOIFSInstance(){
+        if(_instPOIFS == null) _instPOIFS = new POIDataSamples("poifs");
+        return _instPOIFS;
+    }
+
+    public static POIDataSamples getDDFInstance(){
+        if(_instDDF == null) _instDDF = new POIDataSamples("ddf");
+        return _instDDF;
+    }
+
+    public static POIDataSamples getHPSFInstance(){
+        if(_instHPSF == null) _instHPSF = new POIDataSamples("hpsf");
+        return _instHPSF;
+    }
+
+    public static POIDataSamples getPublisherInstance(){
+        if(_instHPBF == null) _instHPBF = new POIDataSamples("publisher");
+        return _instHPBF;
     }
 
+    public static POIDataSamples getHSMFInstance(){
+        if(_instHSMF == null) _instHSMF = new POIDataSamples("hsmf");
+        return _instHSMF;
+    }
     /**
      * Opens a sample file from the test data directory
      *
@@ -60,40 +123,46 @@
         }
         if (_resolvedDataDir == null) {
             throw new RuntimeException("Must set system property '"
-                    + _testDataDir
+                    + TEST_PROPERTY
                     + "' properly before running tests");
         }
 
+        File f = getFile(sampleFileName);
+        try {
+            return new FileInputStream(f);
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     *
+     * @param sampleFileName    the name of the test file
+     * @return
+     * @throws RuntimeException if the file was not found
+     */
+    public File getFile(String sampleFileName) {
         File f = new File(_resolvedDataDir, sampleFileName);
         if (!f.exists()) {
             throw new RuntimeException("Sample file '" + sampleFileName
                     + "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() +
"'");
         }
         try {
-            if(!sampleFileName.equals(f.getCanonicalFile().getName())){
+            if(sampleFileName.length() > 0 && !sampleFileName.equals(f.getCanonicalFile().getName())){
                 throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName
                         + "' but actual file is '" + f.getCanonicalFile().getName() + "'");
             }
         } catch (IOException e){
             throw new RuntimeException(e);
         }
-
-        try {
-            return new FileInputStream(f);
-        } catch (FileNotFoundException e) {
-            throw new RuntimeException(e);
-        }
+        return f;
     }
 
-    /**
-     *
-     * @param classPathTest test file to check if the resources are avaiable from the classpath
-     */
-    private void initialise(String classPathTest) {
-        String dataDirName = System.getProperty(_testDataDir);
+    private void initialise() {
+        String dataDirName = System.getProperty(TEST_PROPERTY);
         if (dataDirName == null) {
             // check to see if we can just get the resources from the classpath
-            InputStream is = openClasspathResource(classPathTest);
+            InputStream is = openClasspathResource("");
             if (is != null) {
                 try {
                     is.close(); // be nice
@@ -104,14 +173,12 @@
                 return;
             }
 
-            throw new RuntimeException("Must set system property '"
-                    + _testDataDir + "' before running tests");
+            throw new RuntimeException("Must set system property '" +
+                    TEST_PROPERTY + "' before running tests");
         }
-        File dataDir = new File(dataDirName);
+        File dataDir = new File(dataDirName, _moduleDir);
         if (!dataDir.exists()) {
-            throw new RuntimeException("Data dir '" + dataDirName
-                    + "' specified by system property '" + _testDataDir
-                    + "' does not exist");
+            throw new RuntimeException("Data dir '" + _moduleDir + " does not exist");
         }
         // convert to canonical file, to make any subsequent error messages
         // clearer.
@@ -129,7 +196,7 @@
      * @return <code>null</code> if the sample file is not deployed on the classpath.
      */
     private InputStream openClasspathResource(String sampleFileName) {
-        return getClass().getResourceAsStream("data/" + sampleFileName);
+        return getClass().getResourceAsStream("/" + _moduleDir + "/" + sampleFileName);
     }
 
     private static final class NonSeekableInputStream extends InputStream {

Modified: poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java Sun Aug 23 12:34:24
2009
@@ -23,6 +23,7 @@
 import java.util.Arrays;
 
 import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
 
 /**
  * Test read/serialize of escher blip records
@@ -30,12 +31,12 @@
  * @author Yegor Kozlov
  */
 public final class TestEscherBlipRecord extends TestCase {
-    protected String cwd = System.getProperty("DDF.testdata.path");
+    private static final POIDataSamples _samples = POIDataSamples.getDDFInstance();
 
     //test reading/serializing of a PNG blip
     public void testReadPNG() {
         //provided in bug-44886
-        byte[] data = read(new File(cwd, "Container.dat"));
+        byte[] data = _samples.readFile("Container.dat");
 
         EscherContainerRecord record = new EscherContainerRecord();
         record.fillFields(data, 0, new DefaultEscherRecordFactory());
@@ -80,7 +81,7 @@
     //test reading/serializing of a PICT metafile
     public void testReadPICT() {
         //provided in bug-44886
-        byte[] data = read(new File(cwd, "Container.dat"));
+        byte[] data = _samples.readFile("Container.dat");
 
         EscherContainerRecord record = new EscherContainerRecord();
         record.fillFields(data, 0, new DefaultEscherRecordFactory());
@@ -131,7 +132,7 @@
 
     //integral test: check that the read-write-read round trip is consistent
     public void testContainer() {
-        byte[] data = read(new File(cwd, "Container.dat"));
+        byte[] data = _samples.readFile("Container.dat");
 
         EscherContainerRecord record = new EscherContainerRecord();
         record.fillFields(data, 0, new DefaultEscherRecordFactory());
@@ -156,7 +157,7 @@
      * The test data was created from pl031405.xls attached to Bugzilla #47143
      */
     public void test47143() {
-        byte[] data = read(new File(cwd, "47143.dat"));
+        byte[] data = _samples.readFile("47143.dat");
         EscherBSERecord bse = new EscherBSERecord();
         bse.fillFields(data, 0, new DefaultEscherRecordFactory());
         bse.toString(); //assert that toString() works

Modified: poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java Sun Aug 23 12:34:24
2009
@@ -25,16 +25,13 @@
 import org.apache.poi.util.HexRead;
 import org.apache.poi.util.HexDump;
 import org.apache.poi.util.IOUtils;
+import org.apache.poi.POIDataSamples;
 
 /**
  * Tests for {@link EscherContainerRecord}
  */
 public final class TestEscherContainerRecord extends TestCase {
-	private String ESCHER_DATA_PATH;
-
-	protected void setUp() {
-		ESCHER_DATA_PATH = System.getProperty("DDF.testdata.path");
-	}
+    private static final POIDataSamples _samples = POIDataSamples.getDDFInstance();
 
 	public void testFillFields() {
 		EscherRecordFactory f = new DefaultEscherRecordFactory();
@@ -151,11 +148,7 @@
 	 *  but hopefully we now read the correct size.
 	 */
 	public void testBug44857() throws Exception {
-		File f = new File(ESCHER_DATA_PATH, "Container.dat");
-		assertTrue(f.exists());
-
-		FileInputStream finp = new FileInputStream(f);
-		byte[] data = IOUtils.toByteArray(finp);
+		byte[] data = _samples.readFile("Container.dat");
 
 		// This used to fail with an OutOfMemory
 		EscherContainerRecord record = new EscherContainerRecord();

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java Sun Aug 23 12:34:24
2009
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hpsf.basic;
 
+import org.apache.poi.POIDataSamples;
+
 import java.io.File;
 import java.io.FileFilter;
 import java.util.logging.Logger;
@@ -30,6 +32,7 @@
  *         href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
  */
 public class AllDataFilesTester {
+    private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
 
     /**
      * <p>Interface specifying how to run a test on a single file.</p>
@@ -56,8 +59,8 @@
      */
     public void runTests(final TestTask task) throws Throwable
     {
-        final String dataDirName = System.getProperty("HPSF.testdata.path");
-        final File dataDir = new File(dataDirName);
+        POIDataSamples _samples = POIDataSamples.getHPSFInstance();
+        final File dataDir = _samples.getFile("");
         final File[] docs = dataDir.listFiles(new FileFilter()
         {
             public boolean accept(final File file)

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java Sun Aug 23 12:34:24 2009
@@ -37,6 +37,7 @@
 import org.apache.poi.hpsf.Section;
 import org.apache.poi.hpsf.SummaryInformation;
 import org.apache.poi.hpsf.wellknown.SectionIDMap;
+import org.apache.poi.POIDataSamples;
 
 /**
  * <p>Tests the basic HPSF functionality.</p>
@@ -80,11 +81,10 @@
      * @exception FileNotFoundException if the file to be read does not exist.
      * @exception IOException if any other I/O exception occurs.
      */
-    public void setUp() throws FileNotFoundException, IOException
+    public void setUp() throws IOException
     {
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
-        final File data = new File(dataDir, POI_FS);
+        POIDataSamples samples = POIDataSamples.getHPSFInstance();
+        final File data = samples.getFile(POI_FS);
         poiFiles = Util.readPOIFiles(data);
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java Sun Aug 23
12:34:24 2009
@@ -35,6 +35,7 @@
 import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.hpsf.SummaryInformation;
 import org.apache.poi.hpsf.Variant;
+import org.apache.poi.POIDataSamples;
 
 /**
  * <p>Test case for OLE2 files with empty properties. An empty property's type
@@ -69,9 +70,8 @@
      */
     public void setUp() throws FileNotFoundException, IOException
     {
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
-        final File data = new File(dataDir, POI_FS);
+        POIDataSamples samples = POIDataSamples.getHPSFInstance();
+        final File data = samples.getFile(POI_FS);
 
         poiFiles = Util.readPOIFiles(data);
     }

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java Sun Aug 23 12:34:24
2009
@@ -25,6 +25,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.POIDataSamples;
 
 /**
  * <p>Tests some HPSF functionality by reading all property sets from all files
@@ -41,8 +42,8 @@
      */
     public void testReadAllFiles()
     {
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
+        POIDataSamples _samples = POIDataSamples.getHPSFInstance();
+        final File dataDir = _samples.getFile("");
         final File[] fileList = dataDir.listFiles(new FileFilter()
             {
                 public boolean accept(final File f)

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java Sun Aug 23 12:34:24
2009
@@ -32,6 +32,7 @@
 import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.hpsf.Section;
 import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.POIDataSamples;
 
 /**
  * <p>Tests whether Unicode string can be read from a
@@ -57,9 +58,8 @@
      * @exception IOException if any other I/O exception occurs
      */
     protected void setUp() {
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
-        data = new File(dataDir, POI_FS);
+        POIDataSamples samples = POIDataSamples.getHPSFInstance();
+        data = samples.getFile(POI_FS);
     }
 
 

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java Sun Aug 23 12:34:24 2009
@@ -63,6 +63,7 @@
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.TempFile;
+import org.apache.poi.POIDataSamples;
 
 /**
  * <p>Tests HPSF's writing functionality.</p>
@@ -71,6 +72,7 @@
  */
 public class TestWrite extends TestCase
 {
+    private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
 
     static final String POI_FS = "TestHPSFWritingFunctionality.doc";
 
@@ -110,10 +112,7 @@
      */
     public void testNoFormatID() throws IOException
     {
-        final String dataDirName = System.getProperty("HPSF.testdata.path");
-        final File dataDir = new File(dataDirName);
-        final File filename = new File(dataDir, POI_FS);
-        filename.deleteOnExit();
+        final File filename = TempFile.createTempFile(POI_FS, ".doc");
 
         /* Create a mutable property set with a section that does not have the
          * formatID set: */
@@ -159,8 +158,7 @@
     public void testWriteEmptyPropertySet()
         throws IOException, UnsupportedVariantTypeException
     {
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
+        final File dataDir = _samples.getFile("");
         final File filename = new File(dataDir, POI_FS);
         filename.deleteOnExit();
 
@@ -202,8 +200,7 @@
     {
         final String AUTHOR = "Rainer Klute";
         final String TITLE = "Test Document"; 
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
+        final File dataDir = _samples.getFile("");
         final File filename = new File(dataDir, POI_FS);
         filename.deleteOnExit();
         final OutputStream out = new FileOutputStream(filename);
@@ -274,8 +271,7 @@
         final String SECTION1 = "Section 1";
         final String SECTION2 = "Section 2";
 
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
+        final File dataDir = _samples.getFile("");
         final File filename = new File(dataDir, POI_FS);
         filename.deleteOnExit();
         final OutputStream out = new FileOutputStream(filename);
@@ -673,8 +669,7 @@
      */
     public void testRecreate()
     {
-        final File dataDir =
-            new File(System.getProperty("HPSF.testdata.path"));
+        final File dataDir = _samples.getFile("");
         final File[] fileList = dataDir.listFiles(new FileFilter()
             {
                 public boolean accept(final File f)

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java Sun Aug 23 12:34:24
2009
@@ -53,6 +53,7 @@
 import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.DocumentInputStream;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.POIDataSamples;
 
 /**
  * <p>Tests HPSF's high-level writing functionality for the well-known property
@@ -78,8 +79,8 @@
 
     /**
      * <p>This test method checks whether DocumentSummary information streams
-     * can be read. This is done by opening all "Test*" files in the directrory
-     * pointed to by the "HPSF.testdata.path" system property, trying to extract
+     * can be read. This is done by opening all "Test*" files in the 'poifs' directrory
+     * pointed to by the "POI.testdata.path" system property, trying to extract
      * the document summary information stream in the root directory and calling
      * its get... methods.</p>
      * @throws IOException 
@@ -93,8 +94,8 @@
             NoPropertySetStreamException, MarkUnsupportedException,
             UnexpectedPropertySetTypeException
     {
-        final String dataDirName = System.getProperty("HPSF.testdata.path");
-        final File dataDir = new File(dataDirName);
+        POIDataSamples _samples = POIDataSamples.getHPSFInstance();
+        final File dataDir = _samples.getFile("");
         final File[] docs = dataDir.listFiles(new FileFilter()
         {
             public boolean accept(final File file)
@@ -205,8 +206,8 @@
             NoPropertySetStreamException, MarkUnsupportedException,
             UnexpectedPropertySetTypeException, WritingNotSupportedException
     {
-        final String dataDirName = System.getProperty("HPSF.testdata.path");
-        final File dataDir = new File(dataDirName);
+        POIDataSamples _samples = POIDataSamples.getHPSFInstance();
+        final File dataDir = _samples.getFile("");
         final File doc1 = new File(dataDir, POI_FS);
     
         /* Read a test document <em>doc1</em> into a POI filesystem. */
@@ -625,8 +626,8 @@
             }
         };
 
-        final String dataDirName = System.getProperty("HPSF.testdata.path");
-        final File dataDir = new File(dataDirName);
+        POIDataSamples _samples = POIDataSamples.getHPSFInstance();
+        final File dataDir = _samples.getFile("");
         final File[] docs = dataDir.listFiles(new FileFilter()
         {
             public boolean accept(final File file)

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
Sun Aug 23 12:34:24 2009
@@ -27,18 +27,15 @@
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.POIDataSamples;
 
 public final class TestHPSFPropertiesExtractor extends TestCase {
-	private String dir;
-
-	protected void setUp() {
-		dir = System.getProperty("HPSF.testdata.path");
-		assertNotNull("HPSF.testdata.path not set", dir);
-	}
+    private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
 
 	public void testNormalProperties() throws Exception {
-		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
-				new File(dir, "TestMickey.doc")));
+		POIFSFileSystem fs = new POIFSFileSystem(
+                _samples.openResourceAsStream("TestMickey.doc")
+        );
 		HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
 		ext.getText();
 
@@ -60,8 +57,9 @@
 	}
 
 	public void testNormalUnicodeProperties() throws Exception {
-		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(new File(dir,
-				"TestUnicode.xls")));
+		POIFSFileSystem fs = new POIFSFileSystem(
+                _samples.openResourceAsStream("TestUnicode.xls")
+        );
 		HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
 		ext.getText();
 
@@ -83,8 +81,9 @@
 	}
 
 	public void testCustomProperties() throws Exception {
-		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
-				new File(dir, "TestMickey.doc")));
+		POIFSFileSystem fs = new POIFSFileSystem(
+                _samples.openResourceAsStream("TestMickey.doc")
+        );
 		HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
 
 		// Custom properties are part of the document info stream
@@ -101,7 +100,9 @@
 		POIFSFileSystem fs;
 		HSSFWorkbook wb;
 		try {
-			fs = new POIFSFileSystem(new FileInputStream(new File(dir, "TestUnicode.xls")));
+			fs = new POIFSFileSystem(
+                    _samples.openResourceAsStream("TestUnicode.xls")
+            );
 			wb = new HSSFWorkbook(fs);
 		} catch (IOException e) {
 			throw new RuntimeException(e);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java Sun Aug 23 12:34:24
2009
@@ -21,6 +21,7 @@
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.POIDataSamples;
 
 /**
  * @author Yegor Kozlov
@@ -44,7 +45,7 @@
     }
 
     public byte[] getTestDataFileContent(String fileName) {
-        return HSSFTestDataSamples.getTestDataFileContent(fileName);
+        return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
     }
 
     public SpreadsheetVersion getSpreadsheetVersion(){

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java Sun Aug 23 12:34:24
2009
@@ -30,17 +30,9 @@
  *
  * @author Josh Micich
  */
-public final class HSSFTestDataSamples extends POIDataSamples {
+public final class HSSFTestDataSamples {
 
-	private static final HSSFTestDataSamples _inst = new HSSFTestDataSamples("HSSF.testdata.path",
"SampleSS.xls");
-
-	private HSSFTestDataSamples(String dir, String classPathTestFile){
-		super(dir, classPathTestFile);
-	}
-
-	public static POIDataSamples getInstance(){
-		return _inst;
-	}
+	private static final POIDataSamples _inst = POIDataSamples.getSpreadSheetInstance();
 
 	public static InputStream openSampleFileStream(String sampleFileName) {
 		return _inst.openResourceAsStream(sampleFileName);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java Sun Aug
23 12:34:24 2009
@@ -28,6 +28,8 @@
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.POIDataSamples;
+
 /**
  *
  */
@@ -214,11 +216,8 @@
 	 * Embded in a non-excel file
 	 */
 	public void testWithEmbeded() throws Exception {
-		// TODO - encapsulate sys prop 'POIFS.testdata.path' similar to HSSFTestDataSamples
-		String pdirname = System.getProperty("POIFS.testdata.path");
-		String filename = pdirname + "/word_with_embeded.doc";
 		POIFSFileSystem fs = new POIFSFileSystem(
-				new FileInputStream(filename)
+			POIDataSamples.getDocumentInstance().openResourceAsStream("word_with_embeded.doc")
 		);
 
 		DirectoryNode objPool = (DirectoryNode) fs.getRoot().getEntry("ObjectPool");
@@ -244,12 +243,10 @@
 	 * Excel embeded in excel
 	 */
 	public void testWithEmbededInOwn() throws Exception {
-		// TODO - encapsulate sys prop 'POIFS.testdata.path' similar to HSSFTestDataSamples
-		String pdirname = System.getProperty("POIFS.testdata.path");
-		String filename = pdirname + "/excel_with_embeded.xls";
+        POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance();
 		POIFSFileSystem fs = new POIFSFileSystem(
-				new FileInputStream(filename)
-		);
+                ssSamples.openResourceAsStream("excel_with_embeded.xls")
+        );
 
 		DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5");
 		DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B4");

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=806959&r1=806958&r2=806959&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Sun Aug
23 12:34:24 2009
@@ -26,6 +26,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.POIDataSamples;
 
 /**
  * Tests for POIFSFileSystem
@@ -134,15 +135,13 @@
 		String[] files = new String[] {
 			"ShortLastBlock.qwp", "ShortLastBlock.wps"	
 		};
-		String pdirname = System.getProperty("POIFS.testdata.path");
 
-		for(int i=0; i<files.length; i++) {
-			File f = new File(pdirname, files[i]);
-			assertTrue(f.exists());
-			
+        POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
+        for(int i=0; i<files.length; i++) {
+
 			// Open the file up
 			POIFSFileSystem fs = new POIFSFileSystem(
-					new FileInputStream(f)
+			    _samples.openResourceAsStream(files[i])
 			);
 			
 			// Write it into a temp output array

Copied: poi/trunk/test-data/hpsf/Test_Humor-Generation.ppt (from r806956, poi/trunk/src/testcases/org/apache/poi/hpsf/data/Test_Humor-Generation.ppt)
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/hpsf/Test_Humor-Generation.ppt?p2=poi/trunk/test-data/hpsf/Test_Humor-Generation.ppt&p1=poi/trunk/src/testcases/org/apache/poi/hpsf/data/Test_Humor-Generation.ppt&r1=806956&r2=806959&rev=806959&view=diff
==============================================================================
Binary files - no diff available.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message