You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/01/25 16:48:23 UTC

svn commit: r615249 [3/3] - in /poi/tags/REL_3_0_2_BETA3: ./ src/documentation/content/xdocs/ src/documentation/content/xdocs/hssf/ src/java/org/apache/poi/ddf/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apach...

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Fri Jan 25 07:48:14 2008
@@ -913,7 +913,104 @@
 
     }
 
-    
+    /**
+     * Bug 44200: Sheet not cloneable when Note added to excel cell
+     */
+    public void test44200() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "44200.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        wb.cloneSheet(0);
+        assertTrue("No Exceptions while cloning sheet", true);
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No Exceptions while reading file", true);
+
+    }
+
+    /**
+     * Bug 44201: Sheet not cloneable when validation added to excel cell
+     */
+    public void test44201() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "44201.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        wb.cloneSheet(0);
+        assertTrue("No Exceptions while cloning sheet", true);
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No Exceptions while reading file", true);
+
+    }
+
+    /**
+     * Bug 37684  : Unhandled Continue Record Error
+     */
+    public void test37684 () throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "37684-1.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        assertTrue("No exceptions while reading workbook", true);
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+        assertTrue("No exceptions while saving workbook", true);
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No exceptions while reading saved stream", true);
+
+
+        in = new FileInputStream(new File(cwd, "37684-2.xls"));
+        wb = new HSSFWorkbook(in);
+        in.close();
+
+        assertTrue("No exceptions while reading workbook", true);
+
+        //serialize and read again
+        out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+        assertTrue("No exceptions while saving workbook", true);
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No exceptions while reading saved stream", true);
+    }
+
+    /**
+     * Bug 41139: Constructing HSSFWorkbook is failed,threw threw ArrayIndexOutOfBoundsException for creating UnknownRecord
+     */
+    public void test41139() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "41139.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        assertTrue("No Exceptions while reading file", true);
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No Exceptions while reading file", true);
+
+    }
+
 }
 
 

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java Fri Jan 25 07:48:14 2008
@@ -20,24 +20,36 @@
 import junit.framework.TestCase;
 
 import java.awt.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 
 /**
  * Tests the capabilities of the EscherGraphics class.
+ * 
+ * All tests have two escher groups available to them,
+ *  one anchored at 0,0,1022,255 and another anchored
+ *  at 20,30,500,200 
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
 public class TestEscherGraphics extends TestCase
 {
-    private HSSFShapeGroup escherGroup;
+	private HSSFWorkbook workbook;
+	private HSSFPatriarch patriarch;
+    private HSSFShapeGroup escherGroupA;
+    private HSSFShapeGroup escherGroupB;
     private EscherGraphics graphics;
 
     protected void setUp() throws Exception
     {
-        HSSFWorkbook workbook = new HSSFWorkbook();
+        workbook = new HSSFWorkbook();
+        
         HSSFSheet sheet = workbook.createSheet("test");
-        escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0));
-        escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor());
-        graphics = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f);
+        patriarch = sheet.createDrawingPatriarch();
+        escherGroupA = patriarch.createGroup(new HSSFClientAnchor(0,0,1022,255,(short)0,0,(short) 0,0));
+        escherGroupB = patriarch.createGroup(new HSSFClientAnchor(20,30,500,200,(short)0,0,(short) 0,0));
+//        escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor());
+        graphics = new EscherGraphics(this.escherGroupA, workbook, Color.black, 1.0f);
         super.setUp();
     }
 
@@ -74,7 +86,7 @@
     public void testFillRect() throws Exception
     {
         graphics.fillRect( 10, 10, 20, 20 );
-        HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
+        HSSFSimpleShape s = (HSSFSimpleShape) escherGroupA.getChildren().get(0);
         assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType());
         assertEquals(10, s.getAnchor().getDx1());
         assertEquals(10, s.getAnchor().getDy1());
@@ -85,8 +97,198 @@
     public void testDrawString() throws Exception
     {
         graphics.drawString("This is a test", 10, 10);
-        HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0);
+        HSSFTextbox t = (HSSFTextbox) escherGroupA.getChildren().get(0);
         assertEquals("This is a test", t.getString().getString().toString());
     }
 
+    public void testGetDataBackAgain() throws Exception {
+    	HSSFSheet s;
+    	HSSFShapeGroup s1;
+    	HSSFShapeGroup s2;
+    	
+    	patriarch.setCoordinates(10, 20, 30, 40);
+    	
+    	ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    	workbook.write(baos);
+    	workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
+    	s = workbook.getSheetAt(0);
+    	
+    	patriarch = s.getDrawingPatriarch();
+    	
+    	assertNotNull(patriarch);
+    	assertEquals(10, patriarch.getX1());
+    	assertEquals(20, patriarch.getY1());
+    	assertEquals(30, patriarch.getX2());
+    	assertEquals(40, patriarch.getY2());
+    	
+    	// Check the two groups too
+    	assertEquals(2, patriarch.countOfAllChildren());
+    	assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+    	assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
+    	
+    	s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+    	s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+    	
+    	assertEquals(0, s1.getX1());
+    	assertEquals(0, s1.getY1());
+    	assertEquals(1023, s1.getX2());
+    	assertEquals(255, s1.getY2());
+    	assertEquals(0, s2.getX1());
+    	assertEquals(0, s2.getY1());
+    	assertEquals(1023, s2.getX2());
+    	assertEquals(255, s2.getY2());
+    	
+    	assertEquals(0, s1.getAnchor().getDx1());
+    	assertEquals(0, s1.getAnchor().getDy1());
+    	assertEquals(1022, s1.getAnchor().getDx2());
+    	assertEquals(255, s1.getAnchor().getDy2());
+    	assertEquals(20, s2.getAnchor().getDx1());
+    	assertEquals(30, s2.getAnchor().getDy1());
+    	assertEquals(500, s2.getAnchor().getDx2());
+    	assertEquals(200, s2.getAnchor().getDy2());
+    	
+    	
+    	// Write and re-load once more, to check that's ok
+    	baos = new ByteArrayOutputStream();
+    	workbook.write(baos);
+    	workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
+    	s = workbook.getSheetAt(0);
+    	patriarch = s.getDrawingPatriarch();
+    	
+    	assertNotNull(patriarch);
+    	assertEquals(10, patriarch.getX1());
+    	assertEquals(20, patriarch.getY1());
+    	assertEquals(30, patriarch.getX2());
+    	assertEquals(40, patriarch.getY2());
+    	
+    	// Check the two groups too
+    	assertEquals(2, patriarch.countOfAllChildren());
+    	assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+    	assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
+    	
+    	s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+    	s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+    	
+    	assertEquals(0, s1.getX1());
+    	assertEquals(0, s1.getY1());
+    	assertEquals(1023, s1.getX2());
+    	assertEquals(255, s1.getY2());
+    	assertEquals(0, s2.getX1());
+    	assertEquals(0, s2.getY1());
+    	assertEquals(1023, s2.getX2());
+    	assertEquals(255, s2.getY2());
+    	
+    	assertEquals(0, s1.getAnchor().getDx1());
+    	assertEquals(0, s1.getAnchor().getDy1());
+    	assertEquals(1022, s1.getAnchor().getDx2());
+    	assertEquals(255, s1.getAnchor().getDy2());
+    	assertEquals(20, s2.getAnchor().getDx1());
+    	assertEquals(30, s2.getAnchor().getDy1());
+    	assertEquals(500, s2.getAnchor().getDx2());
+    	assertEquals(200, s2.getAnchor().getDy2());
+    	
+    	// Change the positions of the first groups,
+    	//  but not of their anchors
+    	s1.setCoordinates(2, 3, 1021, 242);
+    	
+    	baos = new ByteArrayOutputStream();
+    	workbook.write(baos);
+    	workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
+    	s = workbook.getSheetAt(0);
+    	patriarch = s.getDrawingPatriarch();
+    	
+    	assertNotNull(patriarch);
+    	assertEquals(10, patriarch.getX1());
+    	assertEquals(20, patriarch.getY1());
+    	assertEquals(30, patriarch.getX2());
+    	assertEquals(40, patriarch.getY2());
+    	
+    	// Check the two groups too
+    	assertEquals(2, patriarch.countOfAllChildren());
+    	assertEquals(2, patriarch.getChildren().size());
+    	assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+    	assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
+    	
+    	s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+    	s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+    	
+    	assertEquals(2, s1.getX1());
+    	assertEquals(3, s1.getY1());
+    	assertEquals(1021, s1.getX2());
+    	assertEquals(242, s1.getY2());
+    	assertEquals(0, s2.getX1());
+    	assertEquals(0, s2.getY1());
+    	assertEquals(1023, s2.getX2());
+    	assertEquals(255, s2.getY2());
+    	
+    	assertEquals(0, s1.getAnchor().getDx1());
+    	assertEquals(0, s1.getAnchor().getDy1());
+    	assertEquals(1022, s1.getAnchor().getDx2());
+    	assertEquals(255, s1.getAnchor().getDy2());
+    	assertEquals(20, s2.getAnchor().getDx1());
+    	assertEquals(30, s2.getAnchor().getDy1());
+    	assertEquals(500, s2.getAnchor().getDx2());
+    	assertEquals(200, s2.getAnchor().getDy2());
+    	
+    	
+    	// Now add some text to one group, and some more
+    	//  to the base, and check we can get it back again
+    	HSSFTextbox tbox1 =
+    		patriarch.createTextbox(new HSSFClientAnchor(1,2,3,4, (short)0,0,(short)0,0));
+    	tbox1.setString(new HSSFRichTextString("I am text box 1"));
+    	HSSFTextbox tbox2 =
+    		s2.createTextbox(new HSSFChildAnchor(41,42,43,44));
+    	tbox2.setString(new HSSFRichTextString("This is text box 2"));
+    	
+    	assertEquals(3, patriarch.getChildren().size());
+    	
+    	
+    	baos = new ByteArrayOutputStream();
+    	workbook.write(baos);
+    	workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
+    	s = workbook.getSheetAt(0);
+    	
+    	patriarch = s.getDrawingPatriarch();
+    	
+    	assertNotNull(patriarch);
+    	assertEquals(10, patriarch.getX1());
+    	assertEquals(20, patriarch.getY1());
+    	assertEquals(30, patriarch.getX2());
+    	assertEquals(40, patriarch.getY2());
+    	
+    	// Check the two groups and the text
+    	assertEquals(3, patriarch.countOfAllChildren());
+    	assertEquals(2, patriarch.getChildren().size());
+    	
+    	// Should be two groups and a text
+    	assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+    	assertTrue(patriarch.getChildren().get(1) instanceof HSSFTextbox);
+//    	assertTrue(patriarch.getChildren().get(2) instanceof HSSFShapeGroup);
+    	
+    	s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+    	tbox1 = (HSSFTextbox)patriarch.getChildren().get(1);
+    	
+//    	s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+    	
+    	assertEquals(2, s1.getX1());
+    	assertEquals(3, s1.getY1());
+    	assertEquals(1021, s1.getX2());
+    	assertEquals(242, s1.getY2());
+    	assertEquals(0, s2.getX1());
+    	assertEquals(0, s2.getY1());
+    	assertEquals(1023, s2.getX2());
+    	assertEquals(255, s2.getY2());
+    	
+    	assertEquals(0, s1.getAnchor().getDx1());
+    	assertEquals(0, s1.getAnchor().getDy1());
+    	assertEquals(1022, s1.getAnchor().getDx2());
+    	assertEquals(255, s1.getAnchor().getDy2());
+    	assertEquals(20, s2.getAnchor().getDx1());
+    	assertEquals(30, s2.getAnchor().getDy1());
+    	assertEquals(500, s2.getAnchor().getDx2());
+    	assertEquals(200, s2.getAnchor().getDy2());
+    	
+    	// Not working just yet
+    	//assertEquals("I am text box 1", tbox1.getString().getString());
+    }
 }

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java Fri Jan 25 07:48:14 2008
@@ -1127,6 +1127,17 @@
 		cell.setCellFormula("IF(A1=\"A\",1,)");
 	}
     
+	public void testSharedFormula() throws Exception {
+		String readFilename = System.getProperty("HSSF.testdata.path");	
+		File inFile = new File(readFilename+"/SharedFormulaTest.xls");
+		FileInputStream fis = new FileInputStream(inFile);
+		HSSFWorkbook wb = new HSSFWorkbook(fis);
+		
+		assertEquals("A$1*2", wb.getSheetAt(0).getRow(1).getCell((short)1).toString());
+		assertEquals("$A11*2", wb.getSheetAt(0).getRow(11).getCell((short)1).toString());
+		assertEquals("DZ2*2", wb.getSheetAt(0).getRow(1).getCell((short)128).toString());
+		assertEquals("B32770*2", wb.getSheetAt(0).getRow(32768).getCell((short)1).toString());
+	}
     
     public static void main(String [] args) {
         System.out

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java Fri Jan 25 07:48:14 2008
@@ -56,6 +56,11 @@
         row.createCell((short) 1);
         assertEquals(1, row.getFirstCellNum());
         assertEquals(2, row.getLastCellNum());
+        
+        // check the exact case reported in 'bug' 43901 - notice that the cellNum is '0' based
+        row.createCell((short) 3);
+        assertEquals(1, row.getFirstCellNum());
+        assertEquals(3, row.getLastCellNum());
 
     }
 
@@ -97,8 +102,49 @@
         file.delete();
         assertEquals(-1, sheet.getRow((short) 0).getLastCellNum());
         assertEquals(-1, sheet.getRow((short) 0).getFirstCellNum());
-
-
+    }
+    
+    public void testMoveCell() throws Exception {
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet sheet = workbook.createSheet();
+        HSSFRow row = sheet.createRow((short) 0);
+        HSSFRow rowB = sheet.createRow((short) 1);
+        
+        HSSFCell cellA2 = rowB.createCell((short)0);
+        assertEquals(0, rowB.getFirstCellNum());
+        assertEquals(0, rowB.getFirstCellNum());
+        
+        assertEquals(-1, row.getLastCellNum());
+        assertEquals(-1, row.getFirstCellNum());
+        HSSFCell cellB2 = row.createCell((short) 1);
+        HSSFCell cellB3 = row.createCell((short) 2);
+        HSSFCell cellB4 = row.createCell((short) 3);
+    	
+        assertEquals(1, row.getFirstCellNum());
+        assertEquals(3, row.getLastCellNum());
+        
+        // Try to move to somewhere else that's used
+        try {
+        	row.moveCell(cellB2, (short)3);
+        	fail();
+        } catch(IllegalArgumentException e) {}
+        
+        // Try to move one off a different row
+        try {
+        	row.moveCell(cellA2, (short)3);
+        	fail();
+        } catch(IllegalArgumentException e) {}
+        
+        // Move somewhere spare
+        assertNotNull(row.getCell((short)1));
+    	row.moveCell(cellB2, (short)5);
+        assertNull(row.getCell((short)1));
+        assertNotNull(row.getCell((short)5));
+    	
+    	assertEquals(5, cellB2.getCellNum());
+        assertEquals(2, row.getFirstCellNum());
+        assertEquals(5, row.getLastCellNum());
+        
     }
     
     public void testRowBounds()

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java Fri Jan 25 07:48:14 2008
@@ -19,19 +19,24 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.record.HCenterRecord;
-import org.apache.poi.hssf.record.ProtectRecord;
 import org.apache.poi.hssf.record.PasswordRecord;
+import org.apache.poi.hssf.record.ProtectRecord;
 import org.apache.poi.hssf.record.SCLRecord;
 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.hssf.util.Region;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.TempFile;
 
 /**
@@ -224,6 +229,212 @@
         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());
+    }
+    
 	/**
 	 * Test that the ProtectRecord is included when creating or cloning a sheet
 	 */
@@ -531,8 +742,133 @@
         assertTrue("No Exceptions while reading file", true);
 
     }
+    
+    public void testAutoSizeColumn() throws Exception {
+		String filename = System.getProperty("HSSF.testdata.path");
+		filename = filename + "/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.
+		// So, we use ranges, which are pretty large, but
+		//  thankfully don't overlap!
+		int minWithRow1And2 = 6400; 
+		int maxWithRow1And2 = 7800;
+		int minWithRow1Only = 3024;
+		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);
+		out = new ByteArrayOutputStream();
+		wb2.write(out);
+		out.close();
+		HSSFWorkbook wb3 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		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);
+		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);
+		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();
 
-	public static void main(java.lang.String[] args) {
+        // 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));
+        
+		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();
+        
+		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) {
 		 junit.textui.TestRunner.run(TestHSSFSheet.class);
 	}    
 }

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Fri Jan 25 07:48:14 2008
@@ -16,14 +16,25 @@
 */
 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.*;
 import org.apache.poi.hssf.record.NameRecord;
 
 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() throws Exception
     {
         // Test bug 29747
         HSSFWorkbook b = new HSSFWorkbook( );
@@ -34,7 +45,7 @@
         NameRecord nameRecord = b.getWorkbook().getNameRecord( 0 );
         assertEquals( 3, nameRecord.getIndexToSheet() );
     }
-
+    
     public void testDuplicateNames()
             throws Exception
     {
@@ -99,5 +110,104 @@
         b.setDisplayedTab((short) 1);
         assertEquals(b.getSelectedTab(), 1);
         assertEquals(b.getDisplayedTab(), 1);
+    }
+    
+    public void testSheetClone() throws Exception {
+    	// First up, try a simple file
+        HSSFWorkbook b = new HSSFWorkbook();
+        assertEquals(0, b.getNumberOfSheets());
+        b.createSheet("Sheet One");
+        b.createSheet("Sheet Two");
+        
+        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"))
+        );
+        assertEquals(1, b.getNumberOfSheets());
+        b.cloneSheet(0);
+        assertEquals(2, b.getNumberOfSheets());
+    }
+    
+    public void testReadWriteWithCharts() throws Exception {
+        HSSFWorkbook b;
+        HSSFSheet s;
+        
+        // Single chart, two sheets
+        b = new HSSFWorkbook(
+        		new FileInputStream(new File(filename,"44010-SingleChart.xls"))
+        );
+        assertEquals(2, b.getNumberOfSheets());
+        s = b.getSheetAt(1);
+        assertEquals(0, s.getFirstRowNum());
+        assertEquals(0, s.getLastRowNum());
+        
+        // Has chart on 1st sheet??
+        // FIXME
+        assertNotNull(b.getSheetAt(0).getDrawingPatriarch());
+        assertNull(b.getSheetAt(1).getDrawingPatriarch());
+        assertFalse(b.getSheetAt(0).getDrawingPatriarch().containsChart());
+        
+        // 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 = writeRead(b);
+        assertEquals(2, b.getNumberOfSheets());
+        s = b.getSheetAt(1);
+        assertEquals(0, s.getFirstRowNum());
+        assertEquals(0, s.getLastRowNum());
+
+        
+        // Two charts, three sheets
+        b = new HSSFWorkbook(
+        		new FileInputStream(new File(filename,"44010-TwoCharts.xls"))
+        );
+        assertEquals(3, b.getNumberOfSheets());
+        
+        s = b.getSheetAt(1);
+        assertEquals(0, s.getFirstRowNum());
+        assertEquals(0, s.getLastRowNum());
+        s = b.getSheetAt(2);
+        assertEquals(0, s.getFirstRowNum());
+        assertEquals(0, s.getLastRowNum());
+        
+        // Has chart on 1st sheet??
+        // FIXME
+        assertNotNull(b.getSheetAt(0).getDrawingPatriarch());
+        assertNull(b.getSheetAt(1).getDrawingPatriarch());
+        assertNull(b.getSheetAt(2).getDrawingPatriarch());
+        assertFalse(b.getSheetAt(0).getDrawingPatriarch().containsChart());
+        
+        // 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 = writeRead(b);
+        assertEquals(3, b.getNumberOfSheets());
+        
+        s = b.getSheetAt(1);
+        assertEquals(0, s.getFirstRowNum());
+        assertEquals(0, s.getLastRowNum());
+        s = b.getSheetAt(2);
+        assertEquals(0, s.getFirstRowNum());
+        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())
+    	);
     }
 }

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java Fri Jan 25 07:48:14 2008
@@ -26,6 +26,8 @@
 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;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -316,7 +318,23 @@
 		 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());
+	}
         
 	 /**
 	  * Test to see if the print areas can be retrieved/created in memory

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java Fri Jan 25 07:48:14 2008
@@ -19,12 +19,11 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
 /**
  * Tests for how HSSFWorkbook behaves with XLS files
  *  with a WORKBOOK directory entry (instead of the more
@@ -34,11 +33,21 @@
 	private String dirPath;
 	private String xlsHidden = "TwoSheetsOneHidden.xls";
 	private String xlsShown  = "TwoSheetsNoneHidden.xls";
+	private HSSFWorkbook wbH;
+	private HSSFWorkbook wbU;
 
 	protected void setUp() throws Exception {
 		super.setUp();
-		
-        dirPath = System.getProperty("HSSF.testdata.path");
+
+		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);
 	}
 
 	/**
@@ -47,36 +56,27 @@
 	 *  the hidden flags are
 	 */
 	public void testTextSheets() throws Exception {
-		FileInputStream isH = new FileInputStream(dirPath + "/" + xlsHidden);
-		POIFSFileSystem fsH = new POIFSFileSystem(isH);
-		
-		FileInputStream isU = new FileInputStream(dirPath + "/" + xlsShown);
-		POIFSFileSystem fsU = new POIFSFileSystem(isU);
-
-		HSSFWorkbook wbH = new HSSFWorkbook(fsH);
-		HSSFWorkbook wbU = new HSSFWorkbook(fsU);
-		
 		// Both should have two sheets
 		assertEquals(2, wbH.sheets.size());
 		assertEquals(2, wbU.sheets.size());
-		
+
 		// All sheets should have one row
 		assertEquals(0, wbH.getSheetAt(0).getLastRowNum());
 		assertEquals(0, wbH.getSheetAt(1).getLastRowNum());
 		assertEquals(0, wbU.getSheetAt(0).getLastRowNum());
 		assertEquals(0, wbU.getSheetAt(1).getLastRowNum());
-		
+
 		// All rows should have one column
 		assertEquals(1, wbH.getSheetAt(0).getRow(0).getLastCellNum());
 		assertEquals(1, wbH.getSheetAt(1).getRow(0).getLastCellNum());
 		assertEquals(1, wbU.getSheetAt(0).getRow(0).getLastCellNum());
 		assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum());
-		
+
 		// Text should be sheet based
-		assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getStringCellValue());
-		assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getStringCellValue());
-		assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getStringCellValue());
-		assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getStringCellValue());
+		assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString());
+		assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString());
+		assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString());
+		assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString());
 	}
 
 	/**
@@ -84,7 +84,10 @@
 	 *  as expected
 	 */
 	public void testHideUnHideFlags() throws Exception {
-		// TODO
+		assertTrue(wbH.isSheetHidden(0));
+		assertFalse(wbH.isSheetHidden(1));
+		assertFalse(wbU.isSheetHidden(0));
+		assertFalse(wbU.isSheetHidden(1));
 	}
 
 	/**
@@ -92,7 +95,15 @@
 	 *  one hidden
 	 */
 	public void testHide() throws Exception {
-		// TODO
+		wbU.setSheetHidden(0, true);
+		assertTrue(wbU.isSheetHidden(0));
+		assertFalse(wbU.isSheetHidden(1));
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		wbU.write(out);
+		out.close();
+		HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		assertTrue(wb2.isSheetHidden(0));
+		assertFalse(wb2.isSheetHidden(1));
 	}
 
 	/**
@@ -100,6 +111,14 @@
 	 *  none hidden
 	 */
 	public void testUnHide() throws Exception {
-		// TODO
+		wbH.setSheetHidden(0, false);
+		assertFalse(wbH.isSheetHidden(0));
+		assertFalse(wbH.isSheetHidden(1));
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		wbH.write(out);
+		out.close();
+		HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+		assertFalse(wb2.isSheetHidden(0));
+		assertFalse(wb2.isSheetHidden(1));
 	}
 }

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java Fri Jan 25 07:48:14 2008
@@ -25,6 +25,8 @@
 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;
 
@@ -169,6 +171,114 @@
       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();
+
+        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();
+        assertEquals(comment3,"comment top row3 (index2)\n");
+        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 
+        sheet.shiftRows(1, sheet.getLastRowNum(), 1, true, true);
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        wb.write(outputStream);
+
+        // Test that comments were shifted as expected
+        assertEquals(4, sheet.getLastRowNum());
+        assertNotNull(sheet.getCellComment(0,0));
+        assertNull(sheet.getCellComment(1,0));
+        assertNull(sheet.getCellComment(2,0));
+        assertNotNull(sheet.getCellComment(3,0));
+        assertNotNull(sheet.getCellComment(4,0));
+
+        String comment1_shifted = sheet.getCellComment(0,0).getString().getString();
+        assertEquals(comment1,comment1_shifted);
+        String comment3_shifted = sheet.getCellComment(3,0).getString().getString();
+        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()) );
+        sheet = wb.getSheet("Sheet1");
+        assertEquals(4, sheet.getLastRowNum());
+
+        // Verify comments are in the position expected after the shift
+        assertNotNull(sheet.getCellComment(0,0));
+        assertNull(sheet.getCellComment(1,0));
+        assertNull(sheet.getCellComment(2,0));
+        assertNotNull(sheet.getCellComment(3,0));
+        assertNotNull(sheet.getCellComment(4,0));
+
+        comment1_shifted = sheet.getCellComment(0,0).getString().getString();
+        assertEquals(comment1,comment1_shifted);
+        comment3_shifted = sheet.getCellComment(3,0).getString().getString();
+        assertEquals(comment3,comment3_shifted);
+        comment4_shifted = sheet.getCellComment(4,0).getString().getString();
+        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();
+
+        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());
+        assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(1).getCell((short)3).getCellFormula());
+        assertEquals("cell B3 (ref)", sheet.getRow(2).getCell((short)3).getRichStringCellValue().toString());
+        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
+        assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(11).getCell((short)3).getCellFormula());
+
+        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/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java Fri Jan 25 07:48:14 2008
@@ -44,72 +44,13 @@
 	protected String cwd = System.getProperty("HSSF.testdata.path");
 	
 	 
-	 /* ArrayIndexOutOfBound in BOFRecord */  
-	 public void test28772() throws java.io.IOException {
-       String filename = System.getProperty("HSSF.testdata.path");
-       filename=filename+"/28772.xls";
-       FileInputStream in = new FileInputStream(filename);
-       HSSFWorkbook wb = new HSSFWorkbook(in);
-       assertTrue("Read book fine!" , true);
-   }
-	 
-	 /**
-	     * Bug 37684: Unhandled Continue Record Error
-	     * 
-	     * BUT NOW(Jan07): It triggers bug 41026!!
-	     * 
-	     * java.lang.ArrayIndexOutOfBoundsException: 30
-         at org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.rowHasCells(ValueRecordsAggregate.java:219)
-	     */
-	    public void test37684() throws Exception {
-	        FileInputStream in = new FileInputStream(new File(cwd, "37684.xls"));
-	        HSSFWorkbook wb = new HSSFWorkbook(in);
-	        in.close();
 
-	        HSSFSheet sheet = wb.getSheetAt( 0 );
-	        assertNotNull(sheet);
-
-	        assertTrue("No Exceptions while reading file", true);
-
-	        //serialize and read again
-	        ByteArrayOutputStream out = new ByteArrayOutputStream();
-	        wb.write(out);
-	        out.close();
-
-	        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
-	        assertTrue("No Exceptions while reading file", true);
-
-	    }
-	    
-	    /**
-	     * Bug 41139: Constructing HSSFWorkbook is failed,threw threw ArrayIndexOutOfBoundsException for creating UnknownRecord
-	     * 
-	     * BUT NOW (Jan07): It throws the following in write!!
-	     * java.lang.RuntimeException: Coding Error: This method should never be called. This ptg should be converted
-         at org.apache.poi.hssf.record.formula.AreaNPtg.writeBytes(AreaNPtg.java:54)
-         at org.apache.poi.hssf.record.formula.Ptg.serializePtgStack(Ptg.java:384)
-         at org.apache.poi.hssf.record.NameRecord.serialize(NameRecord.java:544)
-         at org.apache.poi.hssf.model.Workbook.serialize(Workbook.java:757)
-         at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:952)
-         at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:898)
-
-	     */
-	    public void test41139() throws Exception {
-	        FileInputStream in = new FileInputStream(new File(cwd, "41139.xls"));
-	        HSSFWorkbook wb = new HSSFWorkbook(in);
-	        in.close();
-
-	        assertTrue("No Exceptions while reading file", true);
-
-	        //serialize and read again
-	        ByteArrayOutputStream out = new ByteArrayOutputStream();
-	        wb.write(out);
-	        out.close();
-
-	        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
-	        assertTrue("No Exceptions while reading file", true);
-
-	    }
-
-	
+    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/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java Fri Jan 25 07:48:14 2008
@@ -21,9 +21,16 @@
 
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.*;
+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.UnionPtg;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
 
 public class TestAreaReference extends TestCase {
      public TestAreaReference(String s) {
@@ -45,6 +52,25 @@
         assertTrue("row is abs",cf.isRowAbsolute());
         assertTrue("col is abs",cf.isColAbsolute());
         assertTrue("string is $B$2",cf.toString().equals("$B$2"));
+        
+        CellReference[] refs = ar.getAllReferencedCells();
+        assertEquals(4, refs.length);
+        
+        assertEquals(0, refs[0].getRow());
+        assertEquals(0, refs[0].getCol());
+        assertNull(refs[0].getSheetName());
+        
+        assertEquals(0, refs[1].getRow());
+        assertEquals(1, refs[1].getCol());
+        assertNull(refs[1].getSheetName());
+        
+        assertEquals(1, refs[2].getRow());
+        assertEquals(0, refs[2].getCol());
+        assertNull(refs[2].getSheetName());
+        
+        assertEquals(1, refs[3].getRow());
+        assertEquals(1, refs[3].getCol());
+        assertNull(refs[3].getSheetName());
     }
     
     /**
@@ -52,16 +78,204 @@
      * Reported by Arne.Clauss@gedas.de
      */
     public void testReferenceWithSheet() {
-    	String ref = "Tabelle1!$B$5";
+    	String ref = "Tabelle1!B5";
 		AreaReference myAreaReference = new AreaReference(ref);
 		CellReference[] myCellReference = myAreaReference.getCells();
-		
+
+		assertEquals(1, myCellReference.length);
 		assertNotNull("cell reference not null : "+myCellReference[0]);
     	assertEquals("Not Column B", (short)1,myCellReference[0].getCol());
 		assertEquals("Not Row 5", 4,myCellReference[0].getRow());
+		assertEquals("Shouldn't be absolute", false, myCellReference[0].isRowAbsolute());
+		assertEquals("Shouldn't be absolute", false, myCellReference[0].isColAbsolute());
+		
+		assertEquals(1, myAreaReference.getAllReferencedCells().length);
+		
+		
+		ref = "Tabelle1!$B$5:$B$7";
+		myAreaReference = new AreaReference(ref);
+		myCellReference = myAreaReference.getCells();
+		assertEquals(2, myCellReference.length);
+		
+		assertEquals("Tabelle1", myCellReference[0].getSheetName());
+		assertEquals(4, myCellReference[0].getRow());
+		assertEquals(1, myCellReference[0].getCol());
+		assertTrue(myCellReference[0].isRowAbsolute());
+		assertTrue(myCellReference[0].isColAbsolute());
+		
+		assertEquals("Tabelle1", myCellReference[1].getSheetName());
+		assertEquals(6, myCellReference[1].getRow());
+		assertEquals(1, myCellReference[1].getCol());
+		assertTrue(myCellReference[1].isRowAbsolute());
+		assertTrue(myCellReference[1].isColAbsolute());
+		
+		// And all that make it up
+		myCellReference = myAreaReference.getAllReferencedCells();
+		assertEquals(3, myCellReference.length);
+		
+		assertEquals("Tabelle1", myCellReference[0].getSheetName());
+		assertEquals(4, myCellReference[0].getRow());
+		assertEquals(1, myCellReference[0].getCol());
+		assertTrue(myCellReference[0].isRowAbsolute());
+		assertTrue(myCellReference[0].isColAbsolute());
+		
+		assertEquals("Tabelle1", myCellReference[1].getSheetName());
+		assertEquals(5, myCellReference[1].getRow());
+		assertEquals(1, myCellReference[1].getCol());
+		assertTrue(myCellReference[1].isRowAbsolute());
+		assertTrue(myCellReference[1].isColAbsolute());
+		
+		assertEquals("Tabelle1", myCellReference[2].getSheetName());
+		assertEquals(6, myCellReference[2].getRow());
+		assertEquals(1, myCellReference[2].getCol());
+		assertTrue(myCellReference[2].isRowAbsolute());
+		assertTrue(myCellReference[2].isColAbsolute());
+    }
+
+    private static class HSSFWB extends HSSFWorkbook {
+        private HSSFWB(InputStream in) throws Exception {
+            super(in);
+        }
+        public Workbook getWorkbook() {
+            return super.getWorkbook();
+        }
+    }
+
+    public void testContiguousReferences() throws Exception {
+        String refSimple = "$C$10";
+        String ref2D = "$C$10:$D$11";
+        String refDCSimple = "$C$10,$D$12,$E$14";
+        String refDC2D = "$C$10:$C$11,$D$12,$E$14:$E$20";
+        String refDC3D = "Tabelle1!$C$10:$C$14,Tabelle1!$D$10:$D$12";
+
+        // Check that we detect as contiguous properly
+        assertTrue(AreaReference.isContiguous(refSimple));
+        assertTrue(AreaReference.isContiguous(ref2D));
+        assertFalse(AreaReference.isContiguous(refDCSimple));
+        assertFalse(AreaReference.isContiguous(refDC2D));
+        assertFalse(AreaReference.isContiguous(refDC3D));
+
+        // Check we can only create contiguous entries
+        new AreaReference(refSimple);
+        new AreaReference(ref2D);
+        try {
+            new AreaReference(refDCSimple);
+            fail();
+        } catch(IllegalArgumentException e) {}
+        try {
+            new AreaReference(refDC2D);
+            fail();
+        } catch(IllegalArgumentException e) {}
+        try {
+            new AreaReference(refDC3D);
+            fail();
+        } catch(IllegalArgumentException e) {}
+
+        // Test that we split as expected
+        AreaReference[] refs;
+
+        refs = AreaReference.generateContiguous(refSimple);
+        assertEquals(1, refs.length);
+        assertEquals(1, refs[0].getDim());
+        assertEquals("$C$10", refs[0].toString());
+
+        refs = AreaReference.generateContiguous(ref2D);
+        assertEquals(1, refs.length);
+        assertEquals(2, refs[0].getDim());
+        assertEquals("$C$10:$D$11", refs[0].toString());
+
+        refs = AreaReference.generateContiguous(refDCSimple);
+        assertEquals(3, refs.length);
+        assertEquals(1, refs[0].getDim());
+        assertEquals(1, refs[1].getDim());
+        assertEquals(1, refs[2].getDim());
+        assertEquals("$C$10", refs[0].toString());
+        assertEquals("$D$12", refs[1].toString());
+        assertEquals("$E$14", refs[2].toString());
+
+        refs = AreaReference.generateContiguous(refDC2D);
+        assertEquals(3, refs.length);
+        assertEquals(2, refs[0].getDim());
+        assertEquals(1, refs[1].getDim());
+        assertEquals(2, refs[2].getDim());
+        assertEquals("$C$10:$C$11", refs[0].toString());
+        assertEquals("$D$12", refs[1].toString());
+        assertEquals("$E$14:$E$20", refs[2].toString());
+
+        refs = AreaReference.generateContiguous(refDC3D);
+        assertEquals(2, refs.length);
+        assertEquals(2, refs[0].getDim());
+        assertEquals(2, refs[1].getDim());
+        assertEquals("$C$10:$C$14", refs[0].toString());
+        assertEquals("$D$10:$D$12", refs[1].toString());
+        assertEquals("Tabelle1", refs[0].getCells()[0].getSheetName());
+        assertEquals("Tabelle1", refs[0].getCells()[1].getSheetName());
+        assertEquals("Tabelle1", refs[1].getCells()[0].getSheetName());
+        assertEquals("Tabelle1", refs[1].getCells()[1].getSheetName());
+    }
+
+    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 );
+        Workbook workbook = wb.getWorkbook();
+        fin.close();
+
+        assertEquals(1, wb.getNumberOfNames());
+        String sheetName = "Tabelle1";
+        String rawRefA = "$C$10:$C$14";
+        String rawRefB = "$C$16:$C$18";
+        String refA = sheetName + "!" + rawRefA;
+        String refB = sheetName + "!" + rawRefB;
+        String ref = refA + "," + refB;
+
+        // Check the low level record
+        NameRecord nr = workbook.getNameRecord(0);
+        assertNotNull(nr);
+        assertEquals("test", nr.getNameText());
+
+        List def =nr.getNameDefinition();
+        assertEquals(4, def.size());
+
+        MemFuncPtg ptgA = (MemFuncPtg)def.get(0);
+        Area3DPtg ptgB = (Area3DPtg)def.get(1);
+        Area3DPtg ptgC = (Area3DPtg)def.get(2);
+        UnionPtg ptgD = (UnionPtg)def.get(3);
+        assertEquals("", ptgA.toFormulaString(workbook));
+        assertEquals(refA, ptgB.toFormulaString(workbook));
+        assertEquals(refB, ptgC.toFormulaString(workbook));
+        assertEquals(",", ptgD.toFormulaString(workbook));
+
+        assertEquals(ref, nr.getAreaReference(workbook));
+
+        // Check the high level definition
+        int idx = wb.getNameIndex("test");
+        assertEquals(0, idx);
+        HSSFName aNamedCell = wb.getNameAt(idx);
+
+        // Should have 2 references
+        assertEquals(ref, aNamedCell.getReference());
+
+        // Check the parsing of the reference into cells
+        assertFalse(AreaReference.isContiguous(aNamedCell.getReference()));
+        AreaReference[] arefs = AreaReference.generateContiguous(aNamedCell.getReference());
+        assertEquals(2, arefs.length);
+        assertEquals(rawRefA, arefs[0].toString());
+        assertEquals(rawRefB, arefs[1].toString());
+
+        for(int i=0; i<arefs.length; i++) {
+            CellReference[] crefs = arefs[i].getCells();
+            for (int j=0; j<crefs.length; j++) {
+                // Check it turns into real stuff
+                HSSFSheet s = wb.getSheet(crefs[j].getSheetName());
+                HSSFRow r = s.getRow(crefs[j].getRow());
+                HSSFCell c = r.getCell(crefs[j].getCol());
+            }
+        }
     }
     
-	public static void main(java.lang.String[] args) {        
+    public static void main(java.lang.String[] args) {
 		junit.textui.TestRunner.run(TestAreaReference.class);
 	}
         

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java Fri Jan 25 07:48:14 2008
@@ -47,4 +47,26 @@
 			// Good
 		}
 	}
+	
+	public void testDetectAsPOIFS() throws IOException {
+		InputStream in;
+		
+		// ooxml file isn't
+		in = new PushbackInputStream(
+				new FileInputStream(dirname + "/SampleSS.xlsx"), 10
+		);
+		assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
+		
+		// xls file is
+		in = new PushbackInputStream(
+				new FileInputStream(dirname + "/SampleSS.xls"), 10
+		);
+		assertTrue(POIFSFileSystem.hasPOIFSHeader(in));
+		
+		// text file isn't
+		in = new PushbackInputStream(
+				new FileInputStream(dirname + "/SampleSS.txt"), 10
+		);
+		assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
+	}
 }

Modified: poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java?rev=615249&r1=615248&r2=615249&view=diff
==============================================================================
--- poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (original)
+++ poi/tags/REL_3_0_2_BETA3/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java Fri Jan 25 07:48:14 2008
@@ -20,6 +20,7 @@
 package org.apache.poi.poifs.storage;
 
 import java.io.*;
+import java.util.Random;
 
 import junit.framework.*;
 
@@ -123,6 +124,118 @@
                 // as expected
             }
         }
+    }
+    
+    /**
+     * Tests that when using a slow input stream, which
+     *  won't return a full block at a time, we don't
+     *  incorrectly think that there's not enough data
+     */
+    public void testSlowInputStream() throws Exception {
+        for (int k = 1; k < 512; k++) {
+            byte[] data = new byte[ 512 ];
+            for (int j = 0; j < data.length; j++) {
+                data[j] = (byte) j;
+            }
+            
+            // Shouldn't complain, as there is enough data,
+            //  even if it dribbles through
+            RawDataBlock block = 
+            	new RawDataBlock(new SlowInputStream(data, k));
+            assertFalse(block.eof());
+        }
+        
+        // But if there wasn't enough data available, will
+        //  complain
+        for (int k = 1; k < 512; k++) {
+            byte[] data = new byte[ 511 ];
+            for (int j = 0; j < data.length; j++) {
+                data[j] = (byte) j;
+            }
+            
+            // Shouldn't complain, as there is enough data
+            try {
+	            RawDataBlock block = 
+	            	new RawDataBlock(new SlowInputStream(data, k));
+	            fail();
+            } catch(IOException e) {
+            	// as expected
+            }
+        }
+    }
+    
+    /**
+     * An input stream which will return a maximum of
+     *  a given number of bytes to read, and often claims
+     *  not to have any data
+     */
+    public static class SlowInputStream extends InputStream {
+    	private Random rnd = new Random();
+    	private byte[] data;
+    	private int chunkSize;
+    	private int pos = 0;
+    	
+    	public SlowInputStream(byte[] data, int chunkSize) {
+    		this.chunkSize = chunkSize;
+    		this.data = data;
+    	}
+    	
+    	/**
+    	 * 75% of the time, claim there's no data available
+    	 */
+    	private boolean claimNoData() {
+    		if(rnd.nextFloat() < 0.25f) {
+    			return false;
+    		}
+    		return true;
+    	}
+    	
+		public int read() throws IOException {
+			if(pos >= data.length) {
+				return -1;
+			}
+			int ret = data[pos];
+			pos++;
+			
+			if(ret < 0) ret += 256;
+			return ret;
+		}
+
+		/**
+		 * Reads the requested number of bytes, or the chunk
+		 *  size, whichever is lower.
+		 * Quite often will simply claim to have no data
+		 */
+		public int read(byte[] b, int off, int len) throws IOException {
+			// Keep the length within the chunk size
+			if(len > chunkSize) {
+				len = chunkSize;
+			}
+			// Don't read off the end of the data
+			if(pos + len > data.length) {
+				len = data.length - pos;
+				
+				// Spot when we're out of data
+				if(len == 0) {
+					return -1;
+				}
+			}
+			
+			// 75% of the time, claim there's no data
+			if(claimNoData()) {
+				return 0;
+			}
+			
+			// Copy, and return what we read
+			System.arraycopy(data, pos, b, off, len);
+			pos += len;
+			return len;
+		}
+
+		public int read(byte[] b) throws IOException {
+			return read(b, 0, b.length);
+		}
+		
     }
 
     /**



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