You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2009/08/19 20:51:54 UTC

svn commit: r805928 [1/2] - in /poi/trunk: ./ src/ooxml/testcases/org/apache/poi/ src/ooxml/testcases/org/apache/poi/ss/ src/ooxml/testcases/org/apache/poi/xssf/ src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/ src/ooxml/testcases/org/apache/poi...

Author: yegor
Date: Wed Aug 19 18:51:44 2009
New Revision: 805928

URL: http://svn.apache.org/viewvc?rev=805928&view=rev
Log:
Centralize logic for finding/opening sample files

Added:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java   (with props)
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java   (with props)
    poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java   (with props)
Modified:
    poi/trunk/build.xml
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestDetectAsOOXML.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java
    poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java

Modified: poi/trunk/build.xml
URL: http://svn.apache.org/viewvc/poi/trunk/build.xml?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/build.xml (original)
+++ poi/trunk/build.xml Wed Aug 19 18:51:44 2009
@@ -200,6 +200,7 @@
         <pathelement location="${ooxml.output.dir}"/>
         <pathelement location="${ooxml.output.test.dir}"/>
         <pathelement location="${main.output.test.dir}"/> <!-- ooxml tests use some utilities from main tests -->
+        <pathelement location="${scratchpad.output.test.dir}"/> 
         <pathelement location="${junit.jar1.dir}"/>
     </path>
 
@@ -519,6 +520,7 @@
         <path refid="ooxml.classpath"/>
         <pathelement path="${ooxml.output.dir}"/>
         <pathelement path="${main.output.test.dir}"/>
+        <pathelement path="${scratchpad.output.test.dir}"/>
         <pathelement location="${junit.jar1.dir}"/>
       </classpath>
     </javac>

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/TestDetectAsOOXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/TestDetectAsOOXML.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/TestDetectAsOOXML.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/TestDetectAsOOXML.java Wed Aug 19 18:51:44 2009
@@ -22,23 +22,18 @@
 import junit.framework.TestCase;
 import java.io.*;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+
 /**
  * Class to test that HXF correctly detects OOXML
  *  documents
  */
 public class TestDetectAsOOXML extends TestCase
 {
-	public String dirname;
-
-	public void setUp() {
-		dirname = System.getProperty("HSSF.testdata.path");
-	}
-
 	public void testOpensProperly() throws Exception
 	{
-		File f = new File(dirname + "/sample.xlsx");
-
-		POIXMLDocument.openPackage(f.toString());
+        OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("sample.xlsx"));
 	}
 	
 	public void testDetectAsPOIFS() throws Exception {
@@ -46,19 +41,19 @@
 		
 		// ooxml file is
 		in = new PushbackInputStream(
-				new FileInputStream(dirname + "/SampleSS.xlsx"), 10
+				HSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"), 10
 		);
 		assertTrue(POIXMLDocument.hasOOXMLHeader(in));
 		
 		// xls file isn't
 		in = new PushbackInputStream(
-				new FileInputStream(dirname + "/SampleSS.xls"), 10
+				HSSFTestDataSamples.openSampleFileStream("SampleSS.xls"), 10
 		);
 		assertFalse(POIXMLDocument.hasOOXMLHeader(in));
 		
 		// text file isn't
 		in = new PushbackInputStream(
-				new FileInputStream(dirname + "/SampleSS.txt"), 10
+				HSSFTestDataSamples.openSampleFileStream("SampleSS.txt"), 10
 		);
 		assertFalse(POIXMLDocument.hasOOXMLHeader(in));
 	}

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java Wed Aug 19 18:51:44 2009
@@ -175,7 +175,7 @@
 
 	public void testGetSetRevision() {
 		String revision = _coreProperties.getRevision();
-		assertTrue("Revision number is 1", new Integer(_coreProperties.getRevision()).intValue() > 1);
+		assertTrue("Revision number is 1", new Integer(revision)> 1);
 		_coreProperties.setRevision("20");
 		assertEquals("20", _coreProperties.getRevision());
 		_coreProperties.setRevision("20xx");

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java Wed Aug 19 18:51:44 2009
@@ -17,10 +17,8 @@
 
 package org.apache.poi.ss;
 
-import java.io.File;
-import java.io.FileInputStream;
-
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
@@ -30,26 +28,14 @@
 import junit.framework.TestCase;
 
 public final class TestWorkbookFactory extends TestCase {
-	private File xls;
-	private File xlsx;
-	private File txt;
+	private String xls;
+	private String xlsx;
+	private String txt;
 
 	protected void setUp() {
-		xls = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "SampleSS.xls"
-		);
-		xlsx = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "SampleSS.xlsx"
-		);
-		txt = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "SampleSS.txt"
-		);
-		assertTrue(xls.exists());
-		assertTrue(xlsx.exists());
-		assertTrue(txt.exists());
+		xls = "SampleSS.xls";
+		xlsx = "SampleSS.xlsx";
+		txt = "SampleSS.txt";
 	}
 
 	public void testCreateNative() throws Exception {
@@ -57,14 +43,15 @@
 
 		// POIFS -> hssf
 		wb = WorkbookFactory.create(
-				new POIFSFileSystem(new FileInputStream(xls))
+				new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls))
 		);
 		assertNotNull(wb);
 		assertTrue(wb instanceof HSSFWorkbook);
 
 		// Package -> xssf
 		wb = WorkbookFactory.create(
-				OPCPackage.open(xlsx.toString())
+				OPCPackage.open(
+                        HSSFTestDataSamples.openSampleFileStream(xlsx))
 		);
 		assertNotNull(wb);
 		assertTrue(wb instanceof XSSFWorkbook);
@@ -80,20 +67,20 @@
 
 		// InputStream -> either
 		wb = WorkbookFactory.create(
-				new FileInputStream(xls)
+				HSSFTestDataSamples.openSampleFileStream(xls)
 		);
 		assertNotNull(wb);
 		assertTrue(wb instanceof HSSFWorkbook);
 
 		wb = WorkbookFactory.create(
-				new FileInputStream(xlsx)
+				HSSFTestDataSamples.openSampleFileStream(xlsx)
 		);
 		assertNotNull(wb);
 		assertTrue(wb instanceof XSSFWorkbook);
 
 		try {
 			wb = WorkbookFactory.create(
-					new FileInputStream(txt)
+					HSSFTestDataSamples.openSampleFileStream(txt)
 			);
 			fail();
 		} catch(IllegalArgumentException e) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java Wed Aug 19 18:51:44 2009
@@ -38,6 +38,14 @@
  * @author Josh Micich
  */
 public class XSSFTestDataSamples {
+    
+    public static InputStream openSampleFileStream(String sampleFileName) {
+        return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+    }
+    public static byte[] getTestDataFileContent(String fileName) {
+        return HSSFTestDataSamples.getTestDataFileContent(fileName);
+    }
+
 	public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
 		InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
 		try {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java Wed Aug 19 18:51:44 2009
@@ -25,31 +25,16 @@
 
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 
 /**
  * Tests for {@link XSSFReader}
  */
 public final class TestXSSFReader extends TestCase {
-	private String dirName;
-
-	@Override
-	protected void setUp() {
-
-		dirName = System.getProperty("HSSF.testdata.path");
-		assertNotNull(dirName);
-		assertTrue( (new File(dirName)).exists() );
-
-		// Use system out logger
-		System.setProperty(
-				"org.apache.poi.util.POILogger",
-				"org.apache.poi.util.SystemOutLogger"
-		);
-	}
 
 	public void testGetBits() throws Exception {
-		File f = new File(dirName, "SampleSS.xlsx");
-		OPCPackage pkg = OPCPackage.open(f.toString());
+		OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
 
 		XSSFReader r = new XSSFReader(pkg);
 
@@ -62,8 +47,7 @@
 	}
 
 	public void testStyles() throws Exception {
-		File f = new File(dirName, "SampleSS.xlsx");
-		OPCPackage pkg = OPCPackage.open(f.toString());
+		OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
 
 		XSSFReader r = new XSSFReader(pkg);
 
@@ -72,8 +56,7 @@
 	}
 
 	public void testStrings() throws Exception {
-		File f = new File(dirName, "SampleSS.xlsx");
-		OPCPackage pkg = OPCPackage.open(f.toString());
+        OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
 
 		XSSFReader r = new XSSFReader(pkg);
 
@@ -82,8 +65,7 @@
 	}
 
 	public void testSheets() throws Exception {
-		File f = new File(dirName, "SampleSS.xlsx");
-		OPCPackage pkg = OPCPackage.open(f.toString());
+        OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
 
 		XSSFReader r = new XSSFReader(pkg);
 		byte[] data = new byte[4096];
@@ -115,8 +97,7 @@
 	 * (as they are defined in the workbook.xml)
 	 */
 	public void testOrderOfSheets() throws Exception {
-		File f = new File(dirName, "reordered_sheets.xlsx");
-		OPCPackage pkg = OPCPackage.open(f.toString());
+        OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("reordered_sheets.xlsx"));
 
 		XSSFReader r = new XSSFReader(pkg);
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java Wed Aug 19 18:51:44 2009
@@ -19,7 +19,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.util.List;
 
 import org.apache.poi.ss.usermodel.Cell;
@@ -120,14 +119,7 @@
 	}
 
 	public void testDontLoostNewLines() throws Exception {
-		File xml = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "WithVariousData.xlsx"
-		);
-		assertTrue(xml.exists());
-
-		OPCPackage pkg = OPCPackage.open(xml.toString());
-		XSSFWorkbook wb = new XSSFWorkbook(pkg);
+		XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
 		List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
 		CommentsTable ct = null;
 		for(POIXMLDocumentPart p : rels) {
@@ -171,13 +163,7 @@
 	}
 
 	public void testExisting() throws Exception {
-		File xml = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "WithVariousData.xlsx"
-		);
-		assertTrue(xml.exists());
-
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
 		Sheet sheet1 = workbook.getSheetAt(0);
 		Sheet sheet2 = workbook.getSheetAt(1);
 
@@ -207,13 +193,7 @@
 	}
 
 	public void testWriteRead() throws Exception {
-		File xml = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "WithVariousData.xlsx"
-		);
-		assertTrue(xml.exists());
-
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
 		XSSFSheet sheet1 = workbook.getSheetAt(0);
 		XSSFSheet sheet2 = workbook.getSheetAt(1);
 
@@ -260,13 +240,7 @@
 	}
 
 	public void testReadWriteMultipleAuthors() throws Exception {
-		File xml = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "WithMoreVariousData.xlsx"
-		);
-		assertTrue(xml.exists());
-
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
 		XSSFSheet sheet1 = workbook.getSheetAt(0);
 		XSSFSheet sheet2 = workbook.getSheetAt(1);
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java Wed Aug 19 18:51:44 2009
@@ -17,8 +17,6 @@
 
 package org.apache.poi.xssf.model;
 
-import java.io.File;
-
 import org.apache.poi.xssf.usermodel.XSSFCellStyle;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -26,15 +24,7 @@
 import junit.framework.TestCase;
 
 public final class TestStylesTable extends TestCase {
-	private File xml;
-
-	protected void setUp() {
-		xml = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "Formatting.xlsx"
-		);
-		assertTrue(xml.exists());
-	}
+	private String testFile = "Formatting.xlsx";
 
 	public void testCreateNew() {
 		StylesTable st = new StylesTable();
@@ -64,7 +54,7 @@
 	}
 
 	public void testLoadExisting() throws Exception {
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
 		assertNotNull(workbook.getStylesSource());
 
 		StylesTable st = workbook.getStylesSource();
@@ -72,7 +62,7 @@
 		doTestExisting(st);
 	}
 	public void testLoadSaveLoad() throws Exception {
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
 		assertNotNull(workbook.getStylesSource());
 
 		StylesTable st = workbook.getStylesSource();
@@ -136,7 +126,7 @@
 	}
 
 	public void testPopulateExisting() throws Exception {
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
 		assertNotNull(workbook.getStylesSource());
 
 		StylesTable st = workbook.getStylesSource();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java Wed Aug 19 18:51:44 2009
@@ -39,13 +39,7 @@
 	}
 
 	public void testLoadExisting() throws Exception {
-		File xml = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "WithMoreVariousData.xlsx"
-		);
-		assertTrue(xml.exists());
-
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
 		assertEquals(3, workbook.getNumberOfSheets());
 
 		XSSFSheet sheet = workbook.getSheetAt(0);
@@ -56,13 +50,7 @@
 	}
 
 	public void testLoadSave() throws Exception {
-		File xml = new File(
-				System.getProperty("HSSF.testdata.path") +
-				File.separator + "WithMoreVariousData.xlsx"
-		);
-		assertTrue(xml.exists());
-
-		XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
 		CreationHelper createHelper = workbook.getCreationHelper();
 		assertEquals(3, workbook.getNumberOfSheets());
 		XSSFSheet sheet = workbook.getSheetAt(0);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Wed Aug 19 18:51:44 2009
@@ -17,8 +17,6 @@
 
 package org.apache.poi.xssf.usermodel;
 
-import java.io.File;
-
 import org.apache.poi.ss.usermodel.BaseTestSheet;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -54,13 +52,7 @@
     }
 
     public void testExistingHeaderFooter() throws Exception {
-        File xml = new File(
-                System.getProperty("HSSF.testdata.path") +
-                        File.separator + "45540_classic_Header.xlsx"
-        );
-        assertTrue(xml.exists());
-
-        XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("45540_classic_Header.xlsx");
         XSSFOddHeader hdr;
         XSSFOddFooter ftr;
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java Wed Aug 19 18:51:44 2009
@@ -29,27 +29,10 @@
 import org.apache.poi.xwpf.usermodel.XWPFRelation;
 
 public final class TestXWPFDocument extends TestCase {
-	private File sampleFile;
-	private File complexFile;
-
-	protected void setUp() throws Exception {
-		super.setUp();
-
-		sampleFile = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "sample.docx"
-		);
-		complexFile = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "IllustrativeCases.docx"
-		);
-
-		assertTrue(sampleFile.exists());
-		assertTrue(complexFile.exists());
-	}
 
 	public void testContainsMainContentType() throws Exception {
-		OPCPackage pack = POIXMLDocument.openPackage(sampleFile.toString());
+		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        OPCPackage pack = doc.getPackage();
 
 		boolean found = false;
 		for(PackagePart part : pack.getParts()) {
@@ -62,40 +45,24 @@
 	}
 
 	public void testOpen() throws Exception {
-		POIXMLDocument.openPackage(sampleFile.toString());
-		POIXMLDocument.openPackage(complexFile.toString());
-
-		new XWPFDocument(
-				POIXMLDocument.openPackage(sampleFile.toString())
-		);
-		new XWPFDocument(
-				POIXMLDocument.openPackage(complexFile.toString())
-		);
-
 		XWPFDocument xml;
 
 		// Simple file
-		xml = new XWPFDocument(
-				POIXMLDocument.openPackage(sampleFile.toString())
-		);
+		xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
 		// Check it has key parts
 		assertNotNull(xml.getDocument());
 		assertNotNull(xml.getDocument().getBody());
 		assertNotNull(xml.getStyle());
 
 		// Complex file
-		xml = new XWPFDocument(
-				POIXMLDocument.openPackage(complexFile.toString())
-		);
+        xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
 		assertNotNull(xml.getDocument());
 		assertNotNull(xml.getDocument().getBody());
 		assertNotNull(xml.getStyle());
 	}
 
 	public void testMetadataBasics() throws Exception {
-		XWPFDocument xml = new XWPFDocument(
-				POIXMLDocument.openPackage(sampleFile.toString())
-		);
+        XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
 		assertNotNull(xml.getProperties().getCoreProperties());
 		assertNotNull(xml.getProperties().getExtendedProperties());
 
@@ -108,9 +75,7 @@
 	}
 
 	public void testMetadataComplex() throws Exception {
-		XWPFDocument xml = new XWPFDocument(
-				POIXMLDocument.openPackage(complexFile.toString())
-		);
+		XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
 		assertNotNull(xml.getProperties().getCoreProperties());
 		assertNotNull(xml.getProperties().getExtendedProperties());
 

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java?rev=805928&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java Wed Aug 19 18:51:44 2009
@@ -0,0 +1,54 @@
+/* ====================================================================
+   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.xwpf;
+
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.POIDataSamples;
+
+import java.io.*;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class XWPFTestDataSamples {
+
+    public static XWPFDocument openSampleDocument(String sampleName) {
+        InputStream is = HWPFTestDataSamples.openSampleFileStream(sampleName);
+        try {
+            return new XWPFDocument(is);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static XWPFDocument writeOutAndReadBack(XWPFDocument doc) {
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+            doc.write(baos);
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            return new XWPFDocument(bais);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static POIDataSamples getInstance(){
+        return HWPFTestDataSamples.getInstance();
+    }
+
+}

Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java Wed Aug 19 18:51:44 2009
@@ -21,6 +21,7 @@
 
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
 
 import junit.framework.TestCase;
 
@@ -33,7 +34,7 @@
      * Get text out of the simple file
      */
     public void testGetSimpleText() throws Exception {
-        XWPFDocument doc = open("sample.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         String text = extractor.getText();
@@ -62,7 +63,7 @@
      * Tests getting the text out of a complex file
      */
     public void testGetComplexText() throws Exception {
-        XWPFDocument doc = open("IllustrativeCases.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         String text = extractor.getText();
@@ -94,7 +95,7 @@
     }
 
     public void testGetWithHyperlinks() throws Exception {
-        XWPFDocument doc = open("TestDocument.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         // Now check contents
@@ -119,7 +120,7 @@
     }
 
     public void testHeadersFooters() throws Exception {
-        XWPFDocument doc = open("ThreeColHeadFoot.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ThreeColHeadFoot.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         assertEquals(
@@ -138,7 +139,7 @@
 
         // Now another file, expect multiple headers
         //  and multiple footers
-        doc = open("DiffFirstPageHeadFoot.docx");
+        doc = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx");
         extractor = new XWPFWordExtractor(doc);
         extractor =
                 new XWPFWordExtractor(doc);
@@ -162,7 +163,7 @@
     }
 
     public void testFootnotes() throws Exception {
-        XWPFDocument doc = open("footnotes.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("footnotes.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         assertTrue(extractor.getText().contains("snoska"));
@@ -170,14 +171,14 @@
 
 
     public void testTableFootnotes() throws Exception {
-        XWPFDocument doc = open("table_footnotes.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("table_footnotes.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         assertTrue(extractor.getText().contains("snoska"));
     }
 
     public void testFormFootnotes() throws Exception {
-        XWPFDocument doc = open("form_footnotes.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("form_footnotes.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         String text = extractor.getText();
@@ -186,33 +187,18 @@
     }
 
     public void testEndnotes() throws Exception {
-        XWPFDocument doc = open("endnotes.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("endnotes.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         assertTrue(extractor.getText().contains("XXX"));
     }
 
     public void testInsertedDeletedText() throws Exception {
-        XWPFDocument doc = open("delins.docx");
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("delins.docx");
         XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
 
         assertTrue(extractor.getText().contains("pendant worn"));
         assertTrue(extractor.getText().contains("extremely well"));
     }
 
-    //TODO use the same logic for opening test files as in HSSFTestDataSamples
-    private XWPFDocument open(String sampleFileName) throws IOException {
-        File file = new File(
-                System.getProperty("HWPF.testdata.path"), sampleFileName);
-
-        try {
-            if(!sampleFileName.equals(file.getCanonicalFile().getName())){
-                throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName
-                        + "' but actual file is '" + file.getCanonicalFile().getName() + "'");
-            }
-        } catch (IOException e){
-            throw new RuntimeException(e);
-        }
-        return new XWPFDocument(POIXMLDocument.openPackage(file.getPath()));
-    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java Wed Aug 19 18:51:44 2009
@@ -20,6 +20,7 @@
 
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
 
 import junit.framework.TestCase;
 
@@ -36,49 +37,13 @@
 
 	protected void setUp() throws Exception {
 		super.setUp();
-		File file;
 
-		file = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "NoHeadFoot.docx"
-		);
-		assertTrue(file.exists());
-		noHeader = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
-
-		file = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "ThreeColHead.docx"
-		);
-		assertTrue(file.exists());
-		header = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
-
-		file = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "SimpleHeadThreeColFoot.docx"
-		);
-		assertTrue(file.exists());
-		headerFooter = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
-
-		file = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "FancyFoot.docx"
-		);
-		assertTrue(file.exists());
-		footer = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
-
-		file = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "PageSpecificHeadFoot.docx"
-		);
-		assertTrue(file.exists());
-		oddEven = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
-
-		file = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "DiffFirstPageHeadFoot.docx"
-		);
-		assertTrue(file.exists());
-		diffFirst = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
+		noHeader = XWPFTestDataSamples.openSampleDocument("NoHeadFoot.docx");
+        header = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
+        headerFooter = XWPFTestDataSamples.openSampleDocument("SimpleHeadThreeColFoot.docx");
+        footer = XWPFTestDataSamples.openSampleDocument("FancyFoot.docx");
+        oddEven = XWPFTestDataSamples.openSampleDocument("PageSpecificHeadFoot.docx");
+        diffFirst = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx");
 	}
 
 	public void testPolicy() {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java Wed Aug 19 18:51:44 2009
@@ -23,6 +23,7 @@
 
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
@@ -31,16 +32,8 @@
 public class TestXWPFHeader extends TestCase {
 	
 	public void testSimpleHeader() throws IOException {
-		File sampleFile = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "headerFooter.docx"
-		);
-		assertTrue(sampleFile.exists());
-		XWPFDocument sampleDoc;
-		sampleDoc = new XWPFDocument(
-				POIXMLDocument.openPackage(sampleFile.toString())
-		);
-		
+		XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerFooter.docx");
+
 		XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
 		
 		
@@ -55,15 +48,7 @@
 	}
 	
 	public void testSetHeader() throws IOException {
-		File sampleFile = new File(
-				System.getProperty("HWPF.testdata.path") +
-				File.separator + "SampleDoc.docx"
-		);
-		assertTrue(sampleFile.exists());
-		XWPFDocument sampleDoc;
-		sampleDoc = new XWPFDocument(
-				POIXMLDocument.openPackage(sampleFile.toString())
-		);
+		XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
 		// no header is set (yet)
 		XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
 		assertNull(policy.getDefaultHeader());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java Wed Aug 19 18:51:44 2009
@@ -22,6 +22,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.POIXMLDocument;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
@@ -41,26 +42,13 @@
  * Tests for XWPF Paragraphs
  */
 public final class TestXWPFParagraph extends TestCase {
-    /**
-     * A simple file
-     */
-    private XWPFDocument xml;
-
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        File file = new File(
-                System.getProperty("HWPF.testdata.path") +
-                File.separator + "ThreeColHead.docx"
-        );
-        assertTrue(file.exists());
-        xml = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
-    }
 
     /**
      * Check that we get the right paragraph from the header
      */
     public void disabled_testHeaderParagraph() {
+        XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
+
         XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
         assertNotNull(hdr);
 
@@ -77,6 +65,7 @@
      * Check that we get the right paragraphs from the document
      */
     public void disabled_testDocumentParagraph() {
+        XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
         XWPFParagraph[] ps = xml.getParagraphs();
         assertEquals(10, ps.length);
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java Wed Aug 19 18:51:44 2009
@@ -41,17 +41,8 @@
   {
     try
     {
-      String filename = System.getProperty("HWPF.testdata.path");
-      if (filename == null)
-      {
-        filename = "c:";
-      }
-
-      filename = filename + "/test.doc";
-
-
-      POIFSFileSystem filesystem = new POIFSFileSystem(new FileInputStream(
-        new File(filename)));
+      POIFSFileSystem filesystem = new POIFSFileSystem(
+              HWPFTestDataSamples.openSampleFileStream("test.doc"));
 
       DocumentEntry documentProps =
         (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");

Added: 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=805928&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java Wed Aug 19 18:51:44 2009
@@ -0,0 +1,65 @@
+/* ====================================================================
+   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.hwpf;
+
+import org.apache.poi.POIDataSamples;
+
+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 static HWPFDocument openSampleFile(String sampleFileName) {
+        try {
+            return new HWPFDocument(_inst.openResourceAsStream(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 HWPFDocument writeOutAndReadBack(HWPFDocument original) {
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+            original.write(baos);
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            return new HWPFDocument(bais);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestDataSamples.java
------------------------------------------------------------------------------
    svn:executable = *

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=805928&r1=805927&r2=805928&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 Wed Aug 19 18:51:44 2009
@@ -17,9 +17,6 @@
 
 package org.apache.poi.hwpf;
 
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
 import java.util.List;
 
 import junit.framework.TestCase;
@@ -43,33 +40,32 @@
 	private String imgDFile;
 
 	protected void setUp() {
-		String dirname = System.getProperty("HWPF.testdata.path");
 
-		docAFile = dirname + "/testPictures.doc";
-		docBFile = dirname + "/two_images.doc";
-		docCFile = dirname + "/vector_image.doc";
-		docDFile = dirname + "/GaiaTest.doc";
-
-		imgAFile = dirname + "/simple_image.jpg";
-		imgBFile = dirname + "/simple_image.png";
-		imgCFile = dirname + "/vector_image.emf";
-		imgDFile = dirname + "/GaiaTestImg.png";
+		docAFile = "testPictures.doc";
+		docBFile = "two_images.doc";
+		docCFile = "vector_image.doc";
+		docDFile = "GaiaTest.doc";
+
+		imgAFile = "simple_image.jpg";
+		imgBFile = "simple_image.png";
+		imgCFile = "vector_image.emf";
+		imgDFile = "GaiaTestImg.png";
 	}
 
 	/**
 	 * Test just opening the files
 	 */
 	public void testOpen() throws Exception {
-		HWPFDocument docA = new HWPFDocument(new FileInputStream(docAFile));
-		HWPFDocument docB = new HWPFDocument(new FileInputStream(docBFile));
+		HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile);
+		HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
 	}
 
 	/**
 	 * Test that we have the right numbers of images in each file
 	 */
 	public void testImageCount() throws Exception {
-		HWPFDocument docA = new HWPFDocument(new FileInputStream(docAFile));
-		HWPFDocument docB = new HWPFDocument(new FileInputStream(docBFile));
+		HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile);
+		HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
 
 		assertNotNull(docA.getPicturesTable());
 		assertNotNull(docB.getPicturesTable());
@@ -88,7 +84,7 @@
 	 * Test that we have the right images in at least one file
 	 */
 	public void testImageData() throws Exception {
-		HWPFDocument docB = new HWPFDocument(new FileInputStream(docBFile));
+		HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
 		PicturesTable picB = docB.getPicturesTable();
 		List picturesB = picB.getAllPictures();
 
@@ -115,7 +111,7 @@
 	 * Test that compressed image data is correctly returned.
 	 */
 	public void testCompressedImageData() throws Exception {
-		HWPFDocument docC = new HWPFDocument(new FileInputStream(docCFile));
+		HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
 		PicturesTable picC = docC.getPicturesTable();
 		List picturesC = picC.getAllPictures();
 
@@ -136,7 +132,7 @@
 	 *  bug #44937
 	 */
 	public void BROKENtestEscherDrawing() throws Exception {
-		HWPFDocument docD = new HWPFDocument(new FileInputStream(docDFile));
+		HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile);
 		List allPictures = docD.getPicturesTable().getAllPictures();
 
 		assertEquals(1, allPictures.size());
@@ -158,23 +154,6 @@
 	}
 
 	private static byte[] readFile(String file) {
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		try {
-			FileInputStream fis = new FileInputStream(file);
-			byte[] buffer = new byte[1024];
-
-			int read = 0;
-			while(read > -1) {
-				read = fis.read(buffer);
-				if(read > 0) {
-					baos.write(buffer,0,read);
-				}
-			}
-			fis.close();
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-
-		return baos.toByteArray();
+		return HWPFTestDataSamples.getTestDataFileContent(file);
 	}
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java Wed Aug 19 18:51:44 2009
@@ -17,8 +17,6 @@
 
 package org.apache.poi.hwpf;
 
-import java.io.FileInputStream;
-
 import org.apache.poi.hwpf.usermodel.Range;
 
 import junit.framework.TestCase;
@@ -96,17 +94,8 @@
 	private HWPFDocument docUnicode;
 
 	public void setUp() throws Exception {
-		String dirname = System.getProperty("HWPF.testdata.path");
-
-		String filename = dirname + "/HeaderFooterUnicode.doc";
-		docUnicode = new HWPFDocument(
-				new FileInputStream(filename)
-		);
-
-		filename = dirname + "/ThreeColHeadFoot.doc";
-		docAscii = new HWPFDocument(
-				new FileInputStream(filename)
-		);
+		docUnicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
+		docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
 	}
 
 	public void testBasics() {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java Wed Aug 19 18:51:44 2009
@@ -17,10 +17,10 @@
 
 package org.apache.poi.hwpf.extractor;
 
-import java.io.FileInputStream;
 import java.util.Iterator;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.hwpf.model.TextPiece;
 import org.apache.poi.hwpf.usermodel.Paragraph;
 import org.apache.poi.hwpf.usermodel.Range;
@@ -53,10 +53,7 @@
 	private HWPFDocument doc;
 
     protected void setUp() throws Exception {
-		String dirname = System.getProperty("HWPF.testdata.path");
-
-		String filename = dirname + "/test2.doc";
-		doc = new HWPFDocument(new FileInputStream(filename));
+		doc = HWPFTestDataSamples.openSampleFile("test2.doc");
     }
 
     /**

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=805928&r1=805927&r2=805928&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 Wed Aug 19 18:51:44 2009
@@ -17,14 +17,15 @@
 
 package org.apache.poi.hwpf.extractor;
 
-import java.io.FileInputStream;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
+import java.io.FileInputStream;
+
 /**
  * Test the different routes to extracting text
  *
@@ -47,7 +48,7 @@
 			"\r\n",
 			"It is otherwise very very boring.\r\n"
 	};
-	private String p_text1_block = new String();
+	private String p_text1_block = "";
 
 	// Well behaved document
 	private WordExtractor extractor;
@@ -64,18 +65,17 @@
         private String filename6;
 
     protected void setUp() throws Exception {
-		String dirname = System.getProperty("HWPF.testdata.path");
 		String pdirname = System.getProperty("POIFS.testdata.path");
 
-		String filename = dirname + "/test2.doc";
-		String filename2 = dirname + "/test.doc";
+		String filename = "test2.doc";
+		String filename2 = "test.doc";
 		filename3 = pdirname + "/excel_with_embeded.xls";
-		filename4 = dirname + "/ThreeColHeadFoot.doc";
-		filename5 = dirname + "/HeaderFooterUnicode.doc";
-                filename6 = dirname + "/footnote.doc";
+		filename4 = "ThreeColHeadFoot.doc";
+		filename5 = "HeaderFooterUnicode.doc";
+                filename6 = "footnote.doc";
 
-		extractor = new WordExtractor(new FileInputStream(filename));
-		extractor2 = new WordExtractor(new FileInputStream(filename2));
+		extractor = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename));
+		extractor2 = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename2));
 
 		// Build splat'd out text version
 		for(int i=0; i<p_text1.length; i++) {
@@ -123,7 +123,8 @@
      * @throws Exception
      */
     public void testExtractFromEmbeded() throws Exception {
-    	POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3));
+    	POIFSFileSystem fs = new POIFSFileSystem(
+                new FileInputStream(filename3));
     	HWPFDocument doc;
     	WordExtractor extractor3;
 
@@ -164,9 +165,7 @@
 
     public void testWithHeader() throws Exception {
     	// Non-unicode
-    	HWPFDocument doc = new HWPFDocument(
-    			new FileInputStream(filename4)
-    	);
+    	HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
     	extractor = new WordExtractor(doc);
 
     	assertEquals(
@@ -181,9 +180,7 @@
 
 
     	// Unicode
-    	doc = new HWPFDocument(
-    			new FileInputStream(filename5)
-    	);
+    	doc = HWPFTestDataSamples.openSampleFile(filename5);
     	extractor = new WordExtractor(doc);
 
     	assertEquals(
@@ -198,9 +195,7 @@
 
     public void testWithFooter() throws Exception {
     	// Non-unicode
-    	HWPFDocument doc = new HWPFDocument(
-    			new FileInputStream(filename4)
-    	);
+    	HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
     	extractor = new WordExtractor(doc);
 
     	assertEquals(
@@ -215,9 +210,7 @@
 
 
     	// Unicode
-    	doc = new HWPFDocument(
-    			new FileInputStream(filename5)
-    	);
+    	doc = HWPFTestDataSamples.openSampleFile(filename5);
     	extractor = new WordExtractor(doc);
 
     	assertEquals(
@@ -231,9 +224,7 @@
     }
 
     public void testFootnote() throws Exception {
-        HWPFDocument doc = new HWPFDocument(
-                new FileInputStream(filename6)
-        );
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
         extractor = new WordExtractor(doc);
 
         String[] text = extractor.getFootnoteText();
@@ -246,9 +237,7 @@
     }
 
     public void testEndnote() throws Exception {
-        HWPFDocument doc = new HWPFDocument(
-                new FileInputStream(filename6)
-        );
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
         extractor = new WordExtractor(doc);
 
         String[] text = extractor.getEndnoteText();
@@ -261,9 +250,7 @@
     }
 
     public void testComments() throws Exception {
-        HWPFDocument doc = new HWPFDocument(
-                new FileInputStream(filename6)
-        );
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
         extractor = new WordExtractor(doc);
 
         String[] text = extractor.getCommentsText();

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=805928&r1=805927&r2=805928&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 Wed Aug 19 18:51:44 2009
@@ -20,6 +20,7 @@
 import java.io.FileInputStream;
 
 import junit.framework.TestCase;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 /**
  * Tests for bugs with the WordExtractor
@@ -27,15 +28,10 @@
  * @author Nick Burch (nick at torchbox dot com)
  */
 public final class TestWordExtractorBugs extends TestCase {
-	private String dirname;
-	protected void setUp() {
-		dirname = System.getProperty("HWPF.testdata.path");
-	}
 
 	public void testProblemMetadata() throws Exception {
-		String filename = dirname + "/ProblemExtracting.doc";
 		WordExtractor extractor =
-			new WordExtractor(new FileInputStream(filename));
+			new WordExtractor(HWPFTestDataSamples.openSampleFileStream("ProblemExtracting.doc"));
 
 		// Check it gives text without error
 		extractor.getText();

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java Wed Aug 19 18:51:44 2009
@@ -24,6 +24,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 /**
  * Unit test for {@link SavedByTable} and {@link SavedByEntry}.
@@ -33,8 +34,6 @@
 public final class TestSavedByTable
   extends TestCase
 {
-  /** Data dir */
-  private File testFile = new File(new File(System.getProperty("HWPF.testdata.path")), "saved-by-table.doc");
 
   /** The expected entries in the test document. */
   private List expected = Arrays.asList(new Object[] {
@@ -62,16 +61,7 @@
     // This document is widely available on the internet as "blair.doc".
     // I tried stripping the content and saving the document but my version
     // of Word (from Office XP) strips this table out.
-    InputStream stream = new BufferedInputStream(new FileInputStream(testFile));
-    HWPFDocument doc;
-    try
-    {
-      doc = new HWPFDocument(stream);
-    }
-    finally
-    {
-      stream.close();
-    }
+    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("saved-by-table.doc");
 
     // Check what we just read.
     assertEquals("List of saved-by entries was not as expected",

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java Wed Aug 19 18:51:44 2009
@@ -19,19 +19,18 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocFixture;
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.hwpf.model.io.HWPFFileSystem;
 
 
 public final class TestTextPieceTable extends TestCase {
   private HWPFDocFixture _hWPFDocFixture;
-  private String dirname;
+  //private String dirname;
 
   public void testReadWrite()
     throws Exception
@@ -66,9 +65,7 @@
 	 *  working with pure-ascii
 	 */
 	public void testAsciiParts() throws Exception {
-		HWPFDocument doc = new HWPFDocument(
-				new FileInputStream(new File(dirname, "ThreeColHeadFoot.doc"))
-		);
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
 		TextPieceTable tbl = doc.getTextTable();
 
 		// All ascii, so stored in one big lump
@@ -101,9 +98,7 @@
 	 *  working with a mix ascii, unicode file
 	 */
 	public void testUnicodeParts() throws Exception {
-		HWPFDocument doc = new HWPFDocument(
-				new FileInputStream(new File(dirname, "HeaderFooterUnicode.doc"))
-		);
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
 		TextPieceTable tbl = doc.getTextTable();
 
 		// In three bits, split every 512 bytes
@@ -177,8 +172,6 @@
 
     _hWPFDocFixture = new HWPFDocFixture(this);
     _hWPFDocFixture.setUp();
-
-    dirname = System.getProperty("HWPF.testdata.path");
   }
 
   protected void tearDown()

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug46610.java Wed Aug 19 18:51:44 2009
@@ -19,34 +19,28 @@
 
 import junit.framework.TestCase;
 
-import java.io.FileInputStream;
-
 import org.apache.poi.hwpf.usermodel.CharacterRun;
 import org.apache.poi.hwpf.usermodel.Paragraph;
 import org.apache.poi.hwpf.usermodel.Range;
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 public class TestBug46610 extends TestCase {
-  private String dirname;
-
-  protected void setUp() {
-    dirname = System.getProperty("HWPF.testdata.path");
-  }
 
   public void testUtf() throws Exception {
-    HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/Bug46610_1.doc"));
+    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_1.doc");
 
     runExtract(doc);
   }
 
   public void testUtf2() throws Exception {
-    HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/Bug46610_2.doc"));
+    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_2.doc");
 
     runExtract(doc);
   }
 
   public void testExtraction() throws Exception {
-    HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/Bug46610_3.doc"));
+    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_3.doc");
 
     String text = runExtract(doc);
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java Wed Aug 19 18:51:44 2009
@@ -17,12 +17,10 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.File;
-import java.io.FileInputStream;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 /**
  * Tests for the handling of header stories into headers, footers etc
@@ -38,21 +36,15 @@
 	private HWPFDocument withFields;
 
 	protected void setUp() throws Exception {
-		String dirname = System.getProperty("HWPF.testdata.path");
 
-		none = new HWPFDocument(new FileInputStream(new File(dirname, "NoHeadFoot.doc")));
-		header = new HWPFDocument(new FileInputStream(new File(dirname, "ThreeColHead.doc")));
-		footer = new HWPFDocument(new FileInputStream(new File(dirname, "ThreeColFoot.doc")));
-		headerFooter = new HWPFDocument(new FileInputStream(new File(dirname,
-				"SimpleHeadThreeColFoot.doc")));
-		oddEven = new HWPFDocument(new FileInputStream(
-				new File(dirname, "PageSpecificHeadFoot.doc")));
-		diffFirst = new HWPFDocument(new FileInputStream(new File(dirname,
-				"DiffFirstPageHeadFoot.doc")));
-		unicode = new HWPFDocument(
-				new FileInputStream(new File(dirname, "HeaderFooterUnicode.doc")));
-		withFields = new HWPFDocument(
-				new FileInputStream(new File(dirname, "HeaderWithMacros.doc")));
+		none = HWPFTestDataSamples.openSampleFile("NoHeadFoot.doc");
+		header = HWPFTestDataSamples.openSampleFile("ThreeColHead.doc");
+		footer = HWPFTestDataSamples.openSampleFile("ThreeColFoot.doc");
+		headerFooter = HWPFTestDataSamples.openSampleFile("SimpleHeadThreeColFoot.doc");
+		oddEven = HWPFTestDataSamples.openSampleFile("PageSpecificHeadFoot.doc");
+		diffFirst = HWPFTestDataSamples.openSampleFile("DiffFirstPageHeadFoot.doc");
+		unicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
+		withFields = HWPFTestDataSamples.openSampleFile("HeaderWithMacros.doc");
 	}
 
 	public void testNone() {

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=805928&r1=805927&r2=805928&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 Wed Aug 19 18:51:44 2009
@@ -17,14 +17,12 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -33,14 +31,12 @@
  * @author Nick Burch (nick at torchbox dot com)
  */
 public final class TestPictures extends TestCase {
-	private String dirname = System.getProperty("HWPF.testdata.path");
-
 
 	/**
 	 * two jpegs
 	 */
 	public void testTwoImages() throws Exception {
-		HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/two_images.doc"));
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc");
 		List pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
@@ -64,7 +60,7 @@
 	 * pngs and jpegs
 	 */
 	public void testDifferentImages() throws Exception {
-		HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/testPictures.doc"));
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testPictures.doc");
 		List pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
@@ -90,7 +86,7 @@
 	 * emf image, nice and simple
 	 */
 	public void testEmfImage() throws Exception {
-		HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/vector_image.doc"));
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("vector_image.doc");
 		List pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
@@ -102,7 +98,7 @@
 		assertTrue(pic.getSize() > 128);
 
 		// Check right contents
-		byte[] emf = loadImage("vector_image.emf");
+		byte[] emf = HWPFTestDataSamples.getTestDataFileContent("vector_image.emf");
 		byte[] pemf = pic.getContent();
 		assertEquals(emf.length, pemf.length);
 		for(int i=0; i<emf.length; i++) {
@@ -119,7 +115,7 @@
 		// pictures. Instead it has an office drawing object. Need to rewrite this test after
 		// revisiting the implementation of office drawing objects.
 
-		HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/emf_2003_image.doc"));
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("emf_2003_image.doc");
 		List pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
@@ -141,22 +137,10 @@
 	}
 
 	public void testPicturesWithTable() throws Exception {
-		HWPFDocument doc = new HWPFDocument(new FileInputStream(
-				new File(dirname, "Bug44603.doc")));
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc");
 
 		List pics = doc.getPicturesTable().getAllPictures();
 		assertEquals(pics.size(), 2);
 	}
 
-	private byte[] loadImage(String filename) throws Exception {
-		ByteArrayOutputStream b = new ByteArrayOutputStream();
-		FileInputStream fis = new FileInputStream(dirname + "/" + filename);
-
-		byte[] buf = new byte[4096];
-		int read = 0;
-		while( (read = fis.read(buf)) > -1 ) {
-			b.write(buf, 0, read);
-		}
-		return b.toByteArray();
-	}
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java Wed Aug 19 18:51:44 2009
@@ -17,12 +17,10 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.File;
-import java.io.FileInputStream;
-
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFTestCase;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.hwpf.model.StyleSheet;
 
 /**
@@ -32,14 +30,11 @@
  */
 public final class TestProblems extends HWPFTestCase {
 
-	private String dirname = System.getProperty("HWPF.testdata.path");
-
     /**
      * ListEntry passed no ListTable
      */
     public void testListEntryNoListTable() throws Exception {
-    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
-    			new File(dirname, "ListEntryNoListTable.doc")));
+    	HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ListEntryNoListTable.doc");
 
     	Range r = doc.getRange();
     	StyleSheet styleSheet = doc.getStyleSheet();
@@ -56,8 +51,7 @@
 	 * AIOOB for TableSprmUncompressor.unCompressTAPOperation
 	 */
 	public void testSprmAIOOB() throws Exception {
-    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
-    			new File(dirname, "AIOOB-Tap.doc")));
+    	HWPFDocument doc = HWPFTestDataSamples.openSampleFile("AIOOB-Tap.doc");
 
     	Range r = doc.getRange();
     	StyleSheet styleSheet = doc.getStyleSheet();
@@ -75,8 +69,7 @@
 	 * Bugs #45062 and #44292
 	 */
 	public void testTableCellLastParagraph() throws Exception {
-    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
-    			new File(dirname, "Bug44292.doc")));
+    	HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44292.doc");
 		Range r = doc.getRange();
 		assertEquals(6, r.numParagraphs());
 		assertEquals(0, r.getStartOffset());
@@ -115,8 +108,7 @@
 	}
 
 	public void testRangeDelete() throws Exception {
-    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
-    			new File(dirname, "Bug28627.doc")));
+    	HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug28627.doc");
 
     	Range range = doc.getRange();
 		int numParagraphs = range.numParagraphs();
@@ -155,8 +147,7 @@
 	 */
 	public void testEncryptedFile() throws Exception {
 		try {
-			new HWPFDocument(new FileInputStream(
-    			new File(dirname, "PasswordProtected.doc")));
+			HWPFTestDataSamples.openSampleFile("PasswordProtected.doc");
 			fail();
 		} catch(EncryptedDocumentException e) {
 			// Good
@@ -164,8 +155,7 @@
 	}
 
 	public void testWriteProperties() throws Exception {
-		HWPFDocument doc = new HWPFDocument(new FileInputStream(
-    			new File(dirname, "SampleDoc.doc")));
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
 		assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor());
 
 		// Write and read

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java Wed Aug 19 18:51:44 2009
@@ -17,11 +17,10 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.FileInputStream;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.hwpf.model.PAPX;
 
 /**
@@ -48,10 +47,7 @@
 	private String illustrativeDocFile;
 
 	protected void setUp() {
-
-		String dirname = System.getProperty("HWPF.testdata.path");
-
-		illustrativeDocFile = dirname + "/testRangeDelete.doc";
+		illustrativeDocFile = "testRangeDelete.doc";
 	}
 
 	/**
@@ -59,7 +55,7 @@
 	 */
 	public void testOpen() throws Exception {
 
-		HWPFDocument docA = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 	}
 
 	/**
@@ -67,7 +63,7 @@
 	 */
 	public void testDocStructure() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 		Range range;
 		Section section;
 		Paragraph para;
@@ -132,7 +128,7 @@
 	 */
 	public void testRangeDeleteOne() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
 		Range range = daDoc.getOverallRange();
 		assertEquals(1, range.numSections());
@@ -178,7 +174,7 @@
 	 */
 	public void testRangeDeleteAll() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
 		Range range = daDoc.getRange();
 		assertEquals(1, range.numSections());

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java Wed Aug 19 18:51:44 2009
@@ -17,11 +17,10 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.FileInputStream;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 /**
  *	Test to see if Range.insertBefore() works even if the Range contains a
@@ -40,10 +39,7 @@
 	private String illustrativeDocFile;
 
 	protected void setUp() {
-
-		String dirname = System.getProperty("HWPF.testdata.path");
-
-		illustrativeDocFile = dirname + "/testRangeInsertion.doc";
+		illustrativeDocFile = "testRangeInsertion.doc";
 	}
 
 	/**
@@ -51,7 +47,7 @@
 	 */
 	public void testOpen() throws Exception {
 
-		HWPFDocument docA = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 	}
 
 	/**
@@ -59,7 +55,7 @@
 	 */
 	public void testDocStructure() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
 		Range range = daDoc.getRange();
 
@@ -87,7 +83,7 @@
 	 */
 	public void testRangeInsertion() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
 		/*
 			Range range = daDoc.getRange();

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java Wed Aug 19 18:51:44 2009
@@ -17,11 +17,10 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.util.List;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.hwpf.model.PropertyNode;
 
 import junit.framework.TestCase;
@@ -66,16 +65,9 @@
 	private HWPFDocument u;
 	private HWPFDocument a;
 
-	private String dirname;
-
 	protected void setUp() throws Exception {
-		dirname = System.getProperty("HWPF.testdata.path");
-		u = new HWPFDocument(
-				new FileInputStream(new File(dirname, "HeaderFooterUnicode.doc"))
-		);
-		a = new HWPFDocument(
-				new FileInputStream(new File(dirname, "SampleDoc.doc"))
-		);
+		u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
+		a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
 	}
 
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java Wed Aug 19 18:51:44 2009
@@ -17,11 +17,10 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.FileInputStream;
-
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 /**
  *	Test to see if Range.replaceText() works even if the Range contains a
@@ -40,21 +39,14 @@
 		"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the Apache Software Foundation and all the POI contributors for their assistance in this matter.\r";
 	private String expectedText3 = "Thank you, Apache Software Foundation!\r";
 
-	private String illustrativeDocFile;
-
-	protected void setUp() {
-
-		String dirname = System.getProperty("HWPF.testdata.path");
-
-		illustrativeDocFile = dirname + "/testRangeReplacement.doc";
-	}
+	private String illustrativeDocFile = "testRangeReplacement.doc";
 
 	/**
 	 * Test just opening the files
 	 */
 	public void testOpen() throws Exception {
 
-		HWPFDocument docA = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 	}
 
 	/**
@@ -62,7 +54,7 @@
 	 */
 	public void testDocStructure() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
 		Range range = daDoc.getRange();
 		assertEquals(414, range.text().length());
@@ -91,7 +83,7 @@
 	 */
 	public void testRangeReplacementOne() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
 		Range range = daDoc.getRange();
 		assertEquals(1, range.numSections());
@@ -124,7 +116,7 @@
 	 */
 	public void testRangeReplacementAll() throws Exception {
 
-		HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));
+		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
 		Range range = daDoc.getRange();
 		assertEquals(1, range.numSections());

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java?rev=805928&r1=805927&r2=805928&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java Wed Aug 19 18:51:44 2009
@@ -19,24 +19,23 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
 
 /**
  * Test the shapes handling
  */
 public final class TestShapes extends TestCase {
-	private String dirname = System.getProperty("HWPF.testdata.path");
 
 	/**
 	 * two shapes, second is a group
 	 */
 	public void testShapes() throws Exception {
-		HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/WithArtShapes.doc"));
+		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("WithArtShapes.doc");
 
 		List shapes = doc.getShapesTable().getAllShapes();
 		List vshapes = doc.getShapesTable().getVisibleShapes();

Added: 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=805928&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java Wed Aug 19 18:51:44 2009
@@ -0,0 +1,182 @@
+/* ====================================================================
+   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;
+
+import java.io.*;
+
+/**
+ * Centralises logic for finding/opening sample files
+ *
+ */
+public abstract class POIDataSamples {
+
+    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;
+
+    /**
+     *
+     * @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
+     */
+    public POIDataSamples(String dir, String classPathTestFile){
+        _testDataDir = dir;
+        initialise(classPathTestFile);
+    }
+
+    /**
+     * Opens a sample file from the test data directory
+     *
+     * @param  sampleFileName the file to open
+     * @return an open <tt>InputStream</tt> for the specified sample file
+     */
+    public InputStream openResourceAsStream(String sampleFileName) {
+
+        if (_sampleDataIsAvaliableOnClassPath) {
+            InputStream result = sampleFileName == null ? null :
+                    openClasspathResource(sampleFileName);
+            if(result == null) {
+                throw new RuntimeException("specified test sample file '" + sampleFileName
+                        + "' not found on the classpath");
+            }
+            // 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 '"
+                    + _testDataDir
+                    + "' 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() + "'");
+        }
+        try {
+            if(!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);
+        }
+    }
+
+    /**
+     *
+     * @param classPathTest test file to check if the resources are avaiable from the classpath
+     */
+    private void initialise(String classPathTest) {
+        String dataDirName = System.getProperty(_testDataDir);
+        if (dataDirName == null) {
+            // check to see if we can just get the resources from the classpath
+            InputStream is = openClasspathResource(classPathTest);
+            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 '"
+                    + _testDataDir + "' before running tests");
+        }
+        File dataDir = new File(dataDirName);
+        if (!dataDir.exists()) {
+            throw new RuntimeException("Data dir '" + dataDirName
+                    + "' specified by system property '" + _testDataDir
+                    + "' 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.
+     *
+     * @param  sampleFileName the file to open
+     * @return <code>null</code> if the sample file is not deployed on the classpath.
+     */
+    private InputStream openClasspathResource(String sampleFileName) {
+        return getClass().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();
+        }
+    }
+
+    /**
+     * @param  fileName the file to open
+     * @return byte array of sample file content from file found in standard hssf test data dir
+     */
+    public byte[] readFile(String fileName) {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+        try {
+            InputStream fis = openResourceAsStream(fileName);
+
+            byte[] buf = new byte[512];
+            while (true) {
+                int bytesRead = fis.read(buf);
+                if (bytesRead < 1) {
+                    break;
+                }
+                bos.write(buf, 0, bytesRead);
+            }
+            fis.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return bos.toByteArray();
+    }
+
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/POIDataSamples.java
------------------------------------------------------------------------------
    svn:executable = *



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