poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r645483 [5/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/TestHSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.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,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.usermodel;
 
@@ -27,6 +25,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.record.HCenterRecord;
 import org.apache.poi.hssf.record.PasswordRecord;
@@ -35,7 +34,6 @@
 import org.apache.poi.hssf.record.VCenterRecord;
 import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.util.Region;
 import org.apache.poi.util.TempFile;
 
@@ -46,395 +44,381 @@
  * @author Glen Stampoultzis (glens at apache.org)
  * @author Andrew C. Oliver (acoliver apache org)
  */
+public final class TestHSSFSheet extends TestCase {
+
+	private static HSSFWorkbook openSample(String sampleFileName) {
+		return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+	}
+
+	/**
+	 * Test the gridset field gets set as expected.
+	 */
+
+	public void testBackupRecord()
+			throws Exception
+	{
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet s = wb.createSheet();
+		Sheet sheet = s.getSheet();
+
+		assertEquals(true, sheet.getGridsetRecord().getGridset());
+		s.setGridsPrinted(true);
+		assertEquals(false, sheet.getGridsetRecord().getGridset());
+	}
+
+	/**
+	 * Test vertically centered output.
+	 */
+
+	public void testVerticallyCenter()
+			throws Exception
+	{
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet s = wb.createSheet();
+		Sheet sheet = s.getSheet();
+		VCenterRecord record =
+				(VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);
+
+		assertEquals(false, record.getVCenter());
+		s.setVerticallyCenter(true);
+		assertEquals(true, record.getVCenter());
+
+		// wb.write(new FileOutputStream("c:\\test.xls"));
+	}
+
+	/**
+	 * Test horizontally centered output.
+	 */
+
+	public void testHorizontallyCenter()
+			throws Exception
+	{
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet s = wb.createSheet();
+		Sheet sheet = s.getSheet();
+		HCenterRecord record =
+				(HCenterRecord) sheet.findFirstRecordBySid(HCenterRecord.sid);
+
+		assertEquals(false, record.getHCenter());
+		s.setHorizontallyCenter(true);
+		assertEquals(true, record.getHCenter());
+
+	}
 
-public class TestHSSFSheet
-        extends TestCase
-{
-    public TestHSSFSheet(String s)
-    {
-        super(s);
-    }
-
-    /**
-     * Test the gridset field gets set as expected.
-     */
-
-    public void testBackupRecord()
-            throws Exception
-    {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet s = wb.createSheet();
-        Sheet sheet = s.getSheet();
-
-        assertEquals(true, sheet.getGridsetRecord().getGridset());
-        s.setGridsPrinted(true);
-        assertEquals(false, sheet.getGridsetRecord().getGridset());
-    }
-
-    /**
-     * Test vertically centered output.
-     */
-
-    public void testVerticallyCenter()
-            throws Exception
-    {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet s = wb.createSheet();
-        Sheet sheet = s.getSheet();
-        VCenterRecord record =
-                (VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);
-
-        assertEquals(false, record.getVCenter());
-        s.setVerticallyCenter(true);
-        assertEquals(true, record.getVCenter());
-
-        // wb.write(new FileOutputStream("c:\\test.xls"));
-    }
-
-    /**
-     * Test horizontally centered output.
-     */
-
-    public void testHorizontallyCenter()
-            throws Exception
-    {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet s = wb.createSheet();
-        Sheet sheet = s.getSheet();
-        HCenterRecord record =
-                (HCenterRecord) sheet.findFirstRecordBySid(HCenterRecord.sid);
-
-        assertEquals(false, record.getHCenter());
-        s.setHorizontallyCenter(true);
-        assertEquals(true, record.getHCenter());
-
-    }    
-    
-    
-    /**
-     * Test WSBboolRecord fields get set in the user model.
-     */
-
-    public void testWSBool()
-    {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet s = wb.createSheet();
-        Sheet sheet = s.getSheet();
-        WSBoolRecord record =
-                (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
-
-        // Check defaults
-        assertEquals(true, record.getAlternateExpression());
-        assertEquals(true, record.getAlternateFormula());
-        assertEquals(false, record.getAutobreaks());
-        assertEquals(false, record.getDialog());
-        assertEquals(false, record.getDisplayGuts());
-        assertEquals(true, record.getFitToPage());
-        assertEquals(false, record.getRowSumsBelow());
-        assertEquals(false, record.getRowSumsRight());
-
-        // Alter
-        s.setAlternativeExpression(false);
-        s.setAlternativeFormula(false);
-        s.setAutobreaks(true);
-        s.setDialog(true);
-        s.setDisplayGuts(true);
-        s.setFitToPage(false);
-        s.setRowSumsBelow(true);
-        s.setRowSumsRight(true);
-
-        // Check
-        assertEquals(false, record.getAlternateExpression());
-        assertEquals(false, record.getAlternateFormula());
-        assertEquals(true, record.getAutobreaks());
-        assertEquals(true, record.getDialog());
-        assertEquals(true, record.getDisplayGuts());
-        assertEquals(false, record.getFitToPage());
-        assertEquals(true, record.getRowSumsBelow());
-        assertEquals(true, record.getRowSumsRight());
-        assertEquals(false, s.getAlternateExpression());
-        assertEquals(false, s.getAlternateFormula());
-        assertEquals(true, s.getAutobreaks());
-        assertEquals(true, s.getDialog());
-        assertEquals(true, s.getDisplayGuts());
-        assertEquals(false, s.getFitToPage());
-        assertEquals(true, s.getRowSumsBelow());
-        assertEquals(true, s.getRowSumsRight());
-    }
-
-    public void testReadBooleans()
-            throws Exception
-    {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test boolean");
-        HSSFRow row = sheet.createRow((short) 2);
-        HSSFCell cell = row.createCell((short) 9);
-        cell.setCellValue(true);
-        cell = row.createCell((short) 11);
-        cell.setCellValue(true);
-        File tempFile = TempFile.createTempFile("bool", "test.xls");
-        FileOutputStream stream = new FileOutputStream(tempFile);
-        workbook.write(stream);
-        stream.close();
-
-        FileInputStream readStream = new FileInputStream(tempFile);
-        workbook = new HSSFWorkbook(readStream);
-        sheet = workbook.getSheetAt(0);
-        row = sheet.getRow(2);
-        stream.close();
-        tempFile.delete();
-        assertNotNull(row);
-        assertEquals(2, row.getPhysicalNumberOfCells());
-    }
-
-    public void testRemoveRow()
-    {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test boolean");
-        HSSFRow row = sheet.createRow((short) 2);
-        sheet.removeRow(row);
-    }
-
-    public void testCloneSheet() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test Clone");
-        HSSFRow row = sheet.createRow((short) 0);
-        HSSFCell cell = row.createCell((short) 0);
-        cell.setCellValue("clone_test"); 
-        HSSFSheet cloned = workbook.cloneSheet(0);
+
+	/**
+	 * Test WSBboolRecord fields get set in the user model.
+	 */
+
+	public void testWSBool()
+	{
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet s = wb.createSheet();
+		Sheet sheet = s.getSheet();
+		WSBoolRecord record =
+				(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+
+		// Check defaults
+		assertEquals(true, record.getAlternateExpression());
+		assertEquals(true, record.getAlternateFormula());
+		assertEquals(false, record.getAutobreaks());
+		assertEquals(false, record.getDialog());
+		assertEquals(false, record.getDisplayGuts());
+		assertEquals(true, record.getFitToPage());
+		assertEquals(false, record.getRowSumsBelow());
+		assertEquals(false, record.getRowSumsRight());
+
+		// Alter
+		s.setAlternativeExpression(false);
+		s.setAlternativeFormula(false);
+		s.setAutobreaks(true);
+		s.setDialog(true);
+		s.setDisplayGuts(true);
+		s.setFitToPage(false);
+		s.setRowSumsBelow(true);
+		s.setRowSumsRight(true);
+
+		// Check
+		assertEquals(false, record.getAlternateExpression());
+		assertEquals(false, record.getAlternateFormula());
+		assertEquals(true, record.getAutobreaks());
+		assertEquals(true, record.getDialog());
+		assertEquals(true, record.getDisplayGuts());
+		assertEquals(false, record.getFitToPage());
+		assertEquals(true, record.getRowSumsBelow());
+		assertEquals(true, record.getRowSumsRight());
+		assertEquals(false, s.getAlternateExpression());
+		assertEquals(false, s.getAlternateFormula());
+		assertEquals(true, s.getAutobreaks());
+		assertEquals(true, s.getDialog());
+		assertEquals(true, s.getDisplayGuts());
+		assertEquals(false, s.getFitToPage());
+		assertEquals(true, s.getRowSumsBelow());
+		assertEquals(true, s.getRowSumsRight());
+	}
+
+	public void testReadBooleans()
+			throws Exception
+	{
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet("Test boolean");
+		HSSFRow row = sheet.createRow((short) 2);
+		HSSFCell cell = row.createCell((short) 9);
+		cell.setCellValue(true);
+		cell = row.createCell((short) 11);
+		cell.setCellValue(true);
+		File tempFile = TempFile.createTempFile("bool", "test.xls");
+		FileOutputStream stream = new FileOutputStream(tempFile);
+		workbook.write(stream);
+		stream.close();
+
+		FileInputStream readStream = new FileInputStream(tempFile);
+		workbook = new HSSFWorkbook(readStream);
+		sheet = workbook.getSheetAt(0);
+		row = sheet.getRow(2);
+		stream.close();
+		tempFile.delete();
+		assertNotNull(row);
+		assertEquals(2, row.getPhysicalNumberOfCells());
+	}
+
+	public void testRemoveRow()
+	{
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet("Test boolean");
+		HSSFRow row = sheet.createRow((short) 2);
+		sheet.removeRow(row);
+	}
+
+	public void testCloneSheet() {
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet("Test Clone");
+		HSSFRow row = sheet.createRow((short) 0);
+		HSSFCell cell = row.createCell((short) 0);
+		cell.setCellValue("clone_test"); 
+		HSSFSheet cloned = workbook.cloneSheet(0);
   
-        //Check for a good clone
-        assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
-        
-        //Check that the cells are not somehow linked
-        cell.setCellValue("Difference Check");
-        assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
-    }
-
-    /** tests that the sheet name for multiple clones of the same sheet is unique
-     * BUG 37416
-     */    
-    public void testCloneSheetMultipleTimes() {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet("Test Clone");
-        HSSFRow row = sheet.createRow((short) 0);
-        HSSFCell cell = row.createCell((short) 0);
-        cell.setCellValue("clone_test");
-        //Clone the sheet multiple times
-        workbook.cloneSheet(0);
-        workbook.cloneSheet(0);
-        
-        assertNotNull(workbook.getSheet("Test Clone"));
-        assertNotNull(workbook.getSheet("Test Clone(1)"));
-        assertNotNull(workbook.getSheet("Test Clone(2)"));  
-    }
-    
-    /**
-     * Setting landscape and portrait stuff on new sheets
-     */
-    public void testPrintSetupLandscapeNew() throws Exception {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheetL = workbook.createSheet("LandscapeS");
-        HSSFSheet sheetP = workbook.createSheet("LandscapeP");
-        
-        // Check two aspects of the print setup
-        assertFalse(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetP.getPrintSetup().getLandscape());
-        assertEquals(0, sheetL.getPrintSetup().getCopies());
-        assertEquals(0, sheetP.getPrintSetup().getCopies());
-        
-        // Change one on each
-        sheetL.getPrintSetup().setLandscape(true);
-        sheetP.getPrintSetup().setCopies((short)3);
-        
-        // Check taken
-        assertTrue(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetP.getPrintSetup().getLandscape());
-        assertEquals(0, sheetL.getPrintSetup().getCopies());
-        assertEquals(3, sheetP.getPrintSetup().getCopies());
-        
-        // Save and re-load, and check still there
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        workbook.write(baos);
-        workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
-        
-        assertTrue(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetP.getPrintSetup().getLandscape());
-        assertEquals(0, sheetL.getPrintSetup().getCopies());
-        assertEquals(3, sheetP.getPrintSetup().getCopies());
-    }
-    
-    /**
-     * Setting landscape and portrait stuff on existing sheets
-     */
-    public void testPrintSetupLandscapeExisting() throws Exception {
-        String filename = System.getProperty("HSSF.testdata.path");
-        filename = filename + "/SimpleWithPageBreaks.xls";
-        HSSFWorkbook workbook = 
-        	new HSSFWorkbook(new FileInputStream(filename));
-        
-        assertEquals(3, workbook.getNumberOfSheets());
-        
-        HSSFSheet sheetL = workbook.getSheetAt(0);
-        HSSFSheet sheetPM = workbook.getSheetAt(1);
-        HSSFSheet sheetLS = workbook.getSheetAt(2);
-        
-        // Check two aspects of the print setup
-        assertFalse(sheetL.getPrintSetup().getLandscape());
-        assertTrue(sheetPM.getPrintSetup().getLandscape());
-        assertTrue(sheetLS.getPrintSetup().getLandscape());
-        assertEquals(1, sheetL.getPrintSetup().getCopies());
-        assertEquals(1, sheetPM.getPrintSetup().getCopies());
-        assertEquals(1, sheetLS.getPrintSetup().getCopies());
-        
-        // Change one on each
-        sheetL.getPrintSetup().setLandscape(true);
-        sheetPM.getPrintSetup().setLandscape(false);
-        sheetPM.getPrintSetup().setCopies((short)3);
-        
-        // Check taken
-        assertTrue(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetPM.getPrintSetup().getLandscape());
-        assertTrue(sheetLS.getPrintSetup().getLandscape());
-        assertEquals(1, sheetL.getPrintSetup().getCopies());
-        assertEquals(3, sheetPM.getPrintSetup().getCopies());
-        assertEquals(1, sheetLS.getPrintSetup().getCopies());
-        
-        // Save and re-load, and check still there
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        workbook.write(baos);
-        workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
-        
-        assertTrue(sheetL.getPrintSetup().getLandscape());
-        assertFalse(sheetPM.getPrintSetup().getLandscape());
-        assertTrue(sheetLS.getPrintSetup().getLandscape());
-        assertEquals(1, sheetL.getPrintSetup().getCopies());
-        assertEquals(3, sheetPM.getPrintSetup().getCopies());
-        assertEquals(1, sheetLS.getPrintSetup().getCopies());
-    }
-    
-    public void testGroupRows() throws Exception {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet s = workbook.createSheet();
-        HSSFRow r1 = s.createRow(0);
-        HSSFRow r2 = s.createRow(1);
-        HSSFRow r3 = s.createRow(2);
-        HSSFRow r4 = s.createRow(3);
-        HSSFRow r5 = s.createRow(4);
-        
-        assertEquals(0, r1.getOutlineLevel());
-        assertEquals(0, r2.getOutlineLevel());
-        assertEquals(0, r3.getOutlineLevel());
-        assertEquals(0, r4.getOutlineLevel());
-        assertEquals(0, r5.getOutlineLevel());
-        
-        s.groupRow(2,3);
-        
-        assertEquals(0, r1.getOutlineLevel());
-        assertEquals(0, r2.getOutlineLevel());
-        assertEquals(1, r3.getOutlineLevel());
-        assertEquals(1, r4.getOutlineLevel());
-        assertEquals(0, r5.getOutlineLevel());
-        
-        // Save and re-open
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        workbook.write(baos);
-        workbook = new HSSFWorkbook(
-        		new ByteArrayInputStream(baos.toByteArray())
-        );
-        
-        s = workbook.getSheetAt(0);
-        r1 = s.getRow(0);
-        r2 = s.getRow(1);
-        r3 = s.getRow(2);
-        r4 = s.getRow(3);
-        r5 = s.getRow(4);
-        
-        assertEquals(0, r1.getOutlineLevel());
-        assertEquals(0, r2.getOutlineLevel());
-        assertEquals(1, r3.getOutlineLevel());
-        assertEquals(1, r4.getOutlineLevel());
-        assertEquals(0, r5.getOutlineLevel());
-    }
-    
-    public void testGroupRowsExisting() throws Exception {
-        String filename = System.getProperty("HSSF.testdata.path");
-        filename = filename + "/NoGutsRecords.xls";
-        HSSFWorkbook workbook = 
-        	new HSSFWorkbook(new FileInputStream(filename));
-        
-        HSSFSheet s = workbook.getSheetAt(0);
-        HSSFRow r1 = s.getRow(0);
-        HSSFRow r2 = s.getRow(1);
-        HSSFRow r3 = s.getRow(2);
-        HSSFRow r4 = s.getRow(3);
-        HSSFRow r5 = s.getRow(4);
-        HSSFRow r6 = s.getRow(5);
-
-        assertEquals(0, r1.getOutlineLevel());
-        assertEquals(0, r2.getOutlineLevel());
-        assertEquals(0, r3.getOutlineLevel());
-        assertEquals(0, r4.getOutlineLevel());
-        assertEquals(0, r5.getOutlineLevel());
-        assertEquals(0, r6.getOutlineLevel());
-        
-        // This used to complain about lacking guts records
-        s.groupRow(2, 4);
-        
-        assertEquals(0, r1.getOutlineLevel());
-        assertEquals(0, r2.getOutlineLevel());
-        assertEquals(1, r3.getOutlineLevel());
-        assertEquals(1, r4.getOutlineLevel());
-        assertEquals(1, r5.getOutlineLevel());
-        assertEquals(0, r6.getOutlineLevel());
-        
-        // Save and re-open
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        workbook.write(baos);
-        workbook = new HSSFWorkbook(
-        		new ByteArrayInputStream(baos.toByteArray())
-        );
-        
-        s = workbook.getSheetAt(0);
-        r1 = s.getRow(0);
-        r2 = s.getRow(1);
-        r3 = s.getRow(2);
-        r4 = s.getRow(3);
-        r5 = s.getRow(4);
-        r6 = s.getRow(5);
-        
-        assertEquals(0, r1.getOutlineLevel());
-        assertEquals(0, r2.getOutlineLevel());
-        assertEquals(1, r3.getOutlineLevel());
-        assertEquals(1, r4.getOutlineLevel());
-        assertEquals(1, r5.getOutlineLevel());
-        assertEquals(0, r6.getOutlineLevel());
-    }
-    
-    public void testGetDrawings() throws Exception {
-        String filename = System.getProperty("HSSF.testdata.path");
-    	HSSFWorkbook wb1c = new HSSFWorkbook(
-    			new FileInputStream(new File(filename,"WithChart.xls"))
-    	);
-    	HSSFWorkbook wb2c = new HSSFWorkbook(
-    			new FileInputStream(new File(filename,"WithTwoCharts.xls"))
-    	);
-    	
-    	// 1 chart sheet -> data on 1st, chart on 2nd
-    	assertNotNull(wb1c.getSheetAt(0).getDrawingPatriarch());
-    	assertNotNull(wb1c.getSheetAt(1).getDrawingPatriarch());
-    	assertFalse(wb1c.getSheetAt(0).getDrawingPatriarch().containsChart());
-    	assertTrue(wb1c.getSheetAt(1).getDrawingPatriarch().containsChart());
-    	
-    	// 2 chart sheet -> data on 1st, chart on 2nd+3rd
-    	assertNotNull(wb2c.getSheetAt(0).getDrawingPatriarch());
-    	assertNotNull(wb2c.getSheetAt(1).getDrawingPatriarch());
-    	assertNotNull(wb2c.getSheetAt(2).getDrawingPatriarch());
-    	assertFalse(wb2c.getSheetAt(0).getDrawingPatriarch().containsChart());
-    	assertTrue(wb2c.getSheetAt(1).getDrawingPatriarch().containsChart());
-    	assertTrue(wb2c.getSheetAt(2).getDrawingPatriarch().containsChart());
-    }
-    
+		//Check for a good clone
+		assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
+
+		//Check that the cells are not somehow linked
+		cell.setCellValue("Difference Check");
+		assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
+	}
+
+	/** tests that the sheet name for multiple clones of the same sheet is unique
+	 * BUG 37416
+	 */
+	public void testCloneSheetMultipleTimes() {
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet("Test Clone");
+		HSSFRow row = sheet.createRow((short) 0);
+		HSSFCell cell = row.createCell((short) 0);
+		cell.setCellValue("clone_test");
+		//Clone the sheet multiple times
+		workbook.cloneSheet(0);
+		workbook.cloneSheet(0);
+
+		assertNotNull(workbook.getSheet("Test Clone"));
+		assertNotNull(workbook.getSheet("Test Clone(1)"));
+		assertNotNull(workbook.getSheet("Test Clone(2)"));  
+	}
+
+	/**
+	 * Setting landscape and portrait stuff on new sheets
+	 */
+	public void testPrintSetupLandscapeNew() throws Exception {
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheetL = workbook.createSheet("LandscapeS");
+		HSSFSheet sheetP = workbook.createSheet("LandscapeP");
+
+		// Check two aspects of the print setup
+		assertFalse(sheetL.getPrintSetup().getLandscape());
+		assertFalse(sheetP.getPrintSetup().getLandscape());
+		assertEquals(0, sheetL.getPrintSetup().getCopies());
+		assertEquals(0, sheetP.getPrintSetup().getCopies());
+
+		// Change one on each
+		sheetL.getPrintSetup().setLandscape(true);
+		sheetP.getPrintSetup().setCopies((short)3);
+
+		// Check taken
+		assertTrue(sheetL.getPrintSetup().getLandscape());
+		assertFalse(sheetP.getPrintSetup().getLandscape());
+		assertEquals(0, sheetL.getPrintSetup().getCopies());
+		assertEquals(3, sheetP.getPrintSetup().getCopies());
+
+		// Save and re-load, and check still there
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		workbook.write(baos);
+		workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
+
+		assertTrue(sheetL.getPrintSetup().getLandscape());
+		assertFalse(sheetP.getPrintSetup().getLandscape());
+		assertEquals(0, sheetL.getPrintSetup().getCopies());
+		assertEquals(3, sheetP.getPrintSetup().getCopies());
+	}
+
+	/**
+	 * Setting landscape and portrait stuff on existing sheets
+	 */
+	public void testPrintSetupLandscapeExisting() throws Exception {
+		HSSFWorkbook workbook = openSample("SimpleWithPageBreaks.xls");
+
+		assertEquals(3, workbook.getNumberOfSheets());
+
+		HSSFSheet sheetL = workbook.getSheetAt(0);
+		HSSFSheet sheetPM = workbook.getSheetAt(1);
+		HSSFSheet sheetLS = workbook.getSheetAt(2);
+
+		// Check two aspects of the print setup
+		assertFalse(sheetL.getPrintSetup().getLandscape());
+		assertTrue(sheetPM.getPrintSetup().getLandscape());
+		assertTrue(sheetLS.getPrintSetup().getLandscape());
+		assertEquals(1, sheetL.getPrintSetup().getCopies());
+		assertEquals(1, sheetPM.getPrintSetup().getCopies());
+		assertEquals(1, sheetLS.getPrintSetup().getCopies());
+
+		// Change one on each
+		sheetL.getPrintSetup().setLandscape(true);
+		sheetPM.getPrintSetup().setLandscape(false);
+		sheetPM.getPrintSetup().setCopies((short)3);
+
+		// Check taken
+		assertTrue(sheetL.getPrintSetup().getLandscape());
+		assertFalse(sheetPM.getPrintSetup().getLandscape());
+		assertTrue(sheetLS.getPrintSetup().getLandscape());
+		assertEquals(1, sheetL.getPrintSetup().getCopies());
+		assertEquals(3, sheetPM.getPrintSetup().getCopies());
+		assertEquals(1, sheetLS.getPrintSetup().getCopies());
+
+		// Save and re-load, and check still there
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		workbook.write(baos);
+		workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
+
+		assertTrue(sheetL.getPrintSetup().getLandscape());
+		assertFalse(sheetPM.getPrintSetup().getLandscape());
+		assertTrue(sheetLS.getPrintSetup().getLandscape());
+		assertEquals(1, sheetL.getPrintSetup().getCopies());
+		assertEquals(3, sheetPM.getPrintSetup().getCopies());
+		assertEquals(1, sheetLS.getPrintSetup().getCopies());
+	}
+
+	public void testGroupRows() throws Exception {
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet s = workbook.createSheet();
+		HSSFRow r1 = s.createRow(0);
+		HSSFRow r2 = s.createRow(1);
+		HSSFRow r3 = s.createRow(2);
+		HSSFRow r4 = s.createRow(3);
+		HSSFRow r5 = s.createRow(4);
+
+		assertEquals(0, r1.getOutlineLevel());
+		assertEquals(0, r2.getOutlineLevel());
+		assertEquals(0, r3.getOutlineLevel());
+		assertEquals(0, r4.getOutlineLevel());
+		assertEquals(0, r5.getOutlineLevel());
+
+		s.groupRow(2,3);
+
+		assertEquals(0, r1.getOutlineLevel());
+		assertEquals(0, r2.getOutlineLevel());
+		assertEquals(1, r3.getOutlineLevel());
+		assertEquals(1, r4.getOutlineLevel());
+		assertEquals(0, r5.getOutlineLevel());
+
+		// Save and re-open
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		workbook.write(baos);
+		workbook = new HSSFWorkbook(
+				new ByteArrayInputStream(baos.toByteArray())
+		);
+
+		s = workbook.getSheetAt(0);
+		r1 = s.getRow(0);
+		r2 = s.getRow(1);
+		r3 = s.getRow(2);
+		r4 = s.getRow(3);
+		r5 = s.getRow(4);
+
+		assertEquals(0, r1.getOutlineLevel());
+		assertEquals(0, r2.getOutlineLevel());
+		assertEquals(1, r3.getOutlineLevel());
+		assertEquals(1, r4.getOutlineLevel());
+		assertEquals(0, r5.getOutlineLevel());
+	}
+
+	public void testGroupRowsExisting() throws Exception {
+		HSSFWorkbook workbook = openSample("NoGutsRecords.xls");
+
+		HSSFSheet s = workbook.getSheetAt(0);
+		HSSFRow r1 = s.getRow(0);
+		HSSFRow r2 = s.getRow(1);
+		HSSFRow r3 = s.getRow(2);
+		HSSFRow r4 = s.getRow(3);
+		HSSFRow r5 = s.getRow(4);
+		HSSFRow r6 = s.getRow(5);
+
+		assertEquals(0, r1.getOutlineLevel());
+		assertEquals(0, r2.getOutlineLevel());
+		assertEquals(0, r3.getOutlineLevel());
+		assertEquals(0, r4.getOutlineLevel());
+		assertEquals(0, r5.getOutlineLevel());
+		assertEquals(0, r6.getOutlineLevel());
+
+		// This used to complain about lacking guts records
+		s.groupRow(2, 4);
+
+		assertEquals(0, r1.getOutlineLevel());
+		assertEquals(0, r2.getOutlineLevel());
+		assertEquals(1, r3.getOutlineLevel());
+		assertEquals(1, r4.getOutlineLevel());
+		assertEquals(1, r5.getOutlineLevel());
+		assertEquals(0, r6.getOutlineLevel());
+
+		// Save and re-open
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		workbook.write(baos);
+		workbook = new HSSFWorkbook(
+				new ByteArrayInputStream(baos.toByteArray())
+		);
+
+		s = workbook.getSheetAt(0);
+		r1 = s.getRow(0);
+		r2 = s.getRow(1);
+		r3 = s.getRow(2);
+		r4 = s.getRow(3);
+		r5 = s.getRow(4);
+		r6 = s.getRow(5);
+
+		assertEquals(0, r1.getOutlineLevel());
+		assertEquals(0, r2.getOutlineLevel());
+		assertEquals(1, r3.getOutlineLevel());
+		assertEquals(1, r4.getOutlineLevel());
+		assertEquals(1, r5.getOutlineLevel());
+		assertEquals(0, r6.getOutlineLevel());
+	}
+
+	public void testGetDrawings() throws Exception {
+		HSSFWorkbook wb1c = openSample("WithChart.xls");
+		HSSFWorkbook wb2c = openSample("WithTwoCharts.xls");
+
+		// 1 chart sheet -> data on 1st, chart on 2nd
+		assertNotNull(wb1c.getSheetAt(0).getDrawingPatriarch());
+		assertNotNull(wb1c.getSheetAt(1).getDrawingPatriarch());
+		assertFalse(wb1c.getSheetAt(0).getDrawingPatriarch().containsChart());
+		assertTrue(wb1c.getSheetAt(1).getDrawingPatriarch().containsChart());
+
+		// 2 chart sheet -> data on 1st, chart on 2nd+3rd
+		assertNotNull(wb2c.getSheetAt(0).getDrawingPatriarch());
+		assertNotNull(wb2c.getSheetAt(1).getDrawingPatriarch());
+		assertNotNull(wb2c.getSheetAt(2).getDrawingPatriarch());
+		assertFalse(wb2c.getSheetAt(0).getDrawingPatriarch().containsChart());
+		assertTrue(wb2c.getSheetAt(1).getDrawingPatriarch().containsChart());
+		assertTrue(wb2c.getSheetAt(2).getDrawingPatriarch().containsChart());
+	}
+
 	/**
 	 * Test that the ProtectRecord is included when creating or cloning a sheet
 	 */
@@ -443,7 +427,7 @@
 		HSSFSheet hssfSheet = workbook.createSheet();
 		Sheet sheet = hssfSheet.getSheet();
 		ProtectRecord protect = sheet.getProtect();
-   	
+   
 		assertFalse(protect.getProtect());
 
 		// This will tell us that cloneSheet, and by extension,
@@ -455,61 +439,61 @@
 		assertTrue(hssfSheet.getProtect());
 	}
 
-    public void testProtectSheet() {
-        short expected = (short)0xfef1;
+	public void testProtectSheet() {
+		short expected = (short)0xfef1;
 	HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet s = wb.createSheet();
-        s.protectSheet("abcdefghij");
-        Sheet sheet = s.getSheet();
+		HSSFSheet s = wb.createSheet();
+		s.protectSheet("abcdefghij");
+		Sheet sheet = s.getSheet();
 	ProtectRecord protect = sheet.getProtect();
 	PasswordRecord pass = sheet.getPassword();
-        assertTrue("protection should be on",protect.getProtect());
-        assertTrue("object protection should be on",sheet.isProtected()[1]);
-        assertTrue("scenario protection should be on",sheet.isProtected()[2]);
-        assertEquals("well known value for top secret hash should be "+Integer.toHexString(expected).substring(4),expected,pass.getPassword());
-    }
-
-
-    public void testZoom()
-            throws Exception
-    {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet();
-        assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid));
-        sheet.setZoom(3,4);
-        assertTrue(sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid) > 0);
-        SCLRecord sclRecord = (SCLRecord) sheet.getSheet().findFirstRecordBySid(SCLRecord.sid);
-        assertEquals(3, sclRecord.getNumerator());
-        assertEquals(4, sclRecord.getDenominator());
-
-        int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid);
-        int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid);
-        assertTrue(sclLoc == window2Loc + 1);
+		assertTrue("protection should be on",protect.getProtect());
+		assertTrue("object protection should be on",sheet.isProtected()[1]);
+		assertTrue("scenario protection should be on",sheet.isProtected()[2]);
+		assertEquals("well known value for top secret hash should be "+Integer.toHexString(expected).substring(4),expected,pass.getPassword());
+	}
+
+
+	public void testZoom()
+			throws Exception
+	{
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet sheet = wb.createSheet();
+		assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid));
+		sheet.setZoom(3,4);
+		assertTrue(sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid) > 0);
+		SCLRecord sclRecord = (SCLRecord) sheet.getSheet().findFirstRecordBySid(SCLRecord.sid);
+		assertEquals(3, sclRecord.getNumerator());
+		assertEquals(4, sclRecord.getDenominator());
+
+		int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid);
+		int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid);
+		assertTrue(sclLoc == window2Loc + 1);
+
+	}
 
-    }
-    
 
 	/**
 	 * When removing one merged region, it would break
 	 *
-	 */    
+	 */
 	public void testRemoveMerged() {
 		HSSFWorkbook wb = new HSSFWorkbook();
 		HSSFSheet sheet = wb.createSheet();
-		Region region = new Region(0, (short)0, 1, (short)1);   	
+		Region region = new Region(0, (short)0, 1, (short)1);   
 		sheet.addMergedRegion(region);
 		region = new Region(1, (short)0, 2, (short)1);
 		sheet.addMergedRegion(region);
-		
-    	sheet.removeMergedRegion(0);
-    	
-    	region = sheet.getMergedRegionAt(0);
-    	assertEquals("Left over region should be starting at row 1", 1, region.getRowFrom());
-    	
-    	sheet.removeMergedRegion(0);
-    	
+
+		sheet.removeMergedRegion(0);
+
+		region = sheet.getMergedRegionAt(0);
+		assertEquals("Left over region should be starting at row 1", 1, region.getRowFrom());
+
+		sheet.removeMergedRegion(0);
+
 		assertEquals("there should be no merged regions left!", 0, sheet.getNumMergedRegions());
-		
+
 		//an, add, remove, get(0) would null pointer
 		sheet.addMergedRegion(region);
 		assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
@@ -517,16 +501,16 @@
 		assertEquals("there should now be zero merged regions!", 0, sheet.getNumMergedRegions());
 		//add it again!
 		region.setRowTo(4);
-    	
+
 		sheet.addMergedRegion(region);
 		assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
-		
+
 		//should exist now!
 		assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
 		region = sheet.getMergedRegionAt(0);
 		assertEquals("the merged row to doesnt match the one we put in ", 4, region.getRowTo());
-    	
-    }
+
+	}
 
 	public void testShiftMerged() {
 		HSSFWorkbook wb = new HSSFWorkbook();
@@ -534,156 +518,132 @@
 		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short)0);
 		cell.setCellValue("first row, first cell");
-		
+
 		row = sheet.createRow(1);
 		cell = row.createCell((short)1);
 		cell.setCellValue("second row, second cell");
-		
-		Region region = new Region(1, (short)0, 1, (short)1);   	
+
+		Region region = new Region(1, (short)0, 1, (short)1);   
 		sheet.addMergedRegion(region);
-		
+
 		sheet.shiftRows(1, 1, 1);
-		
+
 		region = sheet.getMergedRegionAt(0);
 		assertEquals("Merged region not moved over to row 2", 2, region.getRowFrom());
-		
+
 	}
 
-    /**
-     * Tests the display of gridlines, formulas, and rowcolheadings.
-     * @author Shawn Laubach (slaubach at apache dot org)
-     */
-    public void testDisplayOptions() throws Exception {
-    	HSSFWorkbook wb = new HSSFWorkbook();
-    	HSSFSheet sheet = wb.createSheet();
-	
-        File tempFile = TempFile.createTempFile("display", "test.xls");
-        FileOutputStream stream = new FileOutputStream(tempFile);
-        wb.write(stream);
-        stream.close();
-
-        FileInputStream readStream = new FileInputStream(tempFile);
-        wb = new HSSFWorkbook(readStream);
-        sheet = wb.getSheetAt(0);
-    	readStream.close();
-    
-    	assertEquals(sheet.isDisplayGridlines(), true);
-    	assertEquals(sheet.isDisplayRowColHeadings(), true);
-    	assertEquals(sheet.isDisplayFormulas(), false);
-    
-    	sheet.setDisplayGridlines(false);
-    	sheet.setDisplayRowColHeadings(false);
-    	sheet.setDisplayFormulas(true);
-
-        tempFile = TempFile.createTempFile("display", "test.xls");
-        stream = new FileOutputStream(tempFile);
-        wb.write(stream);
-        stream.close();
-
-        readStream = new FileInputStream(tempFile);
-        wb = new HSSFWorkbook(readStream);
-        sheet = wb.getSheetAt(0);
-    	readStream.close();
-    
-    
-    	assertEquals(sheet.isDisplayGridlines(), false);
-    	assertEquals(sheet.isDisplayRowColHeadings(), false);
-    	assertEquals(sheet.isDisplayFormulas(), true);
-    }
-
-    
-    /**
-     * Make sure the excel file loads work
-     *
-     */
-    public void testPageBreakFiles() throws Exception{
-        FileInputStream fis = null;
-        HSSFWorkbook wb     = null;
-        
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/SimpleWithPageBreaks.xls";
-        fis = new FileInputStream(filename);
-        wb = new HSSFWorkbook(fis);
-        fis.close();
-        
-        HSSFSheet sheet = wb.getSheetAt(0);
-        assertNotNull(sheet);
-        
-        assertEquals("1 row page break", 1, sheet.getRowBreaks().length);
-        assertEquals("1 column page break", 1, sheet.getColumnBreaks().length);
-
-        assertTrue("No row page break", sheet.isRowBroken(22));
-        assertTrue("No column page break", sheet.isColumnBroken((short)4));
-        
-        sheet.setRowBreak(10);        
-        sheet.setColumnBreak((short)13);
-
-        assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
-        assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
-        
-        File tempFile = TempFile.createTempFile("display", "testPagebreaks.xls");
-        FileOutputStream stream = new FileOutputStream(tempFile);
-        wb.write(stream);
-        stream.close();
-        
-        wb = new HSSFWorkbook(new FileInputStream(tempFile));
-        sheet = wb.getSheetAt(0);
-
-        assertTrue("No row page break", sheet.isRowBroken(22));
-        assertTrue("No column page break", sheet.isColumnBroken((short)4));
-
-        
-        assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
-        assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
-        
-        
-    }
-    
-    public void testDBCSName () throws Exception {
-    	FileInputStream fis = null;
-        HSSFWorkbook wb     = null;
-        
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/DBCSSheetName.xls";
-        fis = new FileInputStream(filename);
-        wb = new HSSFWorkbook(fis);
-        HSSFSheet s= wb.getSheetAt(1);
-        assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" );
-        assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e");
-    }
-    
-    /**
-     * Testing newly added method that exposes the WINDOW2.toprow
-     * parameter to allow setting the toprow in the visible view
-     * of the sheet when it is first opened.
-     */
-    public void testTopRow() throws Exception
-    {
-        FileInputStream fis = null;
-        HSSFWorkbook wb     = null;
-        
-        String filename = System.getProperty("HSSF.testdata.path");
-
-        filename = filename + "/SimpleWithPageBreaks.xls";
-        fis = new FileInputStream(filename);
-        wb = new HSSFWorkbook(fis);
-        fis.close();
-        
-        HSSFSheet sheet = wb.getSheetAt(0);
-        assertNotNull(sheet);
-        
-        short toprow = (short) 100;
-        short leftcol = (short) 50;
-        sheet.showInPane(toprow,leftcol);
-        assertEquals("HSSFSheet.getTopRow()", toprow, sheet.getTopRow());
-        assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol());
-    }
-    
-    /** cell with formula becomes null on cloning a sheet*/
+	/**
+	 * Tests the display of gridlines, formulas, and rowcolheadings.
+	 * @author Shawn Laubach (slaubach at apache dot org)
+	 */
+	public void testDisplayOptions() throws Exception {
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet sheet = wb.createSheet();
+
+		File tempFile = TempFile.createTempFile("display", "test.xls");
+		FileOutputStream stream = new FileOutputStream(tempFile);
+		wb.write(stream);
+		stream.close();
+
+		FileInputStream readStream = new FileInputStream(tempFile);
+		wb = new HSSFWorkbook(readStream);
+		sheet = wb.getSheetAt(0);
+		readStream.close();
+
+		assertEquals(sheet.isDisplayGridlines(), true);
+		assertEquals(sheet.isDisplayRowColHeadings(), true);
+		assertEquals(sheet.isDisplayFormulas(), false);
+
+		sheet.setDisplayGridlines(false);
+		sheet.setDisplayRowColHeadings(false);
+		sheet.setDisplayFormulas(true);
+
+		tempFile = TempFile.createTempFile("display", "test.xls");
+		stream = new FileOutputStream(tempFile);
+		wb.write(stream);
+		stream.close();
+
+		readStream = new FileInputStream(tempFile);
+		wb = new HSSFWorkbook(readStream);
+		sheet = wb.getSheetAt(0);
+		readStream.close();
+
+
+		assertEquals(sheet.isDisplayGridlines(), false);
+		assertEquals(sheet.isDisplayRowColHeadings(), false);
+		assertEquals(sheet.isDisplayFormulas(), true);
+	}
+
+
+	/**
+	 * Make sure the excel file loads work
+	 *
+	 */
+	public void testPageBreakFiles() throws Exception{
+		HSSFWorkbook wb = openSample("SimpleWithPageBreaks.xls");
+
+		HSSFSheet sheet = wb.getSheetAt(0);
+		assertNotNull(sheet);
+
+		assertEquals("1 row page break", 1, sheet.getRowBreaks().length);
+		assertEquals("1 column page break", 1, sheet.getColumnBreaks().length);
+
+		assertTrue("No row page break", sheet.isRowBroken(22));
+		assertTrue("No column page break", sheet.isColumnBroken((short)4));
+
+		sheet.setRowBreak(10);
+		sheet.setColumnBreak((short)13);
+
+		assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
+		assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
+
+		File tempFile = TempFile.createTempFile("display", "testPagebreaks.xls");
+		FileOutputStream stream = new FileOutputStream(tempFile);
+		wb.write(stream);
+		stream.close();
+
+		wb = new HSSFWorkbook(new FileInputStream(tempFile));
+		sheet = wb.getSheetAt(0);
+
+		assertTrue("No row page break", sheet.isRowBroken(22));
+		assertTrue("No column page break", sheet.isColumnBroken((short)4));
+
+
+		assertEquals("row breaks number", 2, sheet.getRowBreaks().length);
+		assertEquals("column breaks number", 2, sheet.getColumnBreaks().length);
+
+
+	}
+
+	public void testDBCSName () throws Exception {
+		HSSFWorkbook wb = openSample("DBCSSheetName.xls");
+		HSSFSheet s= wb.getSheetAt(1);
+		assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" );
+		assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e");
+	}
+
+	/**
+	 * Testing newly added method that exposes the WINDOW2.toprow
+	 * parameter to allow setting the toprow in the visible view
+	 * of the sheet when it is first opened.
+	 */
+	public void testTopRow() {
+		HSSFWorkbook wb = openSample("SimpleWithPageBreaks.xls");
+
+		HSSFSheet sheet = wb.getSheetAt(0);
+		assertNotNull(sheet);
+
+		short toprow = (short) 100;
+		short leftcol = (short) 50;
+		sheet.showInPane(toprow,leftcol);
+		assertEquals("HSSFSheet.getTopRow()", toprow, sheet.getTopRow());
+		assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol());
+	}
+
+	/** cell with formula becomes null on cloning a sheet*/
 	 public void test35084() {
-   	
+   
    	HSSFWorkbook wb = new HSSFWorkbook();
    	HSSFSheet s =wb.createSheet("Sheet1");
    	HSSFRow r = s.createRow(0);
@@ -696,8 +656,8 @@
    	assertEquals("formula", r.getCell((short)1).getCellFormula(), "A1*2");
    }
 
-    /** test that new default column styles get applied */
-    public void testDefaultColumnStyle() {
+	/** test that new default column styles get applied */
+	public void testDefaultColumnStyle() {
 	HSSFWorkbook wb = new HSSFWorkbook();
 	HSSFCellStyle style = wb.createCellStyle();
 	HSSFSheet s = wb.createSheet();
@@ -705,53 +665,42 @@
 	HSSFRow r = s.createRow(0);
 	HSSFCell c = r.createCell((short)0);
 	assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
-    }
+	}
 
 
-    /**
-     *
-     */
-    public void testAddEmptyRow() throws Exception {
-        //try to add 5 empty rows to a new sheet
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        HSSFSheet sheet = workbook.createSheet();
-        for (int i = 0; i < 5; i++) sheet.createRow(i);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        workbook.write(out);
-        out.close();
-
-        workbook = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
-        assertTrue("No Exceptions while reading file", true);
-
-        //try adding empty rows in an existing worksheet
-        String cwd = System.getProperty("HSSF.testdata.path");
-        FileInputStream in = new FileInputStream(new File(cwd, "Simple.xls"));
-        workbook = new HSSFWorkbook(in);
-        in.close();
-        assertTrue("No Exceptions while reading file", true);
-
-        sheet = workbook.getSheetAt(0);
-        for (int i = 3; i < 10; i++) sheet.createRow(i);
-
-        out = new ByteArrayOutputStream();
-        workbook.write(out);
-        out.close();
-
-        workbook = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
-        assertTrue("No Exceptions while reading file", true);
-
-    }
-    
-    public void testAutoSizeColumn() throws Exception {
-		String filename = System.getProperty("HSSF.testdata.path");
-		filename = filename + "/43902.xls";
+	/**
+	 *
+	 */
+	public void testAddEmptyRow() throws Exception {
+		//try to add 5 empty rows to a new sheet
+		HSSFWorkbook workbook = new HSSFWorkbook();
+		HSSFSheet sheet = workbook.createSheet();
+		for (int i = 0; i < 5; i++) sheet.createRow(i);
+
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		workbook.write(out);
+		out.close();
+
+		workbook = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+
+		//try adding empty rows in an existing worksheet
+		workbook = openSample("Simple.xls");
+
+		sheet = workbook.getSheetAt(0);
+		for (int i = 3; i < 10; i++) sheet.createRow(i);
+
+		out = new ByteArrayOutputStream();
+		workbook.write(out);
+		out.close();
+
+		workbook = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+	}
+
+	public void testAutoSizeColumn() throws Exception {
+		HSSFWorkbook wb = openSample("43902.xls");
 		String sheetName = "my sheet";
-		FileInputStream is = new FileInputStream(filename);
-		POIFSFileSystem fs = new POIFSFileSystem(is);
-		HSSFWorkbook wb = new HSSFWorkbook(fs);
 		HSSFSheet sheet = wb.getSheet(sheetName);
-		
+
 		// Can't use literal numbers for column sizes, as
 		//  will come out with different values on different
 		//  machines based on the fonts available.
@@ -761,27 +710,27 @@
 		int maxWithRow1And2 = 7800;
 		int minWithRow1Only = 2750;
 		int maxWithRow1Only = 3300;
-		
+
 		// autoSize the first column and check its size before the merged region (1,0,1,1) is set:
 		// it has to be based on the 2nd row width
 		sheet.autoSizeColumn((short)0);
 		assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth((short)0) >= minWithRow1And2);
 		assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth((short)0) <= maxWithRow1And2);
-		
+
 		//create a region over the 2nd row and auto size the first column
 		sheet.addMergedRegion(new Region(1,(short)0,1,(short)1));
 		sheet.autoSizeColumn((short)0);
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		wb.write(out);
 		out.close();
-		
+
 		// check that the autoSized column width has ignored the 2nd row 
 		// because it is included in a merged region (Excel like behavior)
 		HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
 		HSSFSheet sheet2 = wb2.getSheet(sheetName);
 		assertTrue(sheet2.getColumnWidth((short)0) >= minWithRow1Only);
 		assertTrue(sheet2.getColumnWidth((short)0) <= maxWithRow1Only);
-		
+
 		// remove the 2nd row merged region and check that the 2nd row value is used to the autoSizeColumn width
 		sheet2.removeMergedRegion(1);
 		sheet2.autoSizeColumn((short)0);
@@ -792,143 +741,140 @@
 		HSSFSheet sheet3 = wb3.getSheet(sheetName);
 		assertTrue(sheet3.getColumnWidth((short)0) >= minWithRow1And2);
 		assertTrue(sheet3.getColumnWidth((short)0) <= maxWithRow1And2);
-    }
+	}
 
-    /**
-     * Setting ForceFormulaRecalculation on sheets
-     */
-    public void testForceRecalculation() throws Exception {
-        String filename = System.getProperty("HSSF.testdata.path");
-        filename = filename + "/UncalcedRecord.xls";
-        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filename));
-        
-        HSSFSheet sheet = workbook.getSheetAt(0);
-        HSSFSheet sheet2 = workbook.getSheetAt(0);
-        HSSFRow row = sheet.getRow(0);
-        row.createCell((short) 0).setCellValue(5);
-        row.createCell((short) 1).setCellValue(8);
+	/**
+	 * Setting ForceFormulaRecalculation on sheets
+	 */
+	public void testForceRecalculation() throws Exception {
+		HSSFWorkbook workbook = openSample("UncalcedRecord.xls");
+
+		HSSFSheet sheet = workbook.getSheetAt(0);
+		HSSFSheet sheet2 = workbook.getSheetAt(0);
+		HSSFRow row = sheet.getRow(0);
+		row.createCell((short) 0).setCellValue(5);
+		row.createCell((short) 1).setCellValue(8);
 		assertFalse(sheet.getForceFormulaRecalculation());
 		assertFalse(sheet2.getForceFormulaRecalculation());
 
-        // Save and manually verify that on column C we have 0, value in template
-        File tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_err.xls" );
-        tempFile.delete();
-        FileOutputStream fout = new FileOutputStream( tempFile );
-        workbook.write( fout );
-        fout.close();
-        sheet.setForceFormulaRecalculation(true);
+		// Save and manually verify that on column C we have 0, value in template
+		File tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_err.xls" );
+		tempFile.delete();
+		FileOutputStream fout = new FileOutputStream( tempFile );
+		workbook.write( fout );
+		fout.close();
+		sheet.setForceFormulaRecalculation(true);
 		assertTrue(sheet.getForceFormulaRecalculation());
 
-        // Save and manually verify that on column C we have now 13, calculated value
-        tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_succ.xls" );
-        tempFile.delete();
-        fout = new FileOutputStream( tempFile );
-        workbook.write( fout );
-        fout.close();
+		// Save and manually verify that on column C we have now 13, calculated value
+		tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_succ.xls" );
+		tempFile.delete();
+		fout = new FileOutputStream( tempFile );
+		workbook.write( fout );
+		fout.close();
 
-        // Try it can be opened
+		// Try it can be opened
 		HSSFWorkbook wb2 = new HSSFWorkbook(new FileInputStream(tempFile));
-		
+
 		// And check correct sheet settings found
 		sheet = wb2.getSheetAt(0);
 		sheet2 = wb2.getSheetAt(1);
 		assertTrue(sheet.getForceFormulaRecalculation());
 		assertFalse(sheet2.getForceFormulaRecalculation());
-		
+
 		// Now turn if back off again
 		sheet.setForceFormulaRecalculation(false);
-		
-        fout = new FileOutputStream( tempFile );
-        wb2.write( fout );
-        fout.close();
-        wb2 = new HSSFWorkbook(new FileInputStream(tempFile));
-        
+
+		fout = new FileOutputStream( tempFile );
+		wb2.write( fout );
+		fout.close();
+		wb2 = new HSSFWorkbook(new FileInputStream(tempFile));
+
 		assertFalse(wb2.getSheetAt(0).getForceFormulaRecalculation());
 		assertFalse(wb2.getSheetAt(1).getForceFormulaRecalculation());
 		assertFalse(wb2.getSheetAt(2).getForceFormulaRecalculation());
-		
+
 		// Now add a new sheet, and check things work
 		//  with old ones unset, new one set
 		HSSFSheet s4 = wb2.createSheet();
 		s4.setForceFormulaRecalculation(true);
-		
+
 		assertFalse(sheet.getForceFormulaRecalculation());
 		assertFalse(sheet2.getForceFormulaRecalculation());
 		assertTrue(s4.getForceFormulaRecalculation());
-		
-        fout = new FileOutputStream( tempFile );
-        wb2.write( fout );
-        fout.close();
-        
+
+		fout = new FileOutputStream( tempFile );
+		wb2.write( fout );
+		fout.close();
+
 		HSSFWorkbook wb3 = new HSSFWorkbook(new FileInputStream(tempFile));
 		assertFalse(wb3.getSheetAt(0).getForceFormulaRecalculation());
 		assertFalse(wb3.getSheetAt(1).getForceFormulaRecalculation());
 		assertFalse(wb3.getSheetAt(2).getForceFormulaRecalculation());
 		assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation());
-    }
+	}
 
-    
-    public static void main(java.lang.String[] args) {
+
+	public static void main(java.lang.String[] args) {
 		 junit.textui.TestRunner.run(TestHSSFSheet.class);
 	}
 
-    public void testColumnWidth() throws Exception {
-        //check we can correctly read column widths from a reference workbook
-        String filename = System.getProperty("HSSF.testdata.path") + "/colwidth.xls";
-        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filename));
-
-        //reference values
-        int[] ref = {365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657};
-
-        HSSFSheet sh = wb.getSheetAt(0);
-        for (char i = 'A'; i <= 'S'; i++) {
-            int idx = i - 'A';
-            int w = sh.getColumnWidth((short)idx);
-            assertEquals(ref[idx], w);
-        }
-
-        //the second sheet doesn't have overridden column widths
-        sh = wb.getSheetAt(1);
-        int def_width = sh.getDefaultColumnWidth();
-        for (char i = 'A'; i <= 'S'; i++) {
-            int idx = i - 'A';
-            int w = sh.getColumnWidth((short)idx);
-            //getDefaultColumnWidth returns width measued in characters
-            //getColumnWidth returns width measued in 1/256th units
-            assertEquals(def_width*256, w);
-        }
-
-        //test new workbook
-        wb = new HSSFWorkbook();
-        sh = wb.createSheet();
-        sh.setDefaultColumnWidth((short)10);
-        assertEquals(10, sh.getDefaultColumnWidth());
-        assertEquals(256*10, sh.getColumnWidth((short)0));
-        assertEquals(256*10, sh.getColumnWidth((short)1));
-        assertEquals(256*10, sh.getColumnWidth((short)2));
-        for (char i = 'D'; i <= 'F'; i++) {
-            short w = (short)(256*12);
-            sh.setColumnWidth((short)i, w);
-            assertEquals(w, sh.getColumnWidth((short)i));
-        }
-
-        //serialize and read again
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        wb.write(out);
-        out.close();
-
-        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
-        sh = wb.getSheetAt(0);
-        assertEquals(10, sh.getDefaultColumnWidth());
-        //columns A-C have default width
-        assertEquals(256*10, sh.getColumnWidth((short)0));
-        assertEquals(256*10, sh.getColumnWidth((short)1));
-        assertEquals(256*10, sh.getColumnWidth((short)2));
-        //columns D-F have custom wodth
-        for (char i = 'D'; i <= 'F'; i++) {
-            short w = (short)(256*12);
-            assertEquals(w, sh.getColumnWidth((short)i));
-        }
+	public void testColumnWidth() throws Exception {
+		//check we can correctly read column widths from a reference workbook
+		HSSFWorkbook wb = openSample("colwidth.xls");
+
+		//reference values
+		int[] ref = {365, 548, 731, 914, 1097, 1280, 1462, 1645, 1828, 2011, 2194, 2377, 2560, 2742, 2925, 3108, 3291, 3474, 3657};
+
+		HSSFSheet sh = wb.getSheetAt(0);
+		for (char i = 'A'; i <= 'S'; i++) {
+			int idx = i - 'A';
+			int w = sh.getColumnWidth((short)idx);
+			assertEquals(ref[idx], w);
+		}
+
+		//the second sheet doesn't have overridden column widths
+		sh = wb.getSheetAt(1);
+		int def_width = sh.getDefaultColumnWidth();
+		for (char i = 'A'; i <= 'S'; i++) {
+			int idx = i - 'A';
+			int w = sh.getColumnWidth((short)idx);
+			//getDefaultColumnWidth returns width measued in characters
+			//getColumnWidth returns width measued in 1/256th units
+			assertEquals(def_width*256, w);
+		}
+
+		//test new workbook
+		wb = new HSSFWorkbook();
+		sh = wb.createSheet();
+		sh.setDefaultColumnWidth((short)10);
+		assertEquals(10, sh.getDefaultColumnWidth());
+		assertEquals(256*10, sh.getColumnWidth((short)0));
+		assertEquals(256*10, sh.getColumnWidth((short)1));
+		assertEquals(256*10, sh.getColumnWidth((short)2));
+		for (char i = 'D'; i <= 'F'; i++) {
+			short w = (short)(256*12);
+			sh.setColumnWidth((short)i, w);
+			assertEquals(w, sh.getColumnWidth((short)i));
+		}
+
+		//serialize and read again
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		wb.write(out);
+		out.close();
 
-    }
+		wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		sh = wb.getSheetAt(0);
+		assertEquals(10, sh.getDefaultColumnWidth());
+		//columns A-C have default width
+		assertEquals(256*10, sh.getColumnWidth((short)0));
+		assertEquals(256*10, sh.getColumnWidth((short)1));
+		assertEquals(256*10, sh.getColumnWidth((short)2));
+		//columns D-F have custom wodth
+		for (char i = 'D'; i <= 'F'; i++) {
+			short w = (short)(256*12);
+			assertEquals(w, sh.getColumnWidth((short)i));
+		}
+
+	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=645483&r1=645482&r2=645483&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Mon Apr  7 05:51:50 2008
@@ -14,28 +14,22 @@
 * 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;
+import junit.framework.TestCase;
 
-import junit.framework.*;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.NameRecord;
+/**
+ * 
+ */
+public final class TestHSSFWorkbook extends TestCase {
+    private static HSSFWorkbook openSample(String sampleFileName) {
+        return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+    }
 
-public class TestHSSFWorkbook extends TestCase
-{
-    HSSFWorkbook hssfWorkbook;
-    String filename;
-
-	protected void setUp() throws Exception {
-		super.setUp();
-        filename = System.getProperty("HSSF.testdata.path");
-	}
-
-	public void testSetRepeatingRowsAndColumns() throws Exception
-    {
+    public void testSetRepeatingRowsAndColumns() {
         // Test bug 29747
         HSSFWorkbook b = new HSSFWorkbook( );
         b.createSheet();
@@ -46,9 +40,7 @@
         assertEquals( 3, nameRecord.getIndexToSheet() );
     }
     
-    public void testDuplicateNames()
-            throws Exception
-    {
+    public void testDuplicateNames() {
         HSSFWorkbook b = new HSSFWorkbook( );
         b.createSheet("Sheet1");
         b.createSheet();
@@ -105,15 +97,15 @@
     public void testSheetSelection() {
         HSSFWorkbook b = new HSSFWorkbook();
         b.createSheet("Sheet One");
-        HSSFSheet s = b.createSheet("Sheet Two");
+        b.createSheet("Sheet Two");
         b.setSelectedTab((short) 1);
         b.setDisplayedTab((short) 1);
         assertEquals(b.getSelectedTab(), 1);
         assertEquals(b.getDisplayedTab(), 1);
     }
     
-    public void testSheetClone() throws Exception {
-    	// First up, try a simple file
+    public void testSheetClone() {
+        // First up, try a simple file
         HSSFWorkbook b = new HSSFWorkbook();
         assertEquals(0, b.getNumberOfSheets());
         b.createSheet("Sheet One");
@@ -122,24 +114,20 @@
         assertEquals(2, b.getNumberOfSheets());
         b.cloneSheet(0);
         assertEquals(3, b.getNumberOfSheets());
-    	
-    	// Now try a problem one with drawing records in it
-        b = new HSSFWorkbook(
-        		new FileInputStream(new File(filename,"SheetWithDrawing.xls"))
-        );
+        
+        // Now try a problem one with drawing records in it
+        b = openSample("SheetWithDrawing.xls");
         assertEquals(1, b.getNumberOfSheets());
         b.cloneSheet(0);
         assertEquals(2, b.getNumberOfSheets());
     }
     
-    public void testReadWriteWithCharts() throws Exception {
+    public void testReadWriteWithCharts() {
         HSSFWorkbook b;
         HSSFSheet s;
         
         // Single chart, two sheets
-        b = new HSSFWorkbook(
-        		new FileInputStream(new File(filename,"44010-SingleChart.xls"))
-        );
+        b = openSample("44010-SingleChart.xls");
         assertEquals(2, b.getNumberOfSheets());
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
@@ -154,9 +142,7 @@
         // We've now called getDrawingPatriarch() so 
         //  everything will be all screwy
         // So, start again
-        b = new HSSFWorkbook(
-        		new FileInputStream(new File(filename,"44010-SingleChart.xls"))
-        );
+        b = openSample("44010-SingleChart.xls");
         
         b = writeRead(b);
         assertEquals(2, b.getNumberOfSheets());
@@ -166,9 +152,7 @@
 
         
         // Two charts, three sheets
-        b = new HSSFWorkbook(
-        		new FileInputStream(new File(filename,"44010-TwoCharts.xls"))
-        );
+        b = openSample("44010-TwoCharts.xls");
         assertEquals(3, b.getNumberOfSheets());
         
         s = b.getSheetAt(1);
@@ -188,9 +172,7 @@
         // We've now called getDrawingPatriarch() so 
         //  everything will be all screwy
         // So, start again
-        b = new HSSFWorkbook(
-        		new FileInputStream(new File(filename,"44010-TwoCharts.xls"))
-        );
+        b = openSample("44010-TwoCharts.xls");
         
         b = writeRead(b);
         assertEquals(3, b.getNumberOfSheets());
@@ -203,11 +185,7 @@
         assertEquals(0, s.getLastRowNum());
     }
     
-    private HSSFWorkbook writeRead(HSSFWorkbook b) throws Exception {
-    	ByteArrayOutputStream baos = new ByteArrayOutputStream();
-    	b.write(baos);
-    	return new HSSFWorkbook(
-    			new ByteArrayInputStream(baos.toByteArray())
-    	);
+    private static HSSFWorkbook writeRead(HSSFWorkbook b) {
+    	return HSSFTestDataSamples.writeOutAndReadBack(b);
     }
 }



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


Mime
View raw message