You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/04/07 05:02:06 UTC

svn commit: r645348 [1/6] - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/util/ testcases/org/apache/poi/ testcases/org/apache/poi/hssf/ testcases/org/apache/poi/hssf/eventusermodel/ testcases/org/apache/poi/hssf/extractor/ testca...

Author: josh
Date: Sun Apr  6 20:02:03 2008
New Revision: 645348

URL: http://svn.apache.org/viewvc?rev=645348&view=rev
Log:
refactored all hssf junits to get test sample data in the in one place

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/util/HexRead.java
    poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java
    poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
    poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
    poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPropertySorter.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Sun Apr  6 20:02:03 2008
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.0.3-beta1" date="2008-04-??">
+           <action dev="POI-DEVELOPERS" type="fix">refactored all junits' usage of HSSF.testdata.path to one place</action>
            <action dev="POI-DEVELOPERS" type="fix">44739 - Small fixes for conditional formatting (regions with max row/col index)</action>
            <action dev="POI-DEVELOPERS" type="add">Implement Sheet.removeShape(Shape shape) in HSLF</action>
            <action dev="RK" type="add">44694 - HPSF: Support for property sets without sections</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sun Apr  6 20:02:03 2008
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.3-beta1" date="2008-04-??">
+           <action dev="POI-DEVELOPERS" type="fix">refactored all junits' usage of HSSF.testdata.path to one place</action>
            <action dev="POI-DEVELOPERS" type="fix">44739 - Small fixes for conditional formatting (regions with max row/col index)</action>
            <action dev="RK" type="add">44694 - HPSF: Support for property sets without sections</action>
            <action dev="POI-DEVELOPERS" type="add">Implement Sheet.removeShape(Shape shape) in HSLF</action>

Modified: poi/trunk/src/java/org/apache/poi/util/HexRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/HexRead.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/HexRead.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/HexRead.java Sun Apr  6 20:02:03 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.util;
 
@@ -25,6 +23,7 @@
 
 /**
  * Utilities to read hex from files.
+ * TODO - move to test packages
  *
  * @author Marc Johnson
  * @author Glen Stampoultzis (glens at apache.org)
@@ -62,10 +61,8 @@
      *
      * @see #readData(String)
      */
-    public static byte[] readData( String filename, String section ) throws IOException
-    {
-        File file = new File( filename );
-        FileInputStream stream = new FileInputStream( file );
+    public static byte[] readData(InputStream stream, String section ) throws IOException {
+    	
         try
         {
             StringBuffer sectionText = new StringBuffer();
@@ -99,6 +96,12 @@
             stream.close();
         }
         throw new IOException( "Section '" + section + "' not found" );
+    }
+    public static byte[] readData( String filename, String section ) throws IOException
+    {
+        File file = new File( filename );
+        FileInputStream stream = new FileInputStream( file );
+        return readData(stream, section);
     }
 
     static public byte[] readData( InputStream stream, int eofChar )

Modified: poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java Sun Apr  6 20:02:03 2008
@@ -15,17 +15,17 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
-
 
 package org.apache.poi;
 
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
 import junit.framework.TestCase;
-import java.io.*;
 
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.poifs.filesystem.*;
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
 /**
  * Tests that POIDocument correctly loads and saves the common
@@ -36,85 +36,73 @@
  *
  * @author Nick Burch (nick at torchbox dot com)
  */
-public class TestPOIDocumentMain extends TestCase {
+public final class TestPOIDocumentMain extends TestCase {
 	// The POI Documents to work on
 	private POIDocument doc;
 	private POIDocument doc2;
-	// POIFS primed on the test (two different hssf) data
-	private POIFSFileSystem pfs;
-	private POIFSFileSystem pfs2;
 
 	/**
-	 * Set things up, using a PowerPoint document and 
-	 *  a Word Document for our testing
+	 * Set things up, two spreadsheets for our testing
 	 */
-    public void setUp() throws Exception {
-		String dirnameHSSF = System.getProperty("HSSF.testdata.path");
-		String filenameHSSF = dirnameHSSF + "/DateFormats.xls";
-		String filenameHSSF2 = dirnameHSSF + "/StringFormulas.xls";
-		
-		FileInputStream fisHSSF = new FileInputStream(filenameHSSF);
-		pfs = new POIFSFileSystem(fisHSSF);
-		doc = new HSSFWorkbook(pfs);
-		
-		FileInputStream fisHSSF2 = new FileInputStream(filenameHSSF2);
-		pfs2 = new POIFSFileSystem(fisHSSF2);
-		doc2 = new HSSFWorkbook(pfs2);
+	public void setUp() {
+		
+		doc = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
+		doc2 = HSSFTestDataSamples.openSampleWorkbook("StringFormulas.xls");
+	}
+	
+	public void testReadProperties() throws Exception {
+		// We should have both sets
+		assertNotNull(doc.getDocumentSummaryInformation());
+		assertNotNull(doc.getSummaryInformation());
+		
+		// Check they are as expected for the test doc
+		assertEquals("Administrator", doc.getSummaryInformation().getAuthor());
+		assertEquals(0, doc.getDocumentSummaryInformation().getByteCount());
+	}
+		
+	public void testReadProperties2() throws Exception {	
+		// Check again on the word one
+		assertNotNull(doc2.getDocumentSummaryInformation());
+		assertNotNull(doc2.getSummaryInformation());
+		
+		assertEquals("Avik Sengupta", doc2.getSummaryInformation().getAuthor());
+		assertEquals(null, doc2.getSummaryInformation().getKeywords());
+		assertEquals(0, doc2.getDocumentSummaryInformation().getByteCount());
 	}
-    
-    public void testReadProperties() throws Exception {
-    	// We should have both sets
-    	assertNotNull(doc.getDocumentSummaryInformation());
-    	assertNotNull(doc.getSummaryInformation());
-    	
-    	// Check they are as expected for the test doc
-    	assertEquals("Administrator", doc.getSummaryInformation().getAuthor());
-    	assertEquals(0, doc.getDocumentSummaryInformation().getByteCount());
-    }
-    	
-    public void testReadProperties2() throws Exception {	
-    	// Check again on the word one
-    	assertNotNull(doc2.getDocumentSummaryInformation());
-    	assertNotNull(doc2.getSummaryInformation());
-    	
-    	assertEquals("Avik Sengupta", doc2.getSummaryInformation().getAuthor());
-    	assertEquals(null, doc2.getSummaryInformation().getKeywords());
-    	assertEquals(0, doc2.getDocumentSummaryInformation().getByteCount());
-    }
-
-    public void testWriteProperties() throws Exception {
-    	// Just check we can write them back out into a filesystem
-    	POIFSFileSystem outFS = new POIFSFileSystem();
-    	doc.readProperties();
-        doc.writeProperties(outFS);
-    	
-    	// Should now hold them
-    	assertNotNull(
-    			outFS.createDocumentInputStream("\005SummaryInformation")
-    	);
-    	assertNotNull(
-    			outFS.createDocumentInputStream("\005DocumentSummaryInformation")
-    	);
-    }
 
-    public void testWriteReadProperties() throws Exception {
+	public void testWriteProperties() throws Exception {
+		// Just check we can write them back out into a filesystem
+		POIFSFileSystem outFS = new POIFSFileSystem();
+		doc.readProperties();
+		doc.writeProperties(outFS);
+		
+		// Should now hold them
+		assertNotNull(
+				outFS.createDocumentInputStream("\005SummaryInformation")
+		);
+		assertNotNull(
+				outFS.createDocumentInputStream("\005DocumentSummaryInformation")
+		);
+	}
+
+	public void testWriteReadProperties() throws Exception {
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 		
-    	// Write them out
-    	POIFSFileSystem outFS = new POIFSFileSystem();
-    	doc.readProperties();
-        doc.writeProperties(outFS);
-    	outFS.writeFilesystem(baos);
-    	
-    	// Create a new version
-    	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-    	POIFSFileSystem inFS = new POIFSFileSystem(bais);
-    	
-    	// Check they're still there
-    	doc.filesystem = inFS;
-    	doc.readProperties();
-    	
-    	// Delegate test
-    	testReadProperties();
-    }
+		// Write them out
+		POIFSFileSystem outFS = new POIFSFileSystem();
+		doc.readProperties();
+		doc.writeProperties(outFS);
+		outFS.writeFilesystem(baos);
+		
+		// Create a new version
+		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+		POIFSFileSystem inFS = new POIFSFileSystem(bais);
+		
+		// Check they're still there
+		doc.filesystem = inFS;
+		doc.readProperties();
+		
+		// Delegate test
+		testReadProperties();
+	}
 }

Added: 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=645348&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java Sun Apr  6 20:02:03 2008
@@ -0,0 +1,175 @@
+/* ====================================================================
+   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 org.apache.poi.hssf;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
+/**
+ * Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder. 
+ * 
+ * @author Josh Micich
+ */
+public final class HSSFTestDataSamples {
+
+	private static final String TEST_DATA_DIR_SYS_PROPERTY_NAME = "HSSF.testdata.path";
+
+	private static boolean _isInitialised;
+	private static File _resolvedDataDir;
+	/** <code>true</code> if standard system propery is not set, 
+	 * but the data is available on the test runtime classpath */
+	private static boolean _sampleDataIsAvaliableOnClassPath;
+
+	/**
+	 * Opens a sample file from the standard HSSF test data directory
+	 * 
+	 * @return an open <tt>InputStream</tt> for the specified sample file
+	 */
+	public static InputStream openSampleFileStream(String sampleFileName) {
+		
+		if(!_isInitialised) {
+			try {
+				initialise();
+			} finally {
+				_isInitialised = true;
+			}
+		}
+		if (_sampleDataIsAvaliableOnClassPath) {
+			InputStream result = openClasspathResource(sampleFileName);
+			if(result == null) {
+				throw new RuntimeException("specified test sample file '" + sampleFileName 
+						+ "' not found on the classpath");
+			}
+//			System.out.println("opening cp: " + sampleFileName);
+			// wrap to avoid temp warning method about auto-closing input stream
+			return new NonSeekableInputStream(result);
+		}
+		if (_resolvedDataDir == null) {
+			throw new RuntimeException("Must set system property '"
+					+ TEST_DATA_DIR_SYS_PROPERTY_NAME
+					+ "' properly before running tests");
+		}
+		
+		File f = new File(_resolvedDataDir, sampleFileName);
+		if (!f.exists()) {
+			throw new RuntimeException("Sample file '" + sampleFileName
+					+ "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() + "'");
+		}
+//		System.out.println("opening " + f.getAbsolutePath());
+		try {
+			return new FileInputStream(f);
+		} catch (FileNotFoundException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	private static void initialise() {
+		String dataDirName = System.getProperty(TEST_DATA_DIR_SYS_PROPERTY_NAME);
+        if (dataDirName == null) {
+        	// check to see if we can just get the resources from the classpath
+        	InputStream is = openClasspathResource("SampleSS.xls"); 
+        	if(is != null) {
+        		try {
+					is.close(); // be nice
+				} catch (IOException e) {
+					throw new RuntimeException(e);
+				}
+        		_sampleDataIsAvaliableOnClassPath = true;
+        		return;
+        	}
+        	
+        	
+        	throw new RuntimeException("Must set system property '"
+        			+ TEST_DATA_DIR_SYS_PROPERTY_NAME
+        			+ "' before running tests");
+        }
+        File dataDir = new File(dataDirName);
+        if (!dataDir.exists()) {
+        	throw new RuntimeException("Data dir '" + dataDirName
+        			+ "' specified by system property '"
+        			+ TEST_DATA_DIR_SYS_PROPERTY_NAME + "' does not exist");
+        }
+        // convert to canonical file, to make any subsequent error messages clearer.
+        try {
+			_resolvedDataDir = dataDir.getCanonicalFile();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * Opens a test sample file from the 'data' sub-package of this class's package. 
+	 * @return <code>null</code> if the sample file is not deployed on the classpath.
+	 */
+	private static InputStream openClasspathResource(String sampleFileName) {
+		return HSSFTestDataSamples.class.getResourceAsStream("data/" + sampleFileName);
+	}
+	
+	private static final class NonSeekableInputStream extends InputStream {
+
+		private final InputStream _is;
+
+		public NonSeekableInputStream(InputStream is) {
+			_is = is;
+		}
+
+		public int read() throws IOException {
+			return _is.read();
+		}
+		public int read(byte[] b, int off, int len) throws IOException {
+			return _is.read(b, off, len);
+		}
+		public boolean markSupported() {
+			return false;
+		}
+		public void close() throws IOException {
+			_is.close();
+		}
+	}
+
+	public static HSSFWorkbook openSampleWorkbook(String sampleFileName) {
+		try {
+			return new HSSFWorkbook(openSampleFileStream(sampleFileName));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+	/**
+	 * Writes a spreadsheet to a <tt>ByteArrayOutputStream</tt> and reads it back
+	 * from a <tt>ByteArrayInputStream</tt>.<p/>
+	 * Useful for verifying that the serialisation round trip
+	 */
+	public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
+		
+		try {
+			ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+			original.write(baos);
+			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+			return new HSSFWorkbook(bais);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+}

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java Sun Apr  6 20:02:03 2008
@@ -16,109 +16,108 @@
 ==================================================================== */
 
 package org.apache.poi.hssf.eventusermodel;
-import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
-import org.apache.poi.hssf.eventusermodel.HSSFListener;
-
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.record.ContinueRecord;
 import org.apache.poi.hssf.record.DVALRecord;
 import org.apache.poi.hssf.record.DVRecord;
 import org.apache.poi.hssf.record.EOFRecord;
 import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.ContinueRecord;
 import org.apache.poi.hssf.record.SelectionRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-
-import junit.framework.TestCase;
-
-public class TestHSSFEventFactory extends TestCase {
-	private String dirname;
+/**
+ * 
+ */
+public final class TestHSSFEventFactory extends TestCase {
 	
-	public TestHSSFEventFactory() {
-		dirname = System.getProperty("HSSF.testdata.path");
+	private static final InputStream openSample(String sampleFileName) {
+		return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
 	}
 
 	public void testWithMissingRecords() throws Exception {
-		File f = new File(dirname + "/SimpleWithSkip.xls");
 
 		HSSFRequest req = new HSSFRequest();
 		MockHSSFListener mockListen = new MockHSSFListener();
 		req.addListenerForAllRecords(mockListen);
 		
-		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f));
+		POIFSFileSystem fs = new POIFSFileSystem(openSample("SimpleWithSkip.xls"));
 		HSSFEventFactory factory = new HSSFEventFactory();
 		factory.processWorkbookEvents(req, fs);
 
+		Record[] recs = mockListen.getRecords();
 		// Check we got the records
-		System.out.println("Processed, found " + mockListen.records.size() + " records");
-		assertTrue( mockListen.records.size() > 100 );
+		assertTrue( recs.length > 100 );
 		
 		// Check that the last few records are as we expect
 		// (Makes sure we don't accidently skip the end ones)
-		int numRec = mockListen.records.size();
-		assertEquals(WindowTwoRecord.class, mockListen.records.get(numRec-3).getClass());
-		assertEquals(SelectionRecord.class, mockListen.records.get(numRec-2).getClass());
-		assertEquals(EOFRecord.class,       mockListen.records.get(numRec-1).getClass());
+		int numRec = recs.length;
+		assertEquals(WindowTwoRecord.class, recs[numRec-3].getClass());
+		assertEquals(SelectionRecord.class, recs[numRec-2].getClass());
+		assertEquals(EOFRecord.class,	   recs[numRec-1].getClass());
 	}
 
 	public void testWithCrazyContinueRecords() throws Exception {
 		// Some files have crazy ordering of their continue records
 		// Check that we don't break on them (bug #42844)
-
-		File f = new File(dirname + "/ContinueRecordProblem.xls");
 		
 		HSSFRequest req = new HSSFRequest();
 		MockHSSFListener mockListen = new MockHSSFListener();
 		req.addListenerForAllRecords(mockListen);
 		
-		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f));
+		POIFSFileSystem fs = new POIFSFileSystem(openSample("ContinueRecordProblem.xls"));
 		HSSFEventFactory factory = new HSSFEventFactory();
 		factory.processWorkbookEvents(req, fs);
 
+		Record[] recs = mockListen.getRecords();
 		// Check we got the records
-		System.out.println("Processed, found " + mockListen.records.size() + " records");
-		assertTrue( mockListen.records.size() > 100 );
+		assertTrue( recs.length > 100 );
 
 		// And none of them are continue ones
-		Record[] r = (Record[])mockListen.records.toArray( 
-							new Record[mockListen.records.size()] );
-		for(int i=0; i<r.length; i++) {
-			assertFalse( r[i] instanceof ContinueRecord );
+		for(int i=0; i<recs.length; i++) {
+			assertFalse( recs[i] instanceof ContinueRecord );
 		}
 		
 		// Check that the last few records are as we expect
 		// (Makes sure we don't accidently skip the end ones)
-		int numRec = mockListen.records.size();
-		assertEquals(DVALRecord.class, mockListen.records.get(numRec-3).getClass());
-		assertEquals(DVRecord.class, mockListen.records.get(numRec-2).getClass());
-		assertEquals(EOFRecord.class,       mockListen.records.get(numRec-1).getClass());
+		int numRec = recs.length;
+		assertEquals(DVALRecord.class, recs[numRec-3].getClass());
+		assertEquals(DVRecord.class,  recs[numRec-2].getClass());
+		assertEquals(EOFRecord.class, recs[numRec-1].getClass());
 	}
 
-    /**
-     * Unknown records can be continued.
-     * Check that HSSFEventFactory doesn't break on them.
-     * (the test file was provided in a reopen of bug #42844)
-     */
-    public void testUnknownContinueRecords() throws Exception {
-         File f = new File(dirname + "/42844.xls");
-
-        HSSFRequest req = new HSSFRequest();
-        MockHSSFListener mockListen = new MockHSSFListener();
-        req.addListenerForAllRecords(mockListen);
-
-        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f));
-        HSSFEventFactory factory = new HSSFEventFactory();
-        factory.processWorkbookEvents(req, fs);
+	/**
+	 * Unknown records can be continued.
+	 * Check that HSSFEventFactory doesn't break on them.
+	 * (the test file was provided in a reopen of bug #42844)
+	 */
+	public void testUnknownContinueRecords() throws Exception {
 
-        assertTrue("no errors while processing the file", true);
-    }
+		HSSFRequest req = new HSSFRequest();
+		MockHSSFListener mockListen = new MockHSSFListener();
+		req.addListenerForAllRecords(mockListen);
+
+		POIFSFileSystem fs = new POIFSFileSystem(openSample("42844.xls"));
+		HSSFEventFactory factory = new HSSFEventFactory();
+		factory.processWorkbookEvents(req, fs);
+
+		assertTrue("no errors while processing the file", true);
+	}
 
 	private static class MockHSSFListener implements HSSFListener {
-		private MockHSSFListener() {}
-		private ArrayList records = new ArrayList();
+		private final List records = new ArrayList();
+
+		public MockHSSFListener() {}
+		public Record[] getRecords() {
+			Record[] result = new Record[records.size()];
+			records.toArray(result);
+			return result;
+		}
 
 		public void processRecord(Record record) {
 			records.add(record);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java Sun Apr  6 20:02:03 2008
@@ -19,11 +19,13 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord;
 import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
 import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord;
@@ -39,8 +41,6 @@
 	private Record[] r;
 
 	public void setUp() {
-		String dirname = System.getProperty("HSSF.testdata.path");
-		File f = new File(dirname + "/MissingBits.xls");
 
 		HSSFRequest req = new HSSFRequest();
 		MockHSSFListener mockListen = new MockHSSFListener();
@@ -49,7 +49,8 @@
 		
 		HSSFEventFactory factory = new HSSFEventFactory();
 		try {
-			POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f));
+			InputStream is = HSSFTestDataSamples.openSampleFileStream("MissingBits.xls");
+			POIFSFileSystem fs = new POIFSFileSystem(is);
 			factory.processWorkbookEvents(req, fs);
 		} catch (IOException e) {
 			throw new RuntimeException(e);

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=645348&r1=645347&r2=645348&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 Apr  6 20:02:03 2008
@@ -14,21 +14,36 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.hssf.extractor;
 
-import java.io.File;
-import java.io.FileInputStream;
+package org.apache.poi.hssf.extractor;
 
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import java.io.IOException;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 
-public class TestExcelExtractor extends TestCase {
-	public void testSimple() throws Exception {
-		String path = System.getProperty("HSSF.testdata.path");
-		FileInputStream fin = new FileInputStream(path + File.separator + "Simple.xls");
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+/**
+ * 
+ */
+public final class TestExcelExtractor extends TestCase {
+
+	private static final ExcelExtractor createExtractor(String sampleFileName) {
+		
+		InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+		
+		try {
+			return new ExcelExtractor(new POIFSFileSystem(is));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+	
+	
+	public void testSimple() {
 		
-		ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin));
+		ExcelExtractor extractor = createExtractor("Simple.xls");
 		
 		assertEquals("Sheet1\nreplaceMe\nSheet2\nSheet3\n", extractor.getText());
 		
@@ -37,11 +52,9 @@
 		assertEquals("replaceMe\n", extractor.getText());
 	}
 	
-	public void testNumericFormula() throws Exception {
-		String path = System.getProperty("HSSF.testdata.path");
-		FileInputStream fin = new FileInputStream(path + File.separator + "sumifformula.xls");
+	public void testNumericFormula() {
 		
-		ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin));
+		ExcelExtractor extractor = createExtractor("sumifformula.xls");
 		
 		assertEquals(
 				"Sheet1\n" +
@@ -68,11 +81,9 @@
 		);
 	}
 	
-	public void testwithContinueRecords() throws Exception {
-		String path = System.getProperty("HSSF.testdata.path");
-		FileInputStream fin = new FileInputStream(path + File.separator + "StringContinueRecords.xls");
+	public void testwithContinueRecords() {
 		
-		ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin));
+		ExcelExtractor extractor = createExtractor("StringContinueRecords.xls");
 		
 		extractor.getText();
 		
@@ -82,11 +93,9 @@
 		assertTrue(extractor.getText().length() > 40960);
 	}
 	
-	public void testStringConcat() throws Exception {
-		String path = System.getProperty("HSSF.testdata.path");
-		FileInputStream fin = new FileInputStream(path + File.separator + "SimpleWithFormula.xls");
+	public void testStringConcat() {
 		
-		ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin));
+		ExcelExtractor extractor = createExtractor("SimpleWithFormula.xls");
 		
 		// Comes out as NaN if treated as a number
 		// And as XYZ if treated as a string
@@ -97,11 +106,9 @@
 		assertEquals("Sheet1\nreplaceme\nreplaceme\nCONCATENATE(A1,A2)\nSheet2\nSheet3\n", extractor.getText());
 	}
 	
-	public void testStringFormula() throws Exception {
-		String path = System.getProperty("HSSF.testdata.path");
-		FileInputStream fin = new FileInputStream(path + File.separator + "StringFormulas.xls");
+	public void testStringFormula() {
 		
-		ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin));
+		ExcelExtractor extractor = createExtractor("StringFormulas.xls");
 		
 		// Comes out as NaN if treated as a number
 		// And as XYZ if treated as a string

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java Sun Apr  6 20:02:03 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,36 +14,28 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
-import java.io.File;
-import java.io.FileInputStream;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import java.io.InputStream;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
-public class TestBOFRecord extends TestCase
-{
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
-
-    public TestBOFRecord()
-    {
-        super();
-        _test_file_path = System.getProperty( _test_file_path_property ) +
-        	File.separator + "bug_42794.xls";
-    }
-
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+/**
+ * 
+ */
+public final class TestBOFRecord extends TestCase {
     public void testBOFRecord() throws Exception {
-    	POIFSFileSystem fs = new POIFSFileSystem(
-    			new FileInputStream(_test_file_path)
-    	);
-    	
-    	// This used to throw an error before
-    	HSSFWorkbook hssf = new HSSFWorkbook(fs);
+        InputStream is = HSSFTestDataSamples.openSampleFileStream("bug_42794.xls");
+        
+        // This used to throw an error before
+        try {
+            new HSSFWorkbook(is);
+        } catch (ArrayIndexOutOfBoundsException e) {
+            throw new AssertionFailedError("Identified bug 42794");
+        }
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java Sun Apr  6 20:02:03 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,65 +14,57 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
 import org.apache.poi.hssf.eventusermodel.HSSFListener;
 import org.apache.poi.hssf.eventusermodel.HSSFRequest;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-
-import junit.framework.TestCase;
-
-public class TestChartTitleFormatRecord extends TestCase
-{
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
-
-    public TestChartTitleFormatRecord()
-    {
-        super();
-        _test_file_path = System.getProperty( _test_file_path_property ) +
-        	File.separator + "WithFormattedGraphTitle.xls";
-    }
-
-    public void testRecord() throws Exception {
-    	POIFSFileSystem fs = new POIFSFileSystem(
-    			new FileInputStream(_test_file_path)
-    	);
-    	
-    	// Check we can open the file via usermodel
-    	HSSFWorkbook hssf = new HSSFWorkbook(fs);
-    	
-    	// Now process it through eventusermodel, and
-    	//  look out for the title records
-    	ChartTitleFormatRecordGrabber grabber =
-    		new ChartTitleFormatRecordGrabber();
-    	InputStream din = fs.createDocumentInputStream("Workbook");
-        HSSFRequest req = new HSSFRequest();
-        req.addListenerForAllRecords(grabber);
-        HSSFEventFactory factory = new HSSFEventFactory();
-        factory.processEvents(req, din);
-        din.close();
-        
-        // Should've found one
-        assertEquals(1, grabber.chartTitleFormatRecords.size());
-        // And it should be of something interesting
-        ChartTitleFormatRecord r =
-        	(ChartTitleFormatRecord)grabber.chartTitleFormatRecords.get(0);
-        assertEquals(3, r.getFormatCount());
-    }
-    
-    public static class ChartTitleFormatRecordGrabber implements HSSFListener {
-    	private ArrayList chartTitleFormatRecords = new ArrayList();
+/**
+ * 
+ */
+public final class TestChartTitleFormatRecord extends TestCase {
+
+	public void testRecord() throws Exception {
+		POIFSFileSystem fs = new POIFSFileSystem(
+				HSSFTestDataSamples.openSampleFileStream("WithFormattedGraphTitle.xls"));
+		
+		// Check we can open the file via usermodel
+		HSSFWorkbook hssf = new HSSFWorkbook(fs);
+		
+		// Now process it through eventusermodel, and
+		//  look out for the title records
+		ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
+		InputStream din = fs.createDocumentInputStream("Workbook");
+		HSSFRequest req = new HSSFRequest();
+		req.addListenerForAllRecords(grabber);
+		HSSFEventFactory factory = new HSSFEventFactory();
+		factory.processEvents(req, din);
+		din.close();
+		
+		// Should've found one
+		assertEquals(1, grabber.chartTitleFormatRecords.size());
+		// And it should be of something interesting
+		ChartTitleFormatRecord r =
+			(ChartTitleFormatRecord)grabber.chartTitleFormatRecords.get(0);
+		assertEquals(3, r.getFormatCount());
+	}
+	
+	private static final class ChartTitleFormatRecordGrabber implements HSSFListener {
+		private final List chartTitleFormatRecords;
+		
+		public ChartTitleFormatRecordGrabber() {
+			chartTitleFormatRecords = new ArrayList();
+		}
 
 		public void processRecord(Record record) {
 			if(record instanceof ChartTitleFormatRecord) {
@@ -82,6 +73,6 @@
 				);
 			}
 		}
-    	
-    }
+		
+	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java Sun Apr  6 20:02:03 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,8 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
-
 
 package org.apache.poi.hssf.record;
 
@@ -39,36 +36,29 @@
  *
  * @author Andrew C. Oliver 
  */
-public class TestFormulaRecord
-        extends TestCase
-{
-
-    public TestFormulaRecord(String name)
-    {
-        super(name);
-    }
-
-    public void testCreateFormulaRecord () {
-        FormulaRecord record = new FormulaRecord();
-        record.setColumn((short)0);
-        //record.setRow((short)1);
-        record.setRow(1);
-        record.setXFIndex((short)4);
-        
-        assertEquals(record.getColumn(),(short)0);
-        //assertEquals(record.getRow(),(short)1);
-        assertEquals((short)record.getRow(),(short)1);
-        assertEquals(record.getXFIndex(),(short)4);
-    }
-    
-    /**
-     * Make sure a NAN value is preserved
-     * This formula record is a representation of =1/0 at row 0, column 0 
-     */
-    public void testCheckNanPreserve() {
-    	byte[] formulaByte = new byte[29];
-    	for (int i = 0; i < formulaByte.length; i++) formulaByte[i] = (byte)0;
-    	formulaByte[4] = (byte)0x0F;
+public final class TestFormulaRecord extends TestCase {
+
+	public void testCreateFormulaRecord () {
+		FormulaRecord record = new FormulaRecord();
+		record.setColumn((short)0);
+		//record.setRow((short)1);
+		record.setRow(1);
+		record.setXFIndex((short)4);
+		
+		assertEquals(record.getColumn(),(short)0);
+		//assertEquals(record.getRow(),(short)1);
+		assertEquals((short)record.getRow(),(short)1);
+		assertEquals(record.getXFIndex(),(short)4);
+	}
+	
+	/**
+	 * Make sure a NAN value is preserved
+	 * This formula record is a representation of =1/0 at row 0, column 0 
+	 */
+	public void testCheckNanPreserve() {
+		byte[] formulaByte = new byte[29];
+		for (int i = 0; i < formulaByte.length; i++) formulaByte[i] = (byte)0;
+		formulaByte[4] = (byte)0x0F;
 		formulaByte[6] = (byte)0x02;
 		formulaByte[8] = (byte)0x07;
 		formulaByte[12] = (byte)0xFF;
@@ -80,7 +70,7 @@
 		formulaByte[23] = (byte)0x01;
 		formulaByte[25] = (byte)0x1E;
 		formulaByte[28] = (byte)0x06;
-    	
+		
 		FormulaRecord record = new FormulaRecord(new TestcaseRecordInputStream(FormulaRecord.sid, (short)29, formulaByte));
 		assertEquals("Row", 0, record.getRow());
 		assertEquals("Column", 0, record.getColumn());		
@@ -92,19 +82,18 @@
 		for (int i = 5; i < 13;i++) {
 			assertEquals("FormulaByte NaN doesn't match", formulaByte[i], output[i+4]);
 		}
+	}
+	
+	/**
+	 * Tests to see if the shared formula cells properly reserialize the expPtg
+	 *
+	 */
+	public void testExpFormula() {
+		byte[] formulaByte = new byte[27];
 		
-    }
-    
-    /**
-     * Tests to see if the shared formula cells properly reserialize the expPtg
-     *
-     */
-    public void testExpFormula() {
-    	byte[] formulaByte = new byte[27];
-    	
 		for (int i = 0; i < formulaByte.length; i++) formulaByte[i] = (byte)0;
-    	
-    	formulaByte[4] =(byte)0x0F;
+		
+		formulaByte[4] =(byte)0x0F;
 		formulaByte[14]=(byte)0x08;
 		formulaByte[18]=(byte)0xE0;
 		formulaByte[19]=(byte)0xFD;
@@ -115,19 +104,19 @@
 		assertEquals("Column", 0, record.getColumn());
 		byte[] output = record.serialize();
 		assertEquals("Output size", 31, output.length); //includes sid+recordlength
-    	assertEquals("Offset 22", 1, output[26]);
-    }
-    
-    public void testWithConcat()  throws Exception {
-    	// =CHOOSE(2,A2,A3,A4)
-    	byte[] data = new byte[] {
-    			6, 0, 68, 0,
-    			1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57,
+		assertEquals("Offset 22", 1, output[26]);
+	}
+	
+	public void testWithConcat()  throws Exception {
+		// =CHOOSE(2,A2,A3,A4)
+		byte[] data = new byte[] {
+				6, 0, 68, 0,
+				1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57,
 				64, 0, 0, 12, 0, 12, -4, 46, 0, 
-				30, 2, 0,    // Int - 2
+				30, 2, 0,	// Int - 2
 				25, 4, 3, 0, // Attr
-				8, 0,        // Concat 
-				17, 0,       // Range 
+				8, 0,		// Concat 
+				17, 0,	   // Range 
 				26, 0, 35, 0, // Bit like an attr
 				36, 1, 0, 0, -64, // Ref - A2
 				25, 8, 21, 0, // Attr
@@ -136,43 +125,35 @@
 				36, 3, 0, 0, -64, // Ref - A4
 				25, 8, 3, 0,  // Attr 
 				66, 4, 100, 0 // CHOOSE
-    	};
-    	RecordInputStream inp = new RecordInputStream(
-    			new ByteArrayInputStream(data)
-    	);
-    	inp.nextRecord();
-    	
-    	FormulaRecord fr = new FormulaRecord(inp);
-    	
-    	assertEquals(14, fr.getNumberOfExpressionTokens());
-    	assertEquals(IntPtg.class,       fr.getParsedExpression().get(0).getClass());
-    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(1).getClass());
-    	assertEquals(ConcatPtg.class,    fr.getParsedExpression().get(2).getClass());
-    	assertEquals(UnknownPtg.class,   fr.getParsedExpression().get(3).getClass());
-    	assertEquals(RangePtg.class,     fr.getParsedExpression().get(4).getClass());
-    	assertEquals(UnknownPtg.class,   fr.getParsedExpression().get(5).getClass());
-    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(6).getClass());
-    	assertEquals(ReferencePtg.class, fr.getParsedExpression().get(7).getClass());
-    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(8).getClass());
-    	assertEquals(ReferencePtg.class, fr.getParsedExpression().get(9).getClass());
-    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(10).getClass());
-    	assertEquals(ReferencePtg.class, fr.getParsedExpression().get(11).getClass());
-    	assertEquals(AttrPtg.class,      fr.getParsedExpression().get(12).getClass());
-    	assertEquals(FuncVarPtg.class,   fr.getParsedExpression().get(13).getClass());
-    	
-    	FuncVarPtg choose = (FuncVarPtg)fr.getParsedExpression().get(13);
-    	assertEquals("CHOOSE", choose.getName());
-    }
-    
-    
-    public static void main(String [] ignored_args)
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        System.out
-            .println("Testing org.apache.poi.hssf.record.FormulaRecord");
-        junit.textui.TestRunner.run(TestFormulaRecord.class);
-    }
-    
-    
+		};
+		RecordInputStream inp = new RecordInputStream(
+				new ByteArrayInputStream(data)
+		);
+		inp.nextRecord();
+		
+		FormulaRecord fr = new FormulaRecord(inp);
+		
+		assertEquals(14, fr.getNumberOfExpressionTokens());
+		assertEquals(IntPtg.class,	   fr.getParsedExpression().get(0).getClass());
+		assertEquals(AttrPtg.class,	  fr.getParsedExpression().get(1).getClass());
+		assertEquals(ConcatPtg.class,	fr.getParsedExpression().get(2).getClass());
+		assertEquals(UnknownPtg.class,   fr.getParsedExpression().get(3).getClass());
+		assertEquals(RangePtg.class,	 fr.getParsedExpression().get(4).getClass());
+		assertEquals(UnknownPtg.class,   fr.getParsedExpression().get(5).getClass());
+		assertEquals(AttrPtg.class,	  fr.getParsedExpression().get(6).getClass());
+		assertEquals(ReferencePtg.class, fr.getParsedExpression().get(7).getClass());
+		assertEquals(AttrPtg.class,	  fr.getParsedExpression().get(8).getClass());
+		assertEquals(ReferencePtg.class, fr.getParsedExpression().get(9).getClass());
+		assertEquals(AttrPtg.class,	  fr.getParsedExpression().get(10).getClass());
+		assertEquals(ReferencePtg.class, fr.getParsedExpression().get(11).getClass());
+		assertEquals(AttrPtg.class,	  fr.getParsedExpression().get(12).getClass());
+		assertEquals(FuncVarPtg.class,   fr.getParsedExpression().get(13).getClass());
+		
+		FuncVarPtg choose = (FuncVarPtg)fr.getParsedExpression().get(13);
+		assertEquals("CHOOSE", choose.getName());
+	}
+	
+	public static void main(String [] ignored_args) {
+		junit.textui.TestRunner.run(TestFormulaRecord.class);
+	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java Sun Apr  6 20:02:03 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
@@ -34,20 +32,8 @@
  * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Csaba Nagy (ncsaba at yahoo dot com)
  */
+public final class TestRecordFactory extends TestCase {
 
-public class TestRecordFactory
-    extends TestCase
-{
-
-    /**
-     * Creates new TestRecordFactory
-     * @param testCaseName
-     */
-
-    public TestRecordFactory(String testCaseName)
-    {
-        super(testCaseName);
-    }
 
     /**
      * TEST NAME:  Test Basic Record Construction <P>
@@ -57,13 +43,9 @@
      * FAILURE:    The wrong records are creates or contain the wrong values <P>
      *
      */
-
-    public void testBasicRecordConstruction()
-        throws Exception
-    {
+    public void testBasicRecordConstruction() {
         short    recType = BOFRecord.sid;
-        byte[]   data    = new byte[]
-        {
+        byte[]   data    = {
             0, 6, 5, 0, -2, 28, -51, 7, -55, 64, 0, 0, 6, 1, 0, 0
         };
         short    size    = 16;
@@ -106,13 +88,9 @@
      * FAILURE:    The wrong records are created or contain the wrong values <P>
      *
      */
-
-    public void testSpecial()
-        throws Exception
-    {
+    public void testSpecial() {
         short    recType = RKRecord.sid;
-        byte[]   data    = new byte[]
-        {
+        byte[]   data    = {
             0, 0, 0, 0, 21, 0, 0, 0, 0, 0
         };
         short    size    = 10;
@@ -138,10 +116,8 @@
      * FAILURE:    The wrong records are created or contain the wrong values <P>
      *
      */
-    public void testContinuedUnknownRecord()
-    {
-        byte[]   data    = new byte[]
-        {
+    public void testContinuedUnknownRecord() {
+        byte[]   data    = {
             0, -1, 0, 0, // an unknown record with 0 length
             0x3C , 0, 3, 0, 1, 2, 3, // a continuation record with 3 bytes of data
             0x3C , 0, 1, 0, 4 // one more continuation record with 1 byte of data
@@ -178,7 +154,7 @@
      */
     public void testMixedContinue() throws Exception {
         /**
-         *  Taken from a real file $HSSF.testdata.path/39512.xls. See Bug 39512 for details.
+         *  Taken from a real test sample file 39512.xls. See Bug 39512 for details.
          */
         String dump =
                 //OBJ
@@ -228,10 +204,7 @@
         assertTrue(Arrays.equals(data, ser));
     }
 
-    public static void main(String [] ignored_args)
-    {
-        System.out
-            .println("Testing org.apache.poi.hssf.record.TestRecordFactory");
+    public static void main(String [] ignored_args) {
         junit.textui.TestRunner.run(TestRecordFactory.class);
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java Sun Apr  6 20:02:03 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,51 +14,47 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
-import org.apache.poi.util.HexRead;
-import org.apache.poi.util.IntMapper;
-import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-
-import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.util.HexRead;
+import org.apache.poi.util.IntMapper;
+
 /**
  * Exercise the SSTDeserializer class.
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public class TestSSTDeserializer
-        extends TestCase
-{
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
+public final class TestSSTDeserializer extends TestCase {
 
-    public TestSSTDeserializer( String s )
-    {
-        super( s );
-    }
-
-    protected void setUp() throws Exception
-    {
-        _test_file_path = System.getProperty( _test_file_path_property );
-    }
 
     private byte[] joinArray(byte[] array1, byte[] array2) {
-      byte[] bigArray = new byte[array1.length+array2.length];
-      System.arraycopy(array1, 0, bigArray, 0, array1.length);
-      System.arraycopy(array2, 0, bigArray, array1.length, array2.length);
-      return bigArray;    
+        byte[] bigArray = new byte[array1.length + array2.length];
+        System.arraycopy(array1, 0, bigArray, 0, array1.length);
+        System.arraycopy(array2, 0, bigArray, array1.length, array2.length);
+        return bigArray;
+    }
+    
+    private static byte[] readSampleHexData(String sampleFileName, String sectionName) {
+        InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+        try {
+            return HexRead.readData(is, sectionName);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public void testSpanRichTextToPlainText()
             throws Exception
     {
-      byte[] header = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt", "header" );
-        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt", "continue1" );
+      byte[] header = readSampleHexData("richtextdata.txt", "header" );
+        byte[] continueBytes = readSampleHexData("richtextdata.txt", "continue1" );
       continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
       TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
       
@@ -74,8 +69,8 @@
     public void testContinuationWithNoOverlap()
             throws Exception
     {
-        byte[] header = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt", "header" );
-        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt", "continue1" );
+        byte[] header = readSampleHexData("evencontinuation.txt", "header" );
+        byte[] continueBytes = readSampleHexData("evencontinuation.txt", "continue1" );
         continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
         TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
 
@@ -93,10 +88,10 @@
     public void testStringAcross2Continuations()
             throws Exception
     {
-        byte[] header = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "header" );
-        byte[] continue1 = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "continue1" );
+        byte[] header = readSampleHexData("stringacross2continuations.txt", "header" );
+        byte[] continue1 = readSampleHexData("stringacross2continuations.txt", "continue1" );
         continue1 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue1.length, continue1);
-        byte[] continue2 = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "continue2" );
+        byte[] continue2 = readSampleHexData("stringacross2continuations.txt", "continue2" );
         continue2 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue2.length, continue2);
         
         byte[] bytes = joinArray(header, continue1);
@@ -111,11 +106,9 @@
         assertEquals( "At a dinner partyAt a dinner party", strings.get( 1 ) + "" );
     }
 
-    public void testExtendedStrings()
-            throws Exception
-    {
-        byte[] header = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "rich-header" );
-        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "rich-continue1" );
+    public void testExtendedStrings() {
+        byte[] header = readSampleHexData("extendedtextstrings.txt", "rich-header" );
+        byte[] continueBytes = readSampleHexData("extendedtextstrings.txt", "rich-continue1" );
         continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
         TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
         
@@ -126,8 +119,8 @@
         assertEquals( "At a dinner party orAt At At ", strings.get( 0  ) + "" );
 
 
-        header = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "norich-header" );
-        continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "norich-continue1" );
+        header = readSampleHexData("extendedtextstrings.txt", "norich-header" );
+        continueBytes = readSampleHexData("extendedtextstrings.txt", "norich-continue1" );
         continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
         in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
         
@@ -136,7 +129,5 @@
         deserializer.manufactureStrings( 1, in);
 
         assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );
-
     }
-
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java Sun Apr  6 20:02:03 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,54 +14,33 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Iterator;
+
 import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.util.HexRead;
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.TempFile;
-
-import java.io.*;
-import java.util.Arrays;
-import java.util.Iterator;
 
 /**
  * @author Marc Johnson (mjohnson at apache dot org)
  * @author Glen Stampoultzis (glens at apache.org)
  */
 
-public class TestSSTRecord
-        extends TestCase
-{
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
-
-    /**
-     * Creates new TestSSTRecord
-     *
-     * @param name
-     */
-
-    public TestSSTRecord( String name )
-    {
-        super( name );
-        _test_file_path = System.getProperty( _test_file_path_property );
-    }
+public final class TestSSTRecord extends TestCase {
 
     /**
      * test processContinueRecord
-     *
-     * @exception IOException
      */
-
-    public void testProcessContinueRecord()
-            throws IOException
-    {
+    public void testProcessContinueRecord() {
 //jmh        byte[] testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord" );
 //jmh        byte[] input = new byte[testdata.length - 4];
 //jmh
@@ -182,9 +160,7 @@
      * @exception IOException
      */
 
-    public void testHugeStrings()
-            throws IOException
-    {
+    public void testHugeStrings() {
         SSTRecord record = new SSTRecord();
         byte[][] bstrings =
                 {
@@ -265,12 +241,8 @@
 
     /**
      * test SSTRecord boundary conditions
-     *
-     * @exception IOException
      */
-    public void testSSTRecordBug()
-            throws IOException
-    {
+    public void testSSTRecordBug() {
         // create an SSTRecord and write a certain pattern of strings
         // to it ... then serialize it and verify the content
         SSTRecord record = new SSTRecord();
@@ -350,38 +322,6 @@
     }
 
     /**
-     * test reader constructor
-     *
-     * @exception IOException
-     */
-
-    public void testReaderConstructor()
-            throws IOException
-    {
-/* JMH this test case data is crap because it does not contain a full record. Ie the last string
-       is missing a record
-
-        byte[] testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord" );
-//        byte[] input = new byte[testdata.length - 4];
-
-        System.arraycopy( testdata, 4, input, 0, input.length );
-        SSTRecord record = new SSTRecord( new TestcaseRecordInputStream(LittleEndian.getShort( testdata, 0 ),
-                LittleEndian.getShort( testdata, 2 ),
-                input) );
-
-        assertEquals( 1464, record.getNumStrings() );
-        assertEquals( 688, record.getNumUniqueStrings() );
-        assertEquals( 492, record.countStrings() );
-        assertEquals( 1, record.getDeserializer().getContinuationExpectedChars() );
-        assertEquals( "Consolidated B-24J Liberator The Dragon & His Tai",
-                record.getDeserializer().getUnfinishedString() );
-//        assertEquals( 52, record.getDeserializer().getTotalLength() );
-//        assertEquals( 3, record.getDeserializer().getStringDataOffset() );
-        assertTrue( !record.getDeserializer().isWideChar() );
- */
-    }
-
-    /**
      * test simple constructor
      */
 
@@ -413,9 +353,7 @@
      * @param ignored_args
      */
 
-    public static void main( String[] ignored_args )
-    {
-        System.out.println( "Testing hssf.record.SSTRecord functionality" );
+    public static void main( String[] ignored_args ) {
         junit.textui.TestRunner.run( TestSSTRecord.class );
     }
 
@@ -425,25 +363,16 @@
     public void testReadWriteDuplicatedRichText1()
             throws Exception
     {
-        File file = new File( _test_file_path + File.separator + "duprich1.xls" );
-        InputStream stream = new FileInputStream( file );
-        HSSFWorkbook wb = new HSSFWorkbook( stream );
-        stream.close();
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls");
         HSSFSheet sheet = wb.getSheetAt( 1 );
         assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell( (short) 8 ).getStringCellValue() );
         assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell( (short) 8 ).getStringCellValue() );
 
-        file = TempFile.createTempFile( "testout", "xls" );
-        FileOutputStream outStream = new FileOutputStream( file );
-        wb.write( outStream );
-        outStream.close();
-        file.delete();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        wb.write( baos );
 
         // test the second file.
-        file = new File( _test_file_path + File.separator + "duprich2.xls" );
-        stream = new FileInputStream( file );
-        wb = new HSSFWorkbook( stream );
-        stream.close();
+        wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls");
         sheet = wb.getSheetAt( 0 );
         int row = 0;
         assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
@@ -453,12 +382,6 @@
         assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
         assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
 
-//        file = new File("/tryme.xls");
-        file = TempFile.createTempFile( "testout", ".xls" );
-        outStream = new FileOutputStream( file );
-        wb.write( outStream );
-        outStream.close();
-        file.delete();
+        wb.write( baos );
     }
-
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java Sun Apr  6 20:02:03 2008
@@ -14,39 +14,23 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+/**
+ * 
+ */
+public final class TestUnicodeNameRecord extends TestCase {
 
-public class TestUnicodeNameRecord extends TestCase {
-    private String _test_file_path;
-    private static final String _test_file_path_property = "HSSF.testdata.path";
-
-    public TestUnicodeNameRecord()
-    {
-        super();
-        _test_file_path = System.getProperty( _test_file_path_property ) +
-        	File.separator + "unicodeNameRecord.xls";
-    }
-
-	public void testReadBook() throws IOException {
-    	POIFSFileSystem fs = new POIFSFileSystem(
-    			new FileInputStream(_test_file_path)
-    	);
+	public void testReadBook() {
 
 		// This bit used to crash
-    	HSSFWorkbook book = new HSSFWorkbook(fs);
-    	HSSFSheet sheet = book.getSheetAt(0);
+		HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("unicodeNameRecord.xls");
+		book.getSheetAt(0);
 	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java Sun Apr  6 20:02:03 2008
@@ -29,6 +29,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.BlankRecord;
 import org.apache.poi.hssf.record.FormulaRecord;
 import org.apache.poi.hssf.record.Record;
@@ -250,22 +251,14 @@
      * 
      */
     public void testSpuriousSharedFormulaFlag() {
-        File dataDir = new File(System.getProperty("HSSF.testdata.path"));
-        File testFile = new File(dataDir, ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE);
         
-        long actualCRC = getFileCRC(testFile);
+        long actualCRC = getFileCRC(HSSFTestDataSamples.openSampleFileStream(ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE));
         long expectedCRC = 2277445406L;
         if(actualCRC != expectedCRC) {
             System.err.println("Expected crc " + expectedCRC  + " but got " + actualCRC);
             throw failUnexpectedTestFileChange();
         }
-        HSSFWorkbook wb;
-        try {
-            FileInputStream in = new FileInputStream(testFile);
-            wb = new HSSFWorkbook(in);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(ABNORMAL_SHARED_FORMULA_FLAG_TEST_FILE);
         
         HSSFSheet s = wb.getSheetAt(0); // Sheet1
         
@@ -311,11 +304,10 @@
     /**
      * gets a CRC checksum for the content of a file
      */
-    private static long getFileCRC(File f) {
+    private static long getFileCRC(InputStream is) {
         CRC32 crc = new CRC32();
         byte[] buf = new byte[2048];
         try {
-            InputStream is = new FileInputStream(f);
             while(true) {
                 int bytesRead = is.read(buf);
                 if(bytesRead < 1) {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java Sun Apr  6 20:02:03 2008
@@ -25,6 +25,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -36,40 +37,27 @@
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
 public abstract class AbstractPtgTestCase extends TestCase {
-    /** Directory containing the test data. */
-    private static String dataDir = System.getProperty("HSSF.testdata.path");
 
     /**
      * Loads a workbook from the given filename in the test data dir.
      *
-     * @param filename the filename.
+     * @param sampleFileName the filename.
      * @return the loaded workbook.
-     * @throws IOException if an error occurs loading the workbook.
      */
-    protected static final HSSFWorkbook loadWorkbook(String filename)
-            throws IOException {
-        File file = new File(dataDir, filename);
-        InputStream stream = new BufferedInputStream(new FileInputStream(file));
-        // TODO - temp workaround to keep stdout quiet due to warning msg in POIFS 
-        // When that warning msg is disabled, remove this wrapper and the close() call, 
-        InputStream wrappedStream = POIFSFileSystem.createNonClosingInputStream(stream);
-        try {
-            return new HSSFWorkbook(wrappedStream);
-        } finally {
-            stream.close();
-        }
+    protected static final HSSFWorkbook loadWorkbook(String sampleFileName) {
+        return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
     }
 
     /**
      * Creates a new Workbook and adds one sheet with the specified name
      */
     protected static final Workbook createWorkbookWithSheet(String sheetName) {
-		
-		Workbook book = Workbook.createWorkbook();
-		// this creates sheet if it doesn't exist
-		book.checkExternSheet(0);
-		// TODO - this call alone does not create the sheet even though the javadoc says it does
-		book.setSheetName(0, sheetName); 
-		return book;
-	}
+        
+        Workbook book = Workbook.createWorkbook();
+        // this creates sheet if it doesn't exist
+        book.checkExternSheet(0);
+        // TODO - this call alone does not create the sheet even though the javadoc says it does
+        book.setSheetName(0, sheetName); 
+        return book;
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java Sun Apr  6 20:02:03 2008
@@ -17,11 +17,9 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 /**
@@ -37,15 +35,7 @@
      * tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook below that   
      */
     public void testReadFormulaContainingExternalFunction() {
-        String filePath = System.getProperty("HSSF.testdata.path")+ "/" 
-        + "externalFunctionExample.xls";
-        HSSFWorkbook wb;
-        try {
-            FileInputStream fin = new FileInputStream(filePath);
-            wb = new HSSFWorkbook( fin );
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
         
         String expectedFormula = "YEARFRAC(B1,C1)";
         HSSFSheet sht = wb.getSheetAt(0);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java Sun Apr  6 20:02:03 2008
@@ -17,9 +17,6 @@
 
 package org.apache.poi.hssf.record.formula.eval;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -27,6 +24,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
 import org.apache.poi.hssf.usermodel.HSSFRow;
@@ -43,49 +41,13 @@
  */
 public final class TestFormulaBugs extends TestCase {
 
-	private static final String TEST_DATA_DIR_SYS_PROPERTY_NAME = "HSSF.testdata.path";
-
-	/**
-	 * Opens a sample file from the standard HSSF test data directory
-	 * 
-	 * @return an open <tt>InputStream</tt> for the specified sample file
-	 */
-	private static InputStream openSampleFileStream(String sampleFileName) {
-		// TODO - move this method somewhere common
-		String dataDirName = System
-				.getProperty(TEST_DATA_DIR_SYS_PROPERTY_NAME);
-		if (dataDirName == null) {
-			throw new RuntimeException("Must set system property '"
-					+ TEST_DATA_DIR_SYS_PROPERTY_NAME
-					+ "' before running tests");
-		}
-		File dataDir = new File(dataDirName);
-		if (!dataDir.exists()) {
-			throw new RuntimeException("Data dir '" + dataDirName
-					+ "' specified by system property '"
-					+ TEST_DATA_DIR_SYS_PROPERTY_NAME + "' does not exist");
-		}
-		File f = new File(dataDir, sampleFileName);
-		if (!f.exists()) {
-			throw new RuntimeException("Sample file '" + sampleFileName
-					+ "' not found in data dir '" + dataDirName + "'");
-		}
-		InputStream is;
-		try {
-			is = new FileInputStream(f);
-		} catch (FileNotFoundException e) {
-			throw new RuntimeException(e);
-		}
-		return is;
-	}
-
 	/**
 	 * Bug 27349 - VLOOKUP with reference to another sheet.<p/> This test was
 	 * added <em>long</em> after the relevant functionality was fixed.
 	 */
 	public void test27349() {
 		// 27349-vlookupAcrossSheets.xls is bugzilla/attachment.cgi?id=10622
-		InputStream is = openSampleFileStream("27349-vlookupAcrossSheets.xls");
+		InputStream is = HSSFTestDataSamples.openSampleFileStream("27349-vlookupAcrossSheets.xls");
 		HSSFWorkbook wb;
 		try {
 			// original bug may have thrown exception here, or output warning to

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java Sun Apr  6 20:02:03 2008
@@ -17,13 +17,13 @@
 
 package org.apache.poi.hssf.record.formula.eval;
 
-import java.io.FileInputStream;
 import java.io.PrintStream;
 
 import junit.framework.Assert;
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.formula.functions.TestMathX;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
@@ -154,9 +154,7 @@
 
 	protected void setUp() throws Exception {
 		if (workbook == null) {
-			String filePath = System.getProperty("HSSF.testdata.path")+ "/" + SS.FILENAME;
-			FileInputStream fin = new FileInputStream( filePath );
-			workbook = new HSSFWorkbook( fin );
+			workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME);
 			sheet = workbook.getSheetAt( 0 );
 		  }
 		_functionFailureCount = 0;
@@ -177,14 +175,14 @@
 		String successMsg = "There were " 
 				+ _evaluationSuccessCount + " successful evaluation(s) and "
 				+ _functionSuccessCount + " function(s) without error";
- 		if(_functionFailureCount > 0) {
+		if(_functionFailureCount > 0) {
 			String msg = _functionFailureCount + " function(s) failed in "
 			+ _evaluationFailureCount + " evaluation(s).  " + successMsg;
 			throw new AssertionFailedError(msg);
 		}
- 		if(false) { // normally no output for successful tests
- 			System.out.println(getClass().getName() + ": " + successMsg);
- 		}
+		if(false) { // normally no output for successful tests
+			System.out.println(getClass().getName() + ": " + successMsg);
+		}
 	}
 
 	/**

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java?rev=645348&r1=645347&r2=645348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java Sun Apr  6 20:02:03 2008
@@ -23,6 +23,7 @@
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -45,14 +46,7 @@
 
 	private static HSSFSheet getSheet() {
 		if (_sheet == null) {
-			String cwd = System.getProperty("HSSF.testdata.path");
-			HSSFWorkbook wb;
-			try {
-				InputStream is = new FileInputStream(new File(cwd, SAMPLE_SPREADSHEET_FILE_NAME));
-				wb = new HSSFWorkbook(is);
-			} catch (IOException e) {
-				throw new RuntimeException(e);
-			}
+			HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_SPREADSHEET_FILE_NAME);
 			_sheet = wb.getSheetAt(0);
 		}
 		return _sheet;



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