poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r645483 [6/7] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/cf/ src/java/org/apache/poi/hssf/usermodel/ src/java/org/apache/poi/util/ src/testcases/org...
Date Mon, 07 Apr 2008 12:52:00 GMT
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java Mon Apr  7 05:51:50 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,17 +14,9 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.usermodel;
 
-import junit.framework.TestCase;
-
-import org.apache.poi.hssf.util.AreaReference;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.TempFile;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -33,6 +24,12 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.util.AreaReference;
+import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.util.TempFile;
 
 /**
  * 
@@ -41,115 +38,69 @@
  * @author Danny Mui (danny at muibros.com)
  * @author Amol S. Deshmukh < amol at ap ache dot org > 
  */
-public class TestNamedRange
-    extends TestCase {
-    
-    public TestNamedRange(String testName) {
-        super(testName);
-    }
-    
-    public static void main(java.lang.String[] args) {
-        String filename = System.getProperty("HSSF.testdata.path");
-        
-        // assume andy is running this in the debugger
-        if (filename == null)
-        {
-            if (args != null && args.length == 1) {
-            System.setProperty(
-                "HSSF.testdata.path",
-                args[0]);
-            } else {
-                System.err.println("Geesh, no HSSF.testdata.path system " +
-                          "property, no command line arg with the path "+
-                          "what do you expect me to do, guess where teh data " +
-                          "files are?  Sorry, I give up!");
-                                   
-            }
-            
-        }
-        
-        
-        junit.textui.TestRunner.run(TestNamedRange.class);
-    }
-    
-    /** Test of TestCase method, of class test.RangeTest. */
-    public void testNamedRange() 
-        throws IOException
-    {
-        FileInputStream fis = null;
-        POIFSFileSystem fs  = null;
-        HSSFWorkbook wb     = null;
-        
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/Simple.xls";
-        
-        
-        fis = new FileInputStream(filename);
-        fs = new POIFSFileSystem(fis);
-        wb = new HSSFWorkbook(fs);
-        
-        
-        //Creating new Named Range
-        HSSFName newNamedRange = wb.createName();
-        
-        //Getting Sheet Name for the reference
-        String sheetName = wb.getSheetName(0);
-        
-        //Setting its name
-        newNamedRange.setNameName("RangeTest");
-        //Setting its reference
-        newNamedRange.setReference(sheetName + "!$D$4:$E$8");
+public final class TestNamedRange extends TestCase {
+
+	private static HSSFWorkbook openSample(String sampleFileName) {
+		return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+	}
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(TestNamedRange.class);
+	}
+
+	/** Test of TestCase method, of class test.RangeTest. */
+	public void testNamedRange() 
+		throws IOException
+	{
+		HSSFWorkbook wb = openSample("Simple.xls");
+
+		//Creating new Named Range
+		HSSFName newNamedRange = wb.createName();
+
+		//Getting Sheet Name for the reference
+		String sheetName = wb.getSheetName(0);
+
+		//Setting its name
+		newNamedRange.setNameName("RangeTest");
+		//Setting its reference
+		newNamedRange.setReference(sheetName + "!$D$4:$E$8");
   
-        //Getting NAmed Range
-        HSSFName namedRange1 = wb.getNameAt(0);
-        //Getting it sheet name
-        sheetName = namedRange1.getSheetName();
-        //Getting its reference
-        String referece = namedRange1.getReference();
-
-        // sanity check
-        SanityChecker c = new SanityChecker();
-        c.checkHSSFWorkbook(wb);
-
-        File             file = TempFile.createTempFile("testNamedRange",
-                                        ".xls");
-
-        FileOutputStream fileOut = new FileOutputStream(file);
-        wb.write(fileOut);
-        fis.close();
-        fileOut.close();
-        
-        assertTrue("file exists",file.exists());
-            
-        FileInputStream in = new FileInputStream(file);
-        wb = new HSSFWorkbook(in);
-        HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
-        assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
-        assertEquals(wb.getSheetName(0)+"!$D$4:$E$8", nm.getReference());
-        
-        
-    }
-     
-    /**
-     * Reads an excel file already containing a named range.
-     * <p>
+		//Getting NAmed Range
+		HSSFName namedRange1 = wb.getNameAt(0);
+		//Getting it sheet name
+		sheetName = namedRange1.getSheetName();
+		//Getting its reference
+		String referece = namedRange1.getReference();
+
+		// sanity check
+		SanityChecker c = new SanityChecker();
+		c.checkHSSFWorkbook(wb);
+
+		File file = TempFile.createTempFile("testNamedRange", ".xls");
+
+		FileOutputStream fileOut = new FileOutputStream(file);
+		wb.write(fileOut);
+
+		fileOut.close();
+
+		assertTrue("file exists",file.exists());
+
+		FileInputStream in = new FileInputStream(file);
+		wb = new HSSFWorkbook(in);
+		HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
+		assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
+		assertEquals(wb.getSheetName(0)+"!$D$4:$E$8", nm.getReference());
+
+
+	}
+	 
+	/**
+	 * Reads an excel file already containing a named range.
+	 * <p>
 	 * Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=9632" target="_bug">#9632</a>
-     */   
-	public void testNamedRead() throws IOException
-	{        
-		FileInputStream fis = null;
- 	 	POIFSFileSystem fs  = null;
-		HSSFWorkbook wb     = null;
-        
-		String filename = System.getProperty("HSSF.testdata.path");
-
-		filename = filename + "/namedinput.xls";
-        
-        
-		fis = new FileInputStream(filename);
-		fs = new POIFSFileSystem(fis);
-		wb = new HSSFWorkbook(fs);
+	 */   
+	public void testNamedRead() {
+		HSSFWorkbook wb = openSample("namedinput.xls");
 
 		//Get index of the namedrange with the name = "NamedRangeName" , which was defined in input.xls as A1:D10
 		int NamedRangeIndex	 = wb.getNameIndex("NamedRangeName");
@@ -161,103 +112,86 @@
 		//Getting its reference
 		String reference = namedRange1.getReference();
 		 
-		fis.close();
-		 
 		assertEquals(sheetName+"!$A$1:$D$10", reference);
-		
+
 		HSSFName namedRange2 = wb.getNameAt(1);
-		
+
 		assertEquals(sheetName+"!$D$17:$G$27", namedRange2.getReference());
 		assertEquals("SecondNamedRange", namedRange2.getNameName());
-		
 	}
-        
-    /**
-     * Reads an excel file already containing a named range and updates it
-     * <p>
-     * Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=16411" target="_bug">#16411</a>
-     */
-    public void testNamedReadModify() throws IOException
-    {
-		FileInputStream fis = null;
-		POIFSFileSystem fs  = null;
-		HSSFWorkbook wb     = null;
-        
-		String filename = System.getProperty("HSSF.testdata.path");
-
-		filename = filename + "/namedinput.xls";
-        
-        
-		fis = new FileInputStream(filename);
-		fs = new POIFSFileSystem(fis);
-		wb = new HSSFWorkbook(fs);
-    	
-    	
+
+	/**
+	 * Reads an excel file already containing a named range and updates it
+	 * <p>
+	 * Addresses Bug <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=16411" target="_bug">#16411</a>
+	 */
+	public void testNamedReadModify() {
+		HSSFWorkbook wb = openSample("namedinput.xls");
+
 		HSSFName name = wb.getNameAt(0);
 		String sheetName = wb.getSheetName(0);
-		
+
 		assertEquals(sheetName+"!$A$1:$D$10", name.getReference());
-		
-		name = wb.getNameAt(1);		
+
+		name = wb.getNameAt(1);
 		String newReference = sheetName +"!$A$1:$C$36"; 
 		 
-		name.setReference(newReference);		
+		name.setReference(newReference);
 		assertEquals(newReference, name.getReference()); 
+	}
 
-    }
-        
 	/**
 	 * Test that multiple named ranges can be added written and read
 	 */
 	public void testMultipleNamedWrite() 
-	    throws IOException
+		throws IOException
 	{
-	    HSSFWorkbook wb     = new HSSFWorkbook();
-         
+		HSSFWorkbook wb	 = new HSSFWorkbook();
+		 
 
 		HSSFSheet sheet = wb.createSheet("testSheet1");
 		String sheetName = wb.getSheetName(0);
-        
-        assertEquals("testSheet1", sheetName);
-         
+
+		assertEquals("testSheet1", sheetName);
+		 
 		//Creating new Named Range
 		HSSFName newNamedRange = wb.createName();
 
 		newNamedRange.setNameName("RangeTest");
-	    newNamedRange.setReference(sheetName + "!$D$4:$E$8");
+		newNamedRange.setReference(sheetName + "!$D$4:$E$8");
+
+		//Creating another new Named Range
+		HSSFName newNamedRange2 = wb.createName();
+
+		newNamedRange2.setNameName("AnotherTest");
+		newNamedRange2.setReference(sheetName + "!$F$1:$G$6");
+
 
-	    //Creating another new Named Range
-	    HSSFName newNamedRange2 = wb.createName();
-	    
-	    newNamedRange2.setNameName("AnotherTest");
-	    newNamedRange2.setReference(sheetName + "!$F$1:$G$6");
-	    
-	    
 		HSSFName namedRange1 = wb.getNameAt(0);
 		String referece = namedRange1.getReference();
-                                
-	    File file = TempFile.createTempFile("testMultiNamedRange", ".xls");
+
+		File file = TempFile.createTempFile("testMultiNamedRange", ".xls");
  
 		FileOutputStream fileOut = new FileOutputStream(file);
 		wb.write(fileOut);
 		fileOut.close();
-		
-         
+
+		 
 		assertTrue("file exists",file.exists());
-            
-	    
+
+
 		FileInputStream in = new FileInputStream(file);
 		wb = new HSSFWorkbook(in);
 		HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest"));
 		assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName()));
 		assertTrue("Reference is "+nm.getReference(),(wb.getSheetName(0)+"!$D$4:$E$8").equals(nm.getReference()));
-         
-	    nm = wb.getNameAt(wb.getNameIndex("AnotherTest"));
-	    assertTrue("Name is "+nm.getNameName(),"AnotherTest".equals(nm.getNameName()));
-	    assertTrue("Reference is "+nm.getReference(),newNamedRange2.getReference().equals(nm.getReference()));        
-	    
-	    
-	}    
+		 
+		nm = wb.getNameAt(wb.getNameIndex("AnotherTest"));
+		assertTrue("Name is "+nm.getNameName(),"AnotherTest".equals(nm.getNameName()));
+		assertTrue("Reference is "+nm.getReference(),newNamedRange2.getReference().equals(nm.getReference()));
+
+
+	}
 
 	/**
 	 * Test case provided by czhang@cambian.com (Chun Zhang)
@@ -268,7 +202,7 @@
 	public void testMultiNamedRange() 
 		 throws IOException
 	 {
-        
+
 		 // Create a new workbook
 		 HSSFWorkbook wb = new HSSFWorkbook ();
 
@@ -276,14 +210,14 @@
 		 // Create a worksheet 'sheet1' in the new workbook
 		 wb.createSheet ();
 		 wb.setSheetName (0, "sheet1");
-        
+
 		 // Create another worksheet 'sheet2' in the new workbook
 		 wb.createSheet ();
 		 wb.setSheetName (1, "sheet2");
-        
+
 		 // Create a new named range for worksheet 'sheet1'
 		 HSSFName namedRange1 = wb.createName();
-        
+
 		 // Set the name for the named range for worksheet 'sheet1'
 		 namedRange1.setNameName("RangeTest1");
 
@@ -292,21 +226,21 @@
 
 		 // Create a new named range for worksheet 'sheet2'
 		 HSSFName namedRange2 = wb.createName();
-        
+
 		 // Set the name for the named range for worksheet 'sheet2'
 		 namedRange2.setNameName("RangeTest2");
 
 		 // Set the reference for the named range for worksheet 'sheet2'
-		 namedRange2.setReference("sheet2" + "!$A$1:$O$21");        
+		 namedRange2.setReference("sheet2" + "!$A$1:$O$21");
  
 		 // Write the workbook to a file
 		 File file = TempFile.createTempFile("testMuiltipletNamedRanges", ".xls");
 		 FileOutputStream fileOut = new FileOutputStream(file);
 		 wb.write(fileOut);
 		 fileOut.close();
-        
+
 		 assertTrue("file exists",file.exists());
-            
+
 		 // Read the Excel file and verify its content
 		 FileInputStream in = new FileInputStream(file);
 		 wb = new HSSFWorkbook(in);
@@ -317,42 +251,42 @@
 		 HSSFName nm2 =wb.getNameAt(wb.getNameIndex("RangeTest2"));
 		 assertTrue("Name is "+nm2.getNameName(),"RangeTest2".equals(nm2.getNameName()));
 		 assertTrue("Reference is "+nm2.getReference(),(wb.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getReference()));
-	 }       
+	 }	   
 
 	public void testUnicodeNamedRange() throws Exception {
-	    HSSFWorkbook workBook = new HSSFWorkbook();
-	    HSSFSheet sheet = workBook.createSheet("Test");
-	    HSSFName name = workBook.createName();
-	    name.setNameName("\u03B1");
-	    name.setReference("Test!$D$3:$E$8");
-	    
-	    ByteArrayOutputStream out = new ByteArrayOutputStream();
-	    workBook.write(out);
-	    
-	    HSSFWorkbook workBook2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
-	    HSSFName name2 = workBook2.getNameAt(0);
-	    
-	    assertEquals("\u03B1", name2.getNameName());
-	    assertEquals("Test!$D$3:$E$8", name2.getReference());
+		HSSFWorkbook workBook = new HSSFWorkbook();
+		HSSFSheet sheet = workBook.createSheet("Test");
+		HSSFName name = workBook.createName();
+		name.setNameName("\u03B1");
+		name.setReference("Test!$D$3:$E$8");
+
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		workBook.write(out);
+
+		HSSFWorkbook workBook2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		HSSFName name2 = workBook2.getNameAt(0);
+
+		assertEquals("\u03B1", name2.getNameName());
+		assertEquals("Test!$D$3:$E$8", name2.getReference());
 	}
-        
+
 	 /**
 	  * Test to see if the print areas can be retrieved/created in memory
 	  */
 	 public void testSinglePrintArea()
 	 {
-	     HSSFWorkbook workbook = new HSSFWorkbook();        
-	     HSSFSheet sheet = workbook.createSheet("Test Print Area");                
-	     String sheetName = workbook.getSheetName(0);
-	     
-	     String reference = sheetName+"!$A$1:$B$1";
-	     workbook.setPrintArea(0, reference);
-	             
-	     String retrievedPrintArea = workbook.getPrintArea(0);
-	    
-	 	 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-	     assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-	     
+		 HSSFWorkbook workbook = new HSSFWorkbook();
+		 HSSFSheet sheet = workbook.createSheet("Test Print Area");
+		 String sheetName = workbook.getSheetName(0);
+		 
+		 String reference = sheetName+"!$A$1:$B$1";
+		 workbook.setPrintArea(0, reference);
+				 
+		 String retrievedPrintArea = workbook.getPrintArea(0);
+
+	 	 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+		 assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
+		 
 	 }
 
 	 /**
@@ -360,53 +294,31 @@
 	  */
 	 public void testSinglePrintAreaWOSheet()
 	 {
-		 HSSFWorkbook workbook = new HSSFWorkbook();        
-		 HSSFSheet sheet = workbook.createSheet("Test Print Area");                
+		 HSSFWorkbook workbook = new HSSFWorkbook();
+		 HSSFSheet sheet = workbook.createSheet("Test Print Area");
 		 String sheetName = workbook.getSheetName(0);
-	     
+		 
 		 String reference = "$A$1:$B$1";
 		 workbook.setPrintArea(0, reference);
-	             
+				 
 		 String retrievedPrintArea = workbook.getPrintArea(0);
-	    
-		 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
+
+		 assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
 		 assertEquals("'" + sheetName + "'!" + reference, retrievedPrintArea);
-	     
+		 
 	 }
 
 
 	 /**
 	  * Test to see if the print area can be retrieved from an excel created file
 	  */
-	 public void testPrintAreaFileRead()
-	 throws IOException
-	 {
-		FileInputStream fis = null;
-		POIFSFileSystem fs  = null;
-		HSSFWorkbook workbook     = null;
-        
-		String filename = System.getProperty("HSSF.testdata.path");
-
-		filename = filename + "/SimpleWithPrintArea.xls";
-        
-        try {
-        
-			fis = new FileInputStream(filename);
-			fs = new POIFSFileSystem(fis);
-			workbook = new HSSFWorkbook(fs);
-			
-			String sheetName = workbook.getSheetName(0);
-			String reference = sheetName+"!$A$1:$C$5";
-			
-			assertEquals(reference, workbook.getPrintArea(0));
-		
-        } finally {
-			fis.close();
-		
-        }
-		
-		     
-         
+	 public void testPrintAreaFileRead() {
+		 HSSFWorkbook workbook = openSample("SimpleWithPrintArea.xls");
+
+		String sheetName = workbook.getSheetName(0);
+		String reference = sheetName+"!$A$1:$C$5";
+
+		assertEquals(reference, workbook.getPrintArea(0));
 	}
 
 
@@ -416,29 +328,29 @@
 	 public void testPrintAreaFile()
 	 throws IOException
 	 {
-	 	HSSFWorkbook workbook = new HSSFWorkbook();        
-	 	HSSFSheet sheet = workbook.createSheet("Test Print Area");                
+	 	HSSFWorkbook workbook = new HSSFWorkbook();
+	 	HSSFSheet sheet = workbook.createSheet("Test Print Area");
 	 	String sheetName = workbook.getSheetName(0);
-	     
+		 
 	 
 	 	String reference = sheetName+"!$A$1:$B$1";
 	 	workbook.setPrintArea(0, reference);
-	     
-	    File file = TempFile.createTempFile("testPrintArea",".xls");
-	     
-	    FileOutputStream fileOut = new FileOutputStream(file);
-	    workbook.write(fileOut);
-	    fileOut.close();
-	     
-	    assertTrue("file exists",file.exists());
-	     
-	    FileInputStream in = new FileInputStream(file);
-	    workbook = new HSSFWorkbook(in);
-	     
-	 	String retrievedPrintArea = workbook.getPrintArea(0);       
-	 	assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
+		 
+		File file = TempFile.createTempFile("testPrintArea",".xls");
+		 
+		FileOutputStream fileOut = new FileOutputStream(file);
+		workbook.write(fileOut);
+		fileOut.close();
+		 
+		assertTrue("file exists",file.exists());
+		 
+		FileInputStream in = new FileInputStream(file);
+		workbook = new HSSFWorkbook(in);
+		 
+	 	String retrievedPrintArea = workbook.getPrintArea(0);	   
+	 	assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
 	 	assertEquals("References Match", "'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
-         
+		 
 	}
 
 	/**
@@ -447,180 +359,178 @@
 	public void testMultiplePrintAreaFile()
 	throws IOException
 	{
-	    HSSFWorkbook workbook = new HSSFWorkbook();        
-	    
-	    HSSFSheet sheet = workbook.createSheet("Sheet1");
-	    sheet = workbook.createSheet("Sheet2");
-	    sheet = workbook.createSheet("Sheet3");
-	    
-	    String sheetName = workbook.getSheetName(0);
+		HSSFWorkbook workbook = new HSSFWorkbook();
+
+		HSSFSheet sheet = workbook.createSheet("Sheet1");
+		sheet = workbook.createSheet("Sheet2");
+		sheet = workbook.createSheet("Sheet3");
+
+		String sheetName = workbook.getSheetName(0);
 		String reference = null;
 
 		reference = sheetName+"!$A$1:$B$1";
 		workbook.setPrintArea(0, reference); 
 
 		sheetName = workbook.getSheetName(1);
-	    String reference2 = sheetName+"!$B$2:$D$5";
-	    workbook.setPrintArea(1, reference2);
+		String reference2 = sheetName+"!$B$2:$D$5";
+		workbook.setPrintArea(1, reference2);
 
 		sheetName = workbook.getSheetName(2);
 		String reference3 = sheetName+"!$D$2:$F$5";
 		workbook.setPrintArea(2, reference3);
-	    
-	    File file = TempFile.createTempFile("testMultiPrintArea",".xls");        
-	    
-	    FileOutputStream fileOut = new FileOutputStream(file);
-	    workbook.write(fileOut);
-	    fileOut.close();
-	    
-	    assertTrue("file exists",file.exists());
-	    
-	    FileInputStream in = new FileInputStream(file);
-	    workbook = new HSSFWorkbook(in);
-	    
-	    String retrievedPrintArea = workbook.getPrintArea(0);        
-	    assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
-	    assertEquals(reference, retrievedPrintArea);
-	    
-		String retrievedPrintArea2 = workbook.getPrintArea(1);        
-	    assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea2);
-	    assertEquals(reference2, retrievedPrintArea2);
-		
-		String retrievedPrintArea3 = workbook.getPrintArea(2);        
-	    assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea3);
-	    assertEquals(reference3, retrievedPrintArea3);
-	    
-	    
-	}
-    
-    /**
-     * Tests the setting of print areas with coordinates (Row/Column designations)
-     *
-     */
-    public void testPrintAreaCoords(){
-		HSSFWorkbook workbook = new HSSFWorkbook();        
-		HSSFSheet sheet = workbook.createSheet("Test Print Area");                
+
+		File file = TempFile.createTempFile("testMultiPrintArea",".xls");
+
+		FileOutputStream fileOut = new FileOutputStream(file);
+		workbook.write(fileOut);
+		fileOut.close();
+
+		assertTrue("file exists",file.exists());
+
+		FileInputStream in = new FileInputStream(file);
+		workbook = new HSSFWorkbook(in);
+
+		String retrievedPrintArea = workbook.getPrintArea(0);
+		assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea);
+		assertEquals(reference, retrievedPrintArea);
+
+		String retrievedPrintArea2 = workbook.getPrintArea(1);
+		assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea2);
+		assertEquals(reference2, retrievedPrintArea2);
+
+		String retrievedPrintArea3 = workbook.getPrintArea(2);
+		assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea3);
+		assertEquals(reference3, retrievedPrintArea3);
+
+
+	}
+
+	/**
+	 * Tests the setting of print areas with coordinates (Row/Column designations)
+	 *
+	 */
+	public void testPrintAreaCoords(){
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet("Test Print Area");
 		String sheetName = workbook.getSheetName(0);
-	     
+		 
 		String reference = sheetName+"!$A$1:$B$1";
 		workbook.setPrintArea(0, 0, 1, 0, 0);
-	             
+				 
 		String retrievedPrintArea = workbook.getPrintArea(0);
-	    
-		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-		assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);    	
-    }
-
-    
-    /**
-     * Tests the parsing of union area expressions, and re-display in the presence of sheet names
-     * with special characters.
-     */
-    public void testPrintAreaUnion(){
-		HSSFWorkbook workbook = new HSSFWorkbook();        
-		HSSFSheet sheet = workbook.createSheet("Test Print Area");                
+
+		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+		assertEquals("'" + sheetName + "'!$A$1:$B$1", retrievedPrintArea);
+	}
+
+
+	/**
+	 * Tests the parsing of union area expressions, and re-display in the presence of sheet names
+	 * with special characters.
+	 */
+	public void testPrintAreaUnion(){
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet("Test Print Area");
 		String sheetName = workbook.getSheetName(0);
-		
+
  
-		String reference =       sheetName +  "!$A$1:$B$1, " + sheetName + "!$D$1:$F$2";
+		String reference =	   sheetName +  "!$A$1:$B$1, " + sheetName + "!$D$1:$F$2";
 		String expResult = "'" + sheetName + "'!$A$1:$B$1,'" + sheetName + "'!$D$1:$F$2";
 		workbook.setPrintArea(0, reference);
-	             
+				 
 		String retrievedPrintArea = workbook.getPrintArea(0);
-	    
-		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-		assertEquals(expResult, retrievedPrintArea);    	
-    }
-    
-    /**
-     * Verifies an existing print area is deleted
-     *
-     */
-    public void testPrintAreaRemove() {
-		HSSFWorkbook workbook = new HSSFWorkbook();        
-		HSSFSheet sheet = workbook.createSheet("Test Print Area");                
+
+		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+		assertEquals(expResult, retrievedPrintArea);
+	}
+
+	/**
+	 * Verifies an existing print area is deleted
+	 *
+	 */
+	public void testPrintAreaRemove() {
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet("Test Print Area");
 		String sheetName = workbook.getSheetName(0);
-	     
+		 
 		String reference = sheetName+"!$A$1:$B$1";
 		workbook.setPrintArea(0, 0, 1, 0, 0);
-	             
+				 
 		String retrievedPrintArea = workbook.getPrintArea(0);
-	    
-		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);        
-    	
-    	workbook.removePrintArea(0);
-    	assertNull("PrintArea was not removed", workbook.getPrintArea(0)); 
-    }
-    
-    /**
-     * Verifies correct functioning for "single cell named range" (aka "named cell")
-     */
-    public void testNamedCell_1() {
-        
-        // setup for this testcase
-        String sheetName = "Test Named Cell";
-        String cellName = "A name for a named cell";
-        String cellValue = "TEST Value";
-        HSSFWorkbook wb = new HSSFWorkbook();        
-        HSSFSheet sheet = wb.createSheet(sheetName);
-        sheet.createRow(0).createCell((short) 0).setCellValue(cellValue);
-         
-        // create named range for a single cell using areareference
-        HSSFName namedCell = wb.createName();
-        namedCell.setNameName(cellName);
-        String reference = sheetName+"!A1:A1";
-        namedCell.setReference(reference);
-        
-        // retrieve the newly created named range
-        int namedCellIdx = wb.getNameIndex(cellName);
-        HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
-        assertNotNull(aNamedCell);
-        
-        // retrieve the cell at the named range and test its contents
-        AreaReference aref = new AreaReference(aNamedCell.getReference());
-        assertTrue("Should be exactly 1 cell in the named cell :'" +cellName+"'", aref.isSingleCell());
-        
-        CellReference cref = aref.getFirstCell();
-        assertNotNull(cref);
-        HSSFSheet s = wb.getSheet(cref.getSheetName());
-        assertNotNull(s);
-        HSSFRow r = sheet.getRow(cref.getRow());
-        HSSFCell c = r.getCell(cref.getCol());
-        String contents = c.getRichStringCellValue().getString();
-        assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
-    }
-
-    /**
-     * Verifies correct functioning for "single cell named range" (aka "named cell")
-     */
-    public void testNamedCell_2() {
-        
-        // setup for this testcase
-        String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet(sname);
-        sheet.createRow(0).createCell((short) 0).setCellValue(cvalue);
-         
-        // create named range for a single cell using cellreference
-        HSSFName namedCell = wb.createName();
-        namedCell.setNameName(cname);
-        String reference = sname+"!A1";
-        namedCell.setReference(reference);
-        
-        // retrieve the newly created named range
-        int namedCellIdx = wb.getNameIndex(cname);
-        HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
-        assertNotNull(aNamedCell);
-        
-        // retrieve the cell at the named range and test its contents
-        CellReference cref = new CellReference(aNamedCell.getReference());
-        assertNotNull(cref);
-        HSSFSheet s = wb.getSheet(cref.getSheetName());
-        HSSFRow r = sheet.getRow(cref.getRow());
-        HSSFCell c = r.getCell(cref.getCol());
-        String contents = c.getStringCellValue();
-        assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
-    }
 
-}
+		assertNotNull("Print Area not defined for first sheet", retrievedPrintArea);
+
+		workbook.removePrintArea(0);
+		assertNull("PrintArea was not removed", workbook.getPrintArea(0)); 
+	}
+
+	/**
+	 * Verifies correct functioning for "single cell named range" (aka "named cell")
+	 */
+	public void testNamedCell_1() {
+
+		// setup for this testcase
+		String sheetName = "Test Named Cell";
+		String cellName = "A name for a named cell";
+		String cellValue = "TEST Value";
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet sheet = wb.createSheet(sheetName);
+		sheet.createRow(0).createCell((short) 0).setCellValue(cellValue);
+		 
+		// create named range for a single cell using areareference
+		HSSFName namedCell = wb.createName();
+		namedCell.setNameName(cellName);
+		String reference = sheetName+"!A1:A1";
+		namedCell.setReference(reference);
+
+		// retrieve the newly created named range
+		int namedCellIdx = wb.getNameIndex(cellName);
+		HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
+		assertNotNull(aNamedCell);
+
+		// retrieve the cell at the named range and test its contents
+		AreaReference aref = new AreaReference(aNamedCell.getReference());
+		assertTrue("Should be exactly 1 cell in the named cell :'" +cellName+"'", aref.isSingleCell());
+
+		CellReference cref = aref.getFirstCell();
+		assertNotNull(cref);
+		HSSFSheet s = wb.getSheet(cref.getSheetName());
+		assertNotNull(s);
+		HSSFRow r = sheet.getRow(cref.getRow());
+		HSSFCell c = r.getCell(cref.getCol());
+		String contents = c.getRichStringCellValue().getString();
+		assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
+	}
+
+	/**
+	 * Verifies correct functioning for "single cell named range" (aka "named cell")
+	 */
+	public void testNamedCell_2() {
 
+		// setup for this testcase
+		String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet sheet = wb.createSheet(sname);
+		sheet.createRow(0).createCell((short) 0).setCellValue(cvalue);
+		 
+		// create named range for a single cell using cellreference
+		HSSFName namedCell = wb.createName();
+		namedCell.setNameName(cname);
+		String reference = sname+"!A1";
+		namedCell.setReference(reference);
+
+		// retrieve the newly created named range
+		int namedCellIdx = wb.getNameIndex(cname);
+		HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
+		assertNotNull(aNamedCell);
+
+		// retrieve the cell at the named range and test its contents
+		CellReference cref = new CellReference(aNamedCell.getReference());
+		assertNotNull(cref);
+		HSSFSheet s = wb.getSheet(cref.getSheetName());
+		HSSFRow r = sheet.getRow(cref.getRow());
+		HSSFCell c = r.getCell(cref.getCol());
+		String contents = c.getStringCellValue();
+		assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
+	}
+}

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java Mon Apr  7 05:51:50 2008
@@ -17,36 +17,28 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.util.List;
 
 import junit.framework.TestCase;
 
-public class TestOLE2Embeding extends TestCase {
-    public void testEmbeding() throws Exception {
-        String dirname = System.getProperty("HSSF.testdata.path");
-        String filename = dirname + "/ole2-embedding.xls";
-
-        File file = new File(filename);
-        FileInputStream in = new FileInputStream(file);
-        HSSFWorkbook workbook;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 
-        // This used to break, until bug #43116 was fixed
-        workbook = new HSSFWorkbook(in);
+/**
+ * 
+ */
+public final class TestOLE2Embeding extends TestCase {
 
-        in.close();
+    public void testEmbeding() {
+        // This used to break, until bug #43116 was fixed
+        HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
 
         // Check we can get at the Escher layer still
         workbook.getAllPictures();
     }
 
     public void testEmbeddedObjects() throws Exception {
-        String dirname = System.getProperty("HSSF.testdata.path");
-        String filename = dirname + "/ole2-embedding.xls";
+        HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls");
 
-        File file = new File(filename);
-        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(file));
         List objects = workbook.getAllEmbeddedObjects();
         assertEquals("Wrong number of objects", 2, objects.size());
         assertEquals("Wrong name for first object", "MBD06CAB431",
@@ -56,6 +48,5 @@
                 ((HSSFObjectData)
                 objects.get(1)).getDirectory().getName());
     }
-
 }
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java Mon Apr  7 05:51:50 2008
@@ -17,32 +17,31 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hpsf.SummaryInformation;
-import org.apache.poi.hpsf.PropertySetFactory;
-
-import java.io.FileInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hpsf.PropertySetFactory;
+import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
 /**
  * Old-style setting of POIFS properties doesn't work with POI 3.0.2
  *
  * @author Yegor Kozlov
  */
 public class TestPOIFSProperties extends TestCase{
-    protected String cwd = System.getProperty("HSSF.testdata.path");
 
-    protected String title = "Testing POIFS properties";
+    private static final String title = "Testing POIFS properties";
 
     public void testFail() throws Exception {
-        FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls"));
+        InputStream is = HSSFTestDataSamples.openSampleFileStream("Simple.xls");
         POIFSFileSystem fs = new POIFSFileSystem(is);
-        is.close();
 
         HSSFWorkbook wb = new HSSFWorkbook(fs);
 
@@ -62,19 +61,13 @@
         POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
         SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
 
-        try {
-            //failing assertion
-            assertEquals(title, summary2.getTitle());
-
-        } catch (AssertionError e){
-            assertTrue(true);
-        }
+        //failing assertion
+        assertEquals(title, summary2.getTitle());
     }
 
     public void testOK() throws Exception {
-        FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls"));
+        InputStream is = HSSFTestDataSamples.openSampleFileStream("Simple.xls");
         POIFSFileSystem fs = new POIFSFileSystem(is);
-        is.close();
 
         //set POIFS properties before constructing HSSFWorkbook
         SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java Mon Apr  7 05:51:50 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,47 +14,29 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.usermodel;
 
+import java.util.GregorianCalendar;
+import java.util.List;
+
 import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.record.BOFRecord;
 import org.apache.poi.hssf.record.EOFRecord;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-
-import java.io.FileInputStream;
-import java.util.GregorianCalendar;
-import java.util.List;
 
 /**
  * @author Glen Stampoultzis (glens at apache.org)
  */
-
-public class TestReadWriteChart
-    extends TestCase
-{
-    public TestReadWriteChart(String s)
-    {
-        super(s);
-    }
+public final class TestReadWriteChart extends TestCase {
 
     /**
      * In the presence of a chart we need to make sure BOF/EOF records still exist.
      */
-
-    public void testBOFandEOFRecords()
-        throws Exception
-    {
-        //System.out.println("made it in testBOFandEOF");
-        String          path      = System.getProperty("HSSF.testdata.path");
-        String          filename  = path + "/SimpleChart.xls";
-        //System.out.println("path is "+path);
-        POIFSFileSystem fs        =
-            new POIFSFileSystem(new FileInputStream(filename));
-        //System.out.println("opened file");
-        HSSFWorkbook    workbook  = new HSSFWorkbook(fs);
+    public void testBOFandEOFRecords() {
+        HSSFWorkbook workbook  = HSSFTestDataSamples.openSampleWorkbook("SimpleChart.xls");
         HSSFSheet       sheet     = workbook.getSheetAt(0);
         HSSFRow         firstRow  = sheet.getRow(0);
         HSSFCell        firstCell = firstRow.getCell(( short ) 0);
@@ -77,29 +58,7 @@
         assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
     }
     
-    public static void main(String [] args)
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        // assume andy is running this in the debugger
-        if (filename == null)
-        {
-            if (args != null && args[0].length() == 1) {
-            System.setProperty(
-                "HSSF.testdata.path",
-                args[0]);
-            } else {
-                System.err.println("Geesh, no HSSF.testdata.path system " +
-                          "property, no command line arg with the path "+
-                          "what do you expect me to do, guess where teh data " +
-                          "files are?  Sorry, I give up!");
-                                   
-            }
-            
-        }
-        System.out
-            .println("Testing org.apache.poi.hssf.usermodel.TestReadWriteChart");
+    public static void main(String [] args) {
         junit.textui.TestRunner.run(TestReadWriteChart.class);
     }
-    
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java Mon Apr  7 05:51:50 2008
@@ -14,40 +14,28 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
+
 package org.apache.poi.hssf.usermodel;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 
 /**
  * Tests for how HSSFWorkbook behaves with XLS files
  *  with a WORKBOOK directory entry (instead of the more
  *  usual, Workbook)
  */
-public class TestSheetHiding extends TestCase {
-	private String dirPath;
-	private String xlsHidden = "TwoSheetsOneHidden.xls";
-	private String xlsShown  = "TwoSheetsNoneHidden.xls";
+public final class TestSheetHiding extends TestCase {
 	private HSSFWorkbook wbH;
 	private HSSFWorkbook wbU;
 
-	protected void setUp() throws Exception {
-		super.setUp();
-
-		dirPath = System.getProperty("HSSF.testdata.path");
-		FileInputStream isH = new FileInputStream(dirPath + "/" + xlsHidden);
-		POIFSFileSystem fsH = new POIFSFileSystem(isH);
-
-		FileInputStream isU = new FileInputStream(dirPath + "/" + xlsShown);
-		POIFSFileSystem fsU = new POIFSFileSystem(isU);
-
-		wbH = new HSSFWorkbook(fsH);
-		wbU = new HSSFWorkbook(fsU);
+	protected void setUp() {
+		wbH = HSSFTestDataSamples.openSampleWorkbook("TwoSheetsOneHidden.xls");
+		wbU = HSSFTestDataSamples.openSampleWorkbook("TwoSheetsNoneHidden.xls");
 	}
 
 	/**

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java Mon Apr  7 05:51:50 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,20 +14,15 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.usermodel;
 
-import junit.framework.TestCase;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.util.TempFile;
-
-import java.io.File;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
 
 /**
  * Tests row shifting capabilities.
@@ -37,16 +31,7 @@
  * @author Shawn Laubach (slaubach at apache dot com)
  * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
  */
-
-public class TestSheetShiftRows extends TestCase {
-
-    /**
-     * Constructor for TestSheetShiftRows.
-     * @param arg0
-     */
-    public TestSheetShiftRows(String arg0) {
-	super(arg0);
-    }
+public final class TestSheetShiftRows extends TestCase {
 
     /**
      * Tests the shiftRows function.  Does three different shifts.
@@ -59,25 +44,16 @@
     public void testShiftRows() throws Exception
     {
         // Read initial file in
-        String filename = System.getProperty( "HSSF.testdata.path" );
-        filename = filename + "/SimpleMultiCell.xls";
-        FileInputStream fin = new FileInputStream( filename );
-        HSSFWorkbook wb = new HSSFWorkbook( fin );
-        fin.close();
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleMultiCell.xls");
         HSSFSheet s = wb.getSheetAt( 0 );
 
         // Shift the second row down 1 and write to temp file
         s.shiftRows( 1, 1, 1 );
-        File tempFile = TempFile.createTempFile( "shift", "test.xls" );
-        FileOutputStream fout = new FileOutputStream( tempFile );
-        wb.write( fout );
-        fout.close();
+
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 
         // Read from temp file and check the number of cells in each
         // row (in original file each row was unique)
-        fin = new FileInputStream( tempFile );
-        wb = new HSSFWorkbook( fin );
-        fin.close();
         s = wb.getSheetAt( 0 );
 
         assertEquals( s.getRow( 0 ).getPhysicalNumberOfCells(), 1 );
@@ -89,15 +65,9 @@
         // Shift rows 1-3 down 3 in the current one.  This tests when
         // 1 row is blank.  Write to a another temp file
         s.shiftRows( 0, 2, 3 );
-        tempFile = TempFile.createTempFile( "shift", "test.xls" );
-        fout = new FileOutputStream( tempFile );
-        wb.write( fout );
-        fout.close();
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
 
         // Read and ensure things are where they should be
-        fin = new FileInputStream( tempFile );
-        wb = new HSSFWorkbook( fin );
-        fin.close();
         s = wb.getSheetAt( 0 );
         assertTrue( s.getRow( 0 ) == null || s.getRow( 0 ).getPhysicalNumberOfCells() == 0 );
         assertTrue( s.getRow( 1 ) == null || s.getRow( 1 ).getPhysicalNumberOfCells() == 0 );
@@ -107,22 +77,12 @@
         assertEquals( s.getRow( 5 ).getPhysicalNumberOfCells(), 2 );
 
         // Read the first file again
-        fin = new FileInputStream( filename );
-        wb = new HSSFWorkbook( fin );
-        fin.close();
+        wb = HSSFTestDataSamples.openSampleWorkbook("SimpleMultiCell.xls");
         s = wb.getSheetAt( 0 );
 
         // Shift rows 3 and 4 up and write to temp file
         s.shiftRows( 2, 3, -2 );
-        tempFile = TempFile.createTempFile( "shift", "test.xls" );
-        fout = new FileOutputStream( tempFile );
-        wb.write( fout );
-        fout.close();
-
-        // Read file and test
-        fin = new FileInputStream( tempFile );
-        wb = new HSSFWorkbook( fin );
-        fin.close();
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
         s = wb.getSheetAt( 0 );
         assertEquals( s.getRow( 0 ).getPhysicalNumberOfCells(), 3 );
         assertEquals( s.getRow( 1 ).getPhysicalNumberOfCells(), 4 );
@@ -137,11 +97,11 @@
      * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
      */
     public void testShiftRow(){
-   	HSSFWorkbook b = new HSSFWorkbook();
-   	HSSFSheet s    = b.createSheet();
-   	s.createRow(0).createCell((short)0).setCellValue("TEST1");
-   	s.createRow(3).createCell((short)0).setCellValue("TEST2");
-   	s.shiftRows(0,4,1);
+       HSSFWorkbook b = new HSSFWorkbook();
+       HSSFSheet s    = b.createSheet();
+       s.createRow(0).createCell((short)0).setCellValue("TEST1");
+       s.createRow(3).createCell((short)0).setCellValue("TEST2");
+       s.shiftRows(0,4,1);
     }
 
     /**
@@ -150,13 +110,13 @@
      * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
      */
     public void testShiftRow0(){
-   	HSSFWorkbook b = new HSSFWorkbook();
-   	HSSFSheet s    = b.createSheet();
-   	s.createRow(0).createCell((short)0).setCellValue("TEST1");
-   	s.createRow(3).createCell((short)0).setCellValue("TEST2");
-   	s.shiftRows(0,4,1);
+       HSSFWorkbook b = new HSSFWorkbook();
+       HSSFSheet s    = b.createSheet();
+       s.createRow(0).createCell((short)0).setCellValue("TEST1");
+       s.createRow(3).createCell((short)0).setCellValue("TEST2");
+       s.shiftRows(0,4,1);
     }
-    
+
     /**
      * When shifting rows, the page breaks should go with it
      *
@@ -167,29 +127,25 @@
       HSSFRow row = s.createRow(4);
       row.createCell((short)0).setCellValue("test");
       s.setRowBreak(4);
-      
+
       s.shiftRows(4, 4, 2);
       assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6));
-      
+
     }
 
 
     public void testShiftWithComments() throws Exception {
-        String filename = System.getProperty( "HSSF.testdata.path" );
-        filename = filename + "/comments.xls";
-        FileInputStream fin = new FileInputStream( filename );
-        HSSFWorkbook wb = new HSSFWorkbook( fin );
-        fin.close();
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("comments.xls");
 
         HSSFSheet sheet = wb.getSheet("Sheet1");
         assertEquals(3, sheet.getLastRowNum());
-        
+
         // Verify comments are in the position expected
         assertNotNull(sheet.getCellComment(0,0));
         assertNull(sheet.getCellComment(1,0));
         assertNotNull(sheet.getCellComment(2,0));
         assertNotNull(sheet.getCellComment(3,0));
-        
+
         String comment1 = sheet.getCellComment(0,0).getString().getString();
         assertEquals(comment1,"comment top row1 (index0)\n");
         String comment3 = sheet.getCellComment(2,0).getString().getString();
@@ -197,7 +153,7 @@
         String comment4 = sheet.getCellComment(3,0).getString().getString();
         assertEquals(comment4,"comment top row4 (index3)\n");
 
-        // Shifting all but first line down to test comments shifting 
+        // Shifting all but first line down to test comments shifting
         sheet.shiftRows(1, sheet.getLastRowNum(), 1, true, true);
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         wb.write(outputStream);
@@ -216,7 +172,7 @@
         assertEquals(comment3,comment3_shifted);
         String comment4_shifted = sheet.getCellComment(4,0).getString().getString();
         assertEquals(comment4,comment4_shifted);
-                
+
         // Write out and read back in again
         // Ensure that the changes were persisted
         wb = new HSSFWorkbook( new ByteArrayInputStream(outputStream.toByteArray()) );
@@ -235,22 +191,18 @@
         comment3_shifted = sheet.getCellComment(3,0).getString().getString();
         assertEquals(comment3,comment3_shifted);
         comment4_shifted = sheet.getCellComment(4,0).getString().getString();
-        assertEquals(comment4,comment4_shifted);        
+        assertEquals(comment4,comment4_shifted);
     }
-    
+
     /**
      * See bug #34023
      */
-    public void testShiftWithFormulas() throws Exception {
-        String filename = System.getProperty( "HSSF.testdata.path" );
-        filename = filename + "/ForShifting.xls";
-        FileInputStream fin = new FileInputStream( filename );
-        HSSFWorkbook wb = new HSSFWorkbook( fin );
-        fin.close();
+    public void testShiftWithFormulas() {
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ForShifting.xls");
 
         HSSFSheet sheet = wb.getSheet("Sheet1");
         assertEquals(19, sheet.getLastRowNum());
-        
+
         assertEquals("cell B1 (ref)", sheet.getRow(0).getCell((short)3).getRichStringCellValue().toString());
         assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell((short)3).getCellFormula());
         assertEquals("cell B2 (ref)", sheet.getRow(1).getCell((short)3).getRichStringCellValue().toString());
@@ -259,15 +211,15 @@
         assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell((short)3).getCellFormula());
         assertEquals("cell B2 (ref)", sheet.getRow(6).getCell((short)1).getRichStringCellValue().toString());
         assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(6).getCell((short)1).getCellFormula());
-        
+
         sheet.shiftRows(1, 1, 10);
-        
+
         // Row 1 => Row 11
         // So strings on row 11 unchanged, but reference in formula is
         assertEquals("cell B1 (ref)", sheet.getRow(0).getCell((short)3).getRichStringCellValue().toString());
         assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell((short)3).getCellFormula());
         assertEquals(0, sheet.getRow(1).getPhysicalNumberOfCells());
-        
+
         // still save b2
         assertEquals("cell B2 (ref)", sheet.getRow(11).getCell((short)3).getRichStringCellValue().toString());
         // but points to b12
@@ -275,7 +227,7 @@
 
         assertEquals("cell B3 (ref)", sheet.getRow(2).getCell((short)3).getRichStringCellValue().toString());
         assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell((short)3).getCellFormula());
-        
+
         // one on a non-shifted row also updated
         assertEquals("cell B2 (ref)", sheet.getRow(6).getCell((short)1).getRichStringCellValue().toString());
         assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(6).getCell((short)1).getCellFormula());

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java Mon Apr  7 05:51:50 2008
@@ -14,43 +14,36 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.hssf.usermodel;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
+package org.apache.poi.hssf.usermodel;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.record.RecordFormatException;
+
 /**
  * @author aviks
- *
- * This testcase contains tests for bugs that are yet to be fixed. 
- * Therefore, the standard ant test target does not run these tests. 
- * Run this testcase with the single-test target. 
- * The names of the tests usually correspond to the Bugzilla id's
- * PLEASE MOVE tests from this class to TestBugs once the bugs are fixed,
- * so that they are then run automatically. 
+ * 
+ * This testcase contains tests for bugs that are yet to be fixed. Therefore,
+ * the standard ant test target does not run these tests. Run this testcase with
+ * the single-test target. The names of the tests usually correspond to the
+ * Bugzilla id's PLEASE MOVE tests from this class to TestBugs once the bugs are
+ * fixed, so that they are then run automatically.
  */
-public class TestUnfixedBugs extends TestCase {
-
-
-	public TestUnfixedBugs(String arg0) {
-		super(arg0);
+public final class TestUnfixedBugs extends TestCase {
 
+	public void test43493() {
+		// Has crazy corrupt sub-records on
+		// a EmbeddedObjectRefSubRecord
+		try {
+			HSSFTestDataSamples.openSampleWorkbook("43493.xls");
+		} catch (RecordFormatException e) {
+			if (e.getCause().getCause() instanceof ArrayIndexOutOfBoundsException) {
+				throw new AssertionFailedError("Identified bug 43493");
+			}
+			throw e;
+		}
 	}
-	
-	protected String cwd = System.getProperty("HSSF.testdata.path");
-	
-	 
-
-    public void test43493() throws Exception {
-        // Has crazy corrup subrecords on
-        //  a EmbeddedObjectRefSubRecord
-        File f = new File(cwd, "43493.xls");
-        HSSFWorkbook wb = new HSSFWorkbook(
-                new FileInputStream(f)
-        );
-    }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java Mon Apr  7 05:51:50 2008
@@ -14,37 +14,33 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
+
 package org.apache.poi.hssf.usermodel;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
 /**
  * Tests for how HSSFWorkbook behaves with XLS files
  *  with a WORKBOOK directory entry (instead of the more
  *  usual, Workbook)
  */
-public class TestUppercaseWorkbook extends TestCase {
-	private String dirPath;
-	private String xlsA = "WORKBOOK_in_capitals.xls";
+public final class TestUppercaseWorkbook extends TestCase {
 
-	protected void setUp() throws Exception {
-		super.setUp();
-		
-        dirPath = System.getProperty("HSSF.testdata.path");
-	}
+	private String xlsA = "WORKBOOK_in_capitals.xls";
 
 	/**
 	 * Test that we can open a file with WORKBOOK
 	 */
 	public void testOpen() throws Exception {
-		FileInputStream is = new FileInputStream(dirPath + "/" + xlsA);
+		InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
 		
 		POIFSFileSystem fs = new POIFSFileSystem(is);
 
@@ -68,7 +64,7 @@
 	 * Test that when we write out, we go back to the correct case
 	 */
 	public void testWrite() throws Exception {
-		FileInputStream is = new FileInputStream(dirPath + "/" + xlsA);
+		InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
 		POIFSFileSystem fs = new POIFSFileSystem(is);
 
 		// Open the workbook, not preserving nodes
@@ -96,7 +92,7 @@
 	 *  correct case
 	 */
 	public void testWritePreserve() throws Exception {
-		FileInputStream is = new FileInputStream(dirPath + "/" + xlsA);
+		InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
 		POIFSFileSystem fs = new POIFSFileSystem(is);
 
 		// Open the workbook, not preserving nodes

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java Mon Apr  7 05:51:50 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,11 +14,18 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.usermodel;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+
 import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.BackupRecord;
 import org.apache.poi.hssf.record.LabelSSTRecord;
@@ -29,12 +35,6 @@
 import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.TempFile;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Iterator;
-
 /**
  * Class to test Workbook functionality
  *
@@ -42,10 +42,7 @@
  * @author Greg Merrill
  * @author Siggi Cherem
  */
-
-public class TestWorkbook
-    extends TestCase
-{
+public class TestWorkbook extends TestCase {
     private static final String LAST_NAME_KEY        = "lastName";
     private static final String FIRST_NAME_KEY       = "firstName";
     private static final String SSN_KEY              = "ssn";
@@ -58,15 +55,9 @@
     private static final String SSN_VALUE            = "555555555";
     private SanityChecker sanityChecker = new SanityChecker();
 
-    /**
-     * Constructor TestWorkbook
-     *
-     * @param name
-     */
 
-    public TestWorkbook(String name)
-    {
-        super(name);
+    private static HSSFWorkbook openSample(String sampleFileName) {
+        return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
     }
 
     /**
@@ -178,21 +169,12 @@
      *
      */
 
-    public void testReadSimple()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
+    public void testReadSimple() {
+        HSSFWorkbook workbook = openSample("Simple.xls");
+        HSSFSheet sheet = workbook.getSheetAt(0);
 
-        filename = filename + "/Simple.xls";
-        FileInputStream stream   = new FileInputStream(filename);
-        POIFSFileSystem fs       = new POIFSFileSystem(stream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fs);
-        HSSFSheet       sheet    = workbook.getSheetAt(0);
-
-        assertEquals(REPLACE_ME,
-                     sheet.getRow(( short ) 0).getCell(( short ) 0)
-                         .getStringCellValue());
-        stream.close();
+        HSSFCell cell = sheet.getRow(0).getCell(0);
+        assertEquals(REPLACE_ME, cell .getRichStringCellValue().getString());
     }
 
     /**
@@ -204,24 +186,15 @@
      *
      */
 
-    public void testReadSimpleWithDataFormat()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/SimpleWithDataFormat.xls";
-        FileInputStream stream   = new FileInputStream(filename);
-        POIFSFileSystem fs       = new POIFSFileSystem(stream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fs);
+    public void testReadSimpleWithDataFormat() {
+        HSSFWorkbook workbook = openSample("SimpleWithDataFormat.xls");
         HSSFSheet       sheet    = workbook.getSheetAt(0);
         HSSFDataFormat  format   = workbook.createDataFormat();
-	HSSFCell	cell	 = 
-                     sheet.getRow(( short ) 0).getCell(( short ) 0);
+        HSSFCell cell = sheet.getRow(0).getCell(0);
 
         assertEquals(1.25,cell.getNumericCellValue(), 1e-10);
 
-	assertEquals(format.getFormat(cell.getCellStyle().getDataFormat()), "0.0");
-        stream.close();
+        assertEquals(format.getFormat(cell.getCellStyle().getDataFormat()), "0.0");
     }
 
 /**
@@ -236,23 +209,23 @@
     public void testWriteDataFormat()
         throws IOException
     {
-	File             file = TempFile.createTempFile("testWriteDataFormat",
+    File             file = TempFile.createTempFile("testWriteDataFormat",
                                                     ".xls");
         FileOutputStream out  = new FileOutputStream(file);
         HSSFWorkbook     wb   = new HSSFWorkbook();
         HSSFSheet        s    = wb.createSheet();
         HSSFRow          r    = null;
         HSSFCell         c    = null;
-	HSSFDataFormat format = wb.createDataFormat();
-	HSSFCellStyle    cs   = wb.createCellStyle();
-	
-	short df = format.getFormat("0.0");
-	cs.setDataFormat(df);
-	
-	r = s.createRow((short)0);
-	c = r.createCell((short)0);
-	c.setCellStyle(cs);
-	c.setCellValue(1.25);
+    HSSFDataFormat format = wb.createDataFormat();
+    HSSFCellStyle    cs   = wb.createCellStyle();
+
+    short df = format.getFormat("0.0");
+    cs.setDataFormat(df);
+
+    r = s.createRow((short)0);
+    c = r.createCell((short)0);
+    c.setCellStyle(cs);
+    c.setCellValue(1.25);
 
         wb.write(out);
         out.close();
@@ -261,16 +234,16 @@
         POIFSFileSystem fs       = new POIFSFileSystem(stream);
         HSSFWorkbook    workbook = new HSSFWorkbook(fs);
         HSSFSheet       sheet    = workbook.getSheetAt(0);
-	HSSFCell	cell	 = 
+    HSSFCell    cell     =
                      sheet.getRow(( short ) 0).getCell(( short ) 0);
-	format = workbook.createDataFormat();
+    format = workbook.createDataFormat();
 
         assertEquals(1.25,cell.getNumericCellValue(), 1e-10);
 
-	assertEquals(format.getFormat(df), "0.0");
+    assertEquals(format.getFormat(df), "0.0");
+
+    assertEquals(format, workbook.createDataFormat());
 
-	assertEquals(format, workbook.createDataFormat());
-	
         stream.close();
     }
 
@@ -283,30 +256,14 @@
      *
      */
 
-    public void testReadEmployeeSimple()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/Employee.xls";
-        FileInputStream stream   = new FileInputStream(filename);
-        POIFSFileSystem fs       = new POIFSFileSystem(stream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fs);
+    public void testReadEmployeeSimple() {
+        HSSFWorkbook workbook = openSample("Employee.xls");
         HSSFSheet       sheet    = workbook.getSheetAt(0);
 
-        assertEquals(EMPLOYEE_INFORMATION,
-                     sheet.getRow(1).getCell(( short ) 1)
-                         .getStringCellValue());
-        assertEquals(LAST_NAME_KEY,
-                     sheet.getRow(3).getCell(( short ) 2)
-                         .getStringCellValue());
-        assertEquals(FIRST_NAME_KEY,
-                     sheet.getRow(4).getCell(( short ) 2)
-                         .getStringCellValue());
-        assertEquals(SSN_KEY,
-                     sheet.getRow(5).getCell(( short ) 2)
-                         .getStringCellValue());
-        stream.close();
+        assertEquals(EMPLOYEE_INFORMATION, sheet.getRow(1).getCell(1).getStringCellValue());
+        assertEquals(LAST_NAME_KEY, sheet.getRow(3).getCell(2).getStringCellValue());
+        assertEquals(FIRST_NAME_KEY, sheet.getRow(4).getCell(2).getStringCellValue());
+        assertEquals(SSN_KEY, sheet.getRow(5).getCell(2).getStringCellValue());
     }
 
     /**
@@ -322,33 +279,17 @@
      *
      */
 
-    public void testModifySimple()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
+    public void testModifySimple() {
+        HSSFWorkbook workbook = openSample("Simple.xls");
+        HSSFSheet sheet = workbook.getSheetAt(0);
+        HSSFCell cell = sheet.getRow(0).getCell(0);
 
-        filename = filename + "/Simple.xls";
-        FileInputStream instream = new FileInputStream(filename);
-        POIFSFileSystem fsin     = new POIFSFileSystem(instream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fsin);
-        HSSFSheet       sheet    = workbook.getSheetAt(0);
-        HSSFCell        cell     =
-            sheet.getRow(( short ) 0).getCell(( short ) 0);
+        cell.setCellValue(new HSSFRichTextString(REPLACED));
 
-        cell.setCellValue(REPLACED);
-        File             destination = TempFile.createTempFile("SimpleResult",
-                                           ".xls");
-        FileOutputStream outstream   = new FileOutputStream(destination);
-
-        workbook.write(outstream);
-        instream.close();
-        outstream.close();
-        instream = new FileInputStream(destination);
-        workbook = new HSSFWorkbook(new POIFSFileSystem(instream));
+        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
         sheet    = workbook.getSheetAt(0);
-        cell     = sheet.getRow(( short ) 0).getCell(( short ) 0);
-        assertEquals(REPLACED, cell.getStringCellValue());
-        instream.close();
+        cell     = sheet.getRow(0).getCell(0);
+        assertEquals(REPLACED, cell.getRichStringCellValue().getString());
     }
 
     /**
@@ -364,42 +305,26 @@
      *             or is incorrect. <P>
      *
      */
-
-    public void testModifySimpleWithSkip()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/SimpleWithSkip.xls";
-        FileInputStream instream = new FileInputStream(filename);
-        POIFSFileSystem fsin     = new POIFSFileSystem(instream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fsin);
-        HSSFSheet       sheet    = workbook.getSheetAt(0);
-        HSSFCell        cell     =
-            sheet.getRow(( short ) 0).getCell(( short ) 1);
+    public void testModifySimpleWithSkip() {
+        HSSFWorkbook workbook = openSample("SimpleWithSkip.xls");
+        HSSFSheet sheet = workbook.getSheetAt(0);
+        HSSFCell cell = sheet.getRow(0).getCell(1);
 
         cell.setCellValue(REPLACED);
-        cell = sheet.getRow(( short ) 1).getCell(( short ) 0);
+        cell = sheet.getRow(1).getCell(0);
         cell.setCellValue(REPLACED);
-        File             destination =
-            TempFile.createTempFile("SimpleWithSkipResult", ".xls");
-        FileOutputStream outstream   = new FileOutputStream(destination);
-
-        workbook.write(outstream);
-        instream.close();
-        outstream.close();
-        instream = new FileInputStream(destination);
-        workbook = new HSSFWorkbook(new POIFSFileSystem(instream));
+
+        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
+
         sheet    = workbook.getSheetAt(0);
-        cell     = sheet.getRow(( short ) 0).getCell(( short ) 1);
+        cell     = sheet.getRow(0).getCell(1);
         assertEquals(REPLACED, cell.getStringCellValue());
-        cell = sheet.getRow(( short ) 0).getCell(( short ) 0);
+        cell = sheet.getRow(0).getCell(0);
         assertEquals(DO_NOT_REPLACE, cell.getStringCellValue());
-        cell = sheet.getRow(( short ) 1).getCell(( short ) 0);
+        cell = sheet.getRow(1).getCell(0);
         assertEquals(REPLACED, cell.getStringCellValue());
-        cell = sheet.getRow(( short ) 1).getCell(( short ) 1);
+        cell = sheet.getRow(1).getCell(1);
         assertEquals(DO_NOT_REPLACE, cell.getStringCellValue());
-        instream.close();
     }
 
     /**
@@ -415,41 +340,26 @@
      *             is incorrect or has not been replaced. <P>
      *
      */
-
-    public void testModifySimpleWithStyling()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/SimpleWithStyling.xls";
-        FileInputStream instream = new FileInputStream(filename);
-        POIFSFileSystem fsin     = new POIFSFileSystem(instream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fsin);
+    public void testModifySimpleWithStyling() {
+        HSSFWorkbook workbook = openSample("SimpleWithStyling.xls");
         HSSFSheet       sheet    = workbook.getSheetAt(0);
 
         for (int k = 0; k < 4; k++)
         {
             HSSFCell cell = sheet.getRow(( short ) k).getCell(( short ) 0);
 
-            cell.setCellValue(REPLACED);
+            cell.setCellValue(new HSSFRichTextString(REPLACED));
         }
-        File             destination =
-            TempFile.createTempFile("SimpleWithStylingResult", ".xls");
-        FileOutputStream outstream   = new FileOutputStream(destination);
-
-        workbook.write(outstream);
-        instream.close();
-        outstream.close();
-        instream = new FileInputStream(destination);
-        workbook = new HSSFWorkbook(new POIFSFileSystem(instream));
+
+
+        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
         sheet    = workbook.getSheetAt(0);
         for (int k = 0; k < 4; k++)
         {
             HSSFCell cell = sheet.getRow(( short ) k).getCell(( short ) 0);
 
-            assertEquals(REPLACED, cell.getStringCellValue());
+            assertEquals(REPLACED, cell.getRichStringCellValue().getString());
         }
-        instream.close();
     }
 
     /**
@@ -465,48 +375,23 @@
      *             is incorrect or has not been replaced. <P>
      *
      */
-
-    public void testModifyEmployee()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/Employee.xls";
-        FileInputStream instream = new FileInputStream(filename);
-        POIFSFileSystem fsin     = new POIFSFileSystem(instream);
-        HSSFWorkbook    workbook = new HSSFWorkbook(fsin);
+    public void testModifyEmployee() {
+        HSSFWorkbook workbook = openSample("Employee.xls");
         HSSFSheet       sheet    = workbook.getSheetAt(0);
-        HSSFCell        cell     =
-            sheet.getRow(( short ) 3).getCell(( short ) 2);
+        HSSFCell        cell     = sheet.getRow(3).getCell(2);
 
         cell.setCellValue(LAST_NAME_VALUE);
-        cell = sheet.getRow(( short ) 4).getCell(( short ) 2);
+        cell = sheet.getRow(4).getCell(2);
         cell.setCellValue(FIRST_NAME_VALUE);
-        cell = sheet.getRow(( short ) 5).getCell(( short ) 2);
+        cell = sheet.getRow(5).getCell(2);
         cell.setCellValue(SSN_VALUE);
-        File             destination = TempFile.createTempFile("EmployeeResult",
-                                           ".xls");
-        FileOutputStream outstream   = new FileOutputStream(destination);
-
-        workbook.write(outstream);
-        instream.close();
-        outstream.close();
-        instream = new FileInputStream(destination);
-        workbook = new HSSFWorkbook(new POIFSFileSystem(instream));
+
+        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
         sheet    = workbook.getSheetAt(0);
-        assertEquals(EMPLOYEE_INFORMATION,
-                     sheet.getRow(1).getCell(( short ) 1)
-                         .getStringCellValue());
-        assertEquals(LAST_NAME_VALUE,
-                     sheet.getRow(3).getCell(( short ) 2)
-                         .getStringCellValue());
-        assertEquals(FIRST_NAME_VALUE,
-                     sheet.getRow(4).getCell(( short ) 2)
-                         .getStringCellValue());
-        assertEquals(SSN_VALUE,
-                     sheet.getRow(5).getCell(( short ) 2)
-                         .getStringCellValue());
-        instream.close();
+        assertEquals(EMPLOYEE_INFORMATION, sheet.getRow(1).getCell(1).getStringCellValue());
+        assertEquals(LAST_NAME_VALUE, sheet.getRow(3).getCell(2).getStringCellValue());
+        assertEquals(FIRST_NAME_VALUE, sheet.getRow(4).getCell(2).getStringCellValue());
+        assertEquals(SSN_VALUE, sheet.getRow(5).getCell(2).getStringCellValue());
     }
 
     /**
@@ -517,21 +402,10 @@
      * FAILURE:    HSSF does not read a sheet or excepts.  HSSF incorrectly indentifies the cell<P>
      *
      */
-
-    public void testReadSheetWithRK()
-        throws IOException
-    {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/rk.xls";
-
-        // a.xls has a value on position (0,0)
-        FileInputStream in = new FileInputStream(filename);
-        POIFSFileSystem fs = new POIFSFileSystem(in);
-        HSSFWorkbook    h  = new HSSFWorkbook(fs);
+    public void testReadSheetWithRK() {
+        HSSFWorkbook h = openSample("rk.xls");
         HSSFSheet       s  = h.getSheetAt(0);
-        HSSFRow         r  = s.getRow(0);
-        HSSFCell        c  = r.getCell(( short ) 0);
+        HSSFCell        c  = s.getRow(0).getCell(0);
         int             a  = c.getCellType();
 
         assertEquals(a, c.CELL_TYPE_NUMERIC);
@@ -564,7 +438,6 @@
         {
             r = s.createRow(rownum);
 
-            // r.setRowNum(( short ) rownum);
             for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
             {
                 c = r.createCell(cellnum);
@@ -572,7 +445,7 @@
                                + ((( double ) rownum / 1000)
                                   + (( double ) cellnum / 10000)));
                 c = r.createCell(( short ) (cellnum + 1));
-                c.setCellValue("TEST");
+                c.setCellValue(new HSSFRichTextString("TEST"));
             }
         }
         s.addMergedRegion(new Region(( short ) 0, ( short ) 0, ( short ) 10,
@@ -632,7 +505,7 @@
         HSSFRow      row      = sheet.createRow(( short ) 2);
         HSSFCell     cell     = row.createCell(( short ) 1);
 
-        cell.setCellValue("Class");
+        cell.setCellValue(new HSSFRichTextString("Class"));
         cell = row.createCell(( short ) 2);
 
         // workbook.write(new FileOutputStream("/a2.xls"));
@@ -687,49 +560,35 @@
         in.close();
         file.deleteOnExit();
     }
-    
+
     /**
      * Generate a file to visually/programmatically verify repeating rows and cols made it
      */
     public void testRepeatingColsRows() throws IOException
     {
-		HSSFWorkbook workbook = new HSSFWorkbook();        
-		HSSFSheet sheet = workbook.createSheet("Test Print Titles");                
-		String sheetName = workbook.getSheetName(0);
-	     
-	    HSSFRow row = sheet.createRow(0);
-	    
-	    HSSFCell cell = row.createCell((short)1);
-	    cell.setCellValue("hi");
-	     
-	     
-		workbook.setRepeatingRowsAndColumns(0, 0, 1, 0, 0); 
-	     
-		File file = TempFile.createTempFile("testPrintTitles",".xls");        
-	     
-		FileOutputStream fileOut = new FileOutputStream(file);
-		workbook.write(fileOut);
-		fileOut.close();
-	     
-		assertTrue("file exists",file.exists());
-	     
-    	
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet sheet = workbook.createSheet("Test Print Titles");
+
+        HSSFRow row = sheet.createRow(0);
+
+        HSSFCell cell = row.createCell((short)1);
+        cell.setCellValue(new HSSFRichTextString("hi"));
+
+
+        workbook.setRepeatingRowsAndColumns(0, 0, 1, 0, 0);
+
+        File file = TempFile.createTempFile("testPrintTitles",".xls");
+
+        FileOutputStream fileOut = new FileOutputStream(file);
+        workbook.write(fileOut);
+        fileOut.close();
+
+        assertTrue("file exists",file.exists());
     }
-  
-    
+
+
     public static void main(String [] ignored_args)
     {
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        // assume this is relative to basedir
-        if (filename == null)
-        {
-            System.setProperty(
-                "HSSF.testdata.path",
-                "src/testcases/org/apache/poi/hssf/data");
-        }
-        System.out
-            .println("Testing org.apache.poi.hssf.usermodel.HSSFWorkbook");
         junit.textui.TestRunner.run(TestWorkbook.class);
     }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java Mon Apr  7 05:51:50 2008
@@ -14,24 +14,29 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.util;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.formula.MemFuncPtg;
 import org.apache.poi.hssf.record.formula.Area3DPtg;
+import org.apache.poi.hssf.record.formula.MemFuncPtg;
 import org.apache.poi.hssf.record.formula.UnionPtg;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFName;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+/**
+ * 
+ */
 public final class TestAreaReference extends TestCase {
 
     public void testAreaRef1() {
@@ -99,7 +104,7 @@
         TestCellReference.confirmCell(allCells[2], "Tabelle1", 6, 1, true, true, "Tabelle1!$B$7");
     }
 
-    private static class HSSFWB extends HSSFWorkbook {
+    private static final class HSSFWB extends HSSFWorkbook {
         public HSSFWB(InputStream in) throws IOException {
             super(in);
         }
@@ -182,12 +187,9 @@
     }
 
     public void testDiscontinousReference() throws Exception {
-        String filename = System.getProperty( "HSSF.testdata.path" );
-        filename = filename + "/44167.xls";
-        FileInputStream fin = new FileInputStream( filename );
-        HSSFWB wb = new HSSFWB( fin );
+        InputStream is = HSSFTestDataSamples.openSampleFileStream("44167.xls");
+        HSSFWB wb = new HSSFWB(is);
         Workbook workbook = wb.getWorkbook();
-        fin.close();
 
         assertEquals(1, wb.getNumberOfNames());
         String sheetName = "Tabelle1";
@@ -269,5 +271,4 @@
     public static void main(String[] args) {
         junit.textui.TestRunner.run(TestAreaReference.class);
     }
-        
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java Mon Apr  7 05:51:50 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,58 +14,56 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.poifs.filesystem;
 
 import junit.framework.TestCase;
 import java.io.*;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+
 /**
  * Class to test that POIFS complains when given an Office 2007 XML document
  *
  * @author Marc Johnson
  */
+public class TestOffice2007XMLException extends TestCase {
 
-public class TestOffice2007XMLException extends TestCase
-{
-	public String dirname;
-
-	public void setUp() {
-		dirname = System.getProperty("HSSF.testdata.path");
+	private static final InputStream openSampleStream(String sampleFileName) {
+		return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
 	}
-
 	public void testXMLException() throws IOException
 	{
-		FileInputStream in = new FileInputStream(dirname + "/sample.xlsx");
+		InputStream in = openSampleStream("sample.xlsx");
 
 		try {
 			new POIFSFileSystem(in);
-			fail();
+			fail("expected exception was not thrown");
 		} catch(OfficeXmlFileException e) {
-			// Good
+			// expected during successful test
+			assertTrue(e.getMessage().indexOf("POI only supports OLE2 Office documents") > 0);
 		}
 	}
 	
-	public void testDetectAsPOIFS() throws IOException {
-		InputStream in;
+	public void testDetectAsPOIFS() {
 		
 		// ooxml file isn't
-		in = new PushbackInputStream(
-				new FileInputStream(dirname + "/SampleSS.xlsx"), 10
-		);
-		assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
+		confirmIsPOIFS("SampleSS.xlsx", false);
 		
 		// xls file is
-		in = new PushbackInputStream(
-				new FileInputStream(dirname + "/SampleSS.xls"), 10
-		);
-		assertTrue(POIFSFileSystem.hasPOIFSHeader(in));
+		confirmIsPOIFS("SampleSS.xls", true);
 		
 		// text file isn't
-		in = new PushbackInputStream(
-				new FileInputStream(dirname + "/SampleSS.txt"), 10
-		);
-		assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
+		confirmIsPOIFS("SampleSS.txt", false);
+	}
+	private void confirmIsPOIFS(String sampleFileName, boolean expectedResult) {
+		InputStream in  = new PushbackInputStream(openSampleStream(sampleFileName), 10);
+		boolean actualResult;
+		try {
+			actualResult = POIFSFileSystem.hasPOIFSHeader(in);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+		assertEquals(expectedResult, actualResult);
 	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Mon Apr  7 05:51:50 2008
@@ -17,14 +17,13 @@
 
 package org.apache.poi.poifs.filesystem;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+
 /**
  * Tests for POIFSFileSystem
  * 
@@ -32,10 +31,6 @@
  */
 public final class TestPOIFSFileSystem extends TestCase {
 
-	public TestPOIFSFileSystem(String testName) {
-		super(testName);
-	}
-	
 	/**
 	 * Mock exception used to ensure correct error handling
 	 */
@@ -121,16 +116,7 @@
 		
 	}
 
-	private static InputStream openSampleStream(String sampleName) {
-		String dataDirName = System.getProperty("HSSF.testdata.path");
-		if(dataDirName == null) {
-		    throw new RuntimeException("Missing system property '" + "HSSF.testdata.path" + "'");
-		}
-        File f = new File(dataDirName + "/" + sampleName);
-        try {
-            return new FileInputStream(f);
-        } catch (FileNotFoundException e) {
-            throw new RuntimeException("Sample file '" + f.getAbsolutePath() + "' not found");
-        }
+	private static InputStream openSampleStream(String sampleFileName) {
+		return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
 	}
 }



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


Mime
View raw message