You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/05/16 19:08:42 UTC

svn commit: r657135 [3/3] - in /poi/branches/ooxml: ./ src/documentation/ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ src/java/org/apache/poi/...

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheetAdditional.java Fri May 16 10:08:40 2008
@@ -19,125 +19,18 @@
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.ColumnInfoRecord;
-import org.apache.poi.hssf.record.MergeCellsRecord;
-import org.apache.poi.hssf.record.PageBreakRecord;
-import org.apache.poi.hssf.record.RowRecord;
-import org.apache.poi.hssf.record.StringRecord;
 
 /**
  * @author Tony Poppleton
  */
-public class TestSheetAdditional extends TestCase
-{
-	/**
-	 * Constructor for SheetTest.
-	 * @param arg0
-	 */
-	public TestSheetAdditional(String arg0)
-	{
-		super(arg0);
-	}
+public final class TestSheetAdditional extends TestCase {
 	
-	public void testAddMergedRegion()
-	{
-		Sheet sheet = Sheet.createSheet();
-		int regionsToAdd = 4096;
-		int startRecords = sheet.getRecords().size();
-		
-		//simple test that adds a load of regions
-		for (int n = 0; n < regionsToAdd; n++)
-		{
-			int index = sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
-			assertTrue("Merged region index expected to be " + n + " got " + index, index == n);
-		}
-		
-		//test all the regions were indeed added 
-		assertTrue(sheet.getNumMergedRegions() == regionsToAdd);
-		
-		//test that the regions were spread out over the appropriate number of records
-		int recordsAdded    = sheet.getRecords().size() - startRecords;
-		int recordsExpected = regionsToAdd/1027;
-		if ((regionsToAdd % 1027) != 0)
-			recordsExpected++;
-		assertTrue("The " + regionsToAdd + " merged regions should have been spread out over " + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
-		
-		// Check we can't add one with invalud date
-		try {
-			sheet.addMergedRegion(10, (short)10, 9, (short)12);
-			fail();
-		} catch(IllegalArgumentException e) {}
-		try {
-			sheet.addMergedRegion(10, (short)10, 12, (short)9);
-			fail();
-		} catch(IllegalArgumentException e) {}
-	}
-
-	public void testRemoveMergedRegion()
-	{
-		Sheet sheet = Sheet.createSheet();
-		int regionsToAdd = 4096;
-		
-		for (int n = 0; n < regionsToAdd; n++)
-			sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
-			
-		int records = sheet.getRecords().size();
-		
-		//remove a third from the beginning
-		for (int n = 0; n < regionsToAdd/3; n++)
-		{
-			sheet.removeMergedRegion(0); 
-			//assert they have been deleted
-			assertTrue("Num of regions should be " + (regionsToAdd - n - 1) + " not " + sheet.getNumMergedRegions(), sheet.getNumMergedRegions() == regionsToAdd - n - 1);
-		}
-		
-		//assert any record removing was done
-		int recordsRemoved = (regionsToAdd/3)/1027; //doesn't work for particular values of regionsToAdd
-		assertTrue("Expected " + recordsRemoved + " record to be removed from the starting " + records + ".  Currently there are " + sheet.getRecords().size() + " records", records - sheet.getRecords().size() == recordsRemoved);
-	}
-
-	/**
-	 * Bug: 22922 (Reported by Xuemin Guan)
-	 * <p>
-	 * Remove mergedregion fails when a sheet loses records after an initial CreateSheet
-	 * fills up the records.
-	 *
-	 */
-	public void testMovingMergedRegion() {
-		List records = new ArrayList();
-		
-		MergeCellsRecord merged = new MergeCellsRecord();
-		merged.addArea(0, (short)0, 1, (short)2);
-		records.add(new RowRecord());
-		records.add(new RowRecord());
-		records.add(new RowRecord());
-		records.add(merged);
-		
-		Sheet sheet = Sheet.createSheet(records, 0);
-		sheet.records.remove(0);
-		
-		//stub object to throw off list INDEX operations
-		sheet.removeMergedRegion(0);
-		assertEquals("Should be no more merged regions", 0, sheet.getNumMergedRegions());
-	}
-
-	public void testGetMergedRegionAt()
-	{
-		//TODO
-	}
-
-	public void testGetNumMergedRegions()
-	{
-		//TODO
-	}
-
-	public void DISBALEDtestGetCellWidth() throws Exception
-	{
+	public void testGetCellWidth() {
 		Sheet sheet = Sheet.createSheet();
 		ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
 
@@ -146,14 +39,8 @@
 		nci.setLastColumn((short)10);
 		nci.setColumnWidth((short)100);
 		
-		Field f = null;
-		f = Sheet.class.getDeclaredField("columnSizes");
-		f.setAccessible(true);
-		List columnSizes = new ArrayList();
-		f.set(sheet,columnSizes);
-		columnSizes.add(nci);
-		sheet.records.add(1 + sheet.dimsloc, nci);
-		sheet.dimsloc++;
+		
+		sheet.columns.insertColumn(nci);
 
 		assertEquals((short)100,sheet.getColumnWidth((short)5));
 		assertEquals((short)100,sheet.getColumnWidth((short)6));
@@ -172,151 +59,6 @@
 		assertEquals((short)100,sheet.getColumnWidth((short)10));
 	}
 
-	/**
-	 * Makes sure all rows registered for this sheet are aggregated, they were being skipped
-	 *
-	 */
-	public void testRowAggregation() {
-		List records = new ArrayList();
-		RowRecord row = new RowRecord();
-		row.setRowNumber(0);		
-		records.add(row);
-		
-		row = new RowRecord();
-		row.setRowNumber(1);
-		records.add(row);
-
-		records.add(new StringRecord());
-		
-		row = new RowRecord();
-		row.setRowNumber(2);
-		records.add(row);
-		
-		
-		Sheet sheet = Sheet.createSheet(records, 0);
-		assertNotNull("Row [2] was skipped", sheet.getRow(2));
-		
-	}
-	
-	/**
-	 * Make sure page break functionality works (in memory)
-	 *
-	 */
-	public void testRowPageBreaks(){
-		short colFrom = 0;
-		short colTo = 255;
-		
-		Sheet sheet = Sheet.createSheet();
-		sheet.setRowBreak(0, colFrom, colTo);
-		
-		assertTrue("no row break at 0", sheet.isRowBroken(0));
-		assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
-		
-		sheet.setRowBreak(0, colFrom, colTo);		
-		sheet.setRowBreak(0, colFrom, colTo);		
-
-		assertTrue("no row break at 0", sheet.isRowBroken(0));
-		assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
-		
-		sheet.setRowBreak(10, colFrom, colTo);
-		sheet.setRowBreak(11, colFrom, colTo);
-
-		assertTrue("no row break at 10", sheet.isRowBroken(10));
-		assertTrue("no row break at 11", sheet.isRowBroken(11));
-		assertEquals("3 row break available", 3, sheet.getNumRowBreaks());
-		
-		
-		boolean is10 = false;
-		boolean is0 = false;
-		boolean is11 = false;
-		
-		Iterator iterator = sheet.getRowBreaks();
-		while (iterator.hasNext()) {
-			PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-			int main = (int)breakItem.main;
-			if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
-			if (main == 0) 	is0 = true;
-			if (main == 10) is10= true;
-			if (main == 11) is11 = true;
-		}
-		
-		assertTrue("one of the breaks didnt make it", is0 && is10 && is11); 
-		
-		sheet.removeRowBreak(11);
-		assertFalse("row should be removed", sheet.isRowBroken(11));
-		
-		sheet.removeRowBreak(0);
-		assertFalse("row should be removed", sheet.isRowBroken(0));
-		
-		sheet.removeRowBreak(10);
-		assertFalse("row should be removed", sheet.isRowBroken(10));
-		
-		assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
-		
-		
-	}
-	
-	/**
-	 * Make sure column pag breaks works properly (in-memory)
-	 *
-	 */
-	public void testColPageBreaks(){
-		short rowFrom = 0;
-		short rowTo = (short)65535;
-		
-		Sheet sheet = Sheet.createSheet();
-		sheet.setColumnBreak((short)0, rowFrom, rowTo); 
-		
-		assertTrue("no col break at 0", sheet.isColumnBroken((short)0));
-		assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());		
-		
-		sheet.setColumnBreak((short)0, rowFrom, rowTo);
-		
-		assertTrue("no col break at 0", sheet.isColumnBroken((short)0));
-		assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());		
-		
-		sheet.setColumnBreak((short)1, rowFrom, rowTo);
-		sheet.setColumnBreak((short)10, rowFrom, rowTo);
-		sheet.setColumnBreak((short)15, rowFrom, rowTo);
-		
-		assertTrue("no col break at 1", sheet.isColumnBroken((short)1));
-		assertTrue("no col break at 10", sheet.isColumnBroken((short)10));
-		assertTrue("no col break at 15", sheet.isColumnBroken((short)15));
-		assertEquals("4 col break available", 4, sheet.getNumColumnBreaks());		
-
-		boolean is10 = false;
-		boolean is0 = false;
-		boolean is1 = false;
-		boolean is15 = false;
-		
-		Iterator iterator = sheet.getColumnBreaks();
-		while (iterator.hasNext()) {
-			PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-			int main = (int)breakItem.main;
-			if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
-			if (main == 0) 	is0 = true;
-			if (main == 1) 	is1 = true;
-			if (main == 10) is10= true;
-			if (main == 15) is15 = true;
-		}
-		
-		assertTrue("one of the breaks didnt make it", is0 && is1 && is10 && is15); 
-		
-		sheet.removeColumnBreak((short)15);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)15));
-
-		sheet.removeColumnBreak((short)0);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)0));
-		
-		sheet.removeColumnBreak((short)1);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)1));
-		
-		sheet.removeColumnBreak((short)10);
-		assertFalse("column break should not be there", sheet.isColumnBroken((short)10));
-		
-		assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
-	}
-
 }
 
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestRowRecordsAggregate.java Fri May 16 10:08:40 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,34 +14,28 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
+
 package org.apache.poi.hssf.record.aggregates;
 
-import org.apache.poi.hssf.record.*;
+import junit.framework.TestCase;
 
-public class TestRowRecordsAggregate extends junit.framework.TestCase {
-    public TestRowRecordsAggregate(String name) {
-        super (name);
-    }
+import org.apache.poi.hssf.record.RowRecord;
+
+/**
+ * 
+ */
+public final class TestRowRecordsAggregate extends TestCase {
     
     public void testRowGet() {
         RowRecordsAggregate rra = new RowRecordsAggregate();
-        RowRecord rr = new RowRecord();
-        rr.setRowNumber(( short ) 4);
+        RowRecord rr = new RowRecord(4);
         rra.insertRow(rr);
-        RowRecord rr2 = new RowRecord(); rr2.setRowNumber((short) 1);
-        rra.insertRow(rr2);
+        rra.insertRow(new RowRecord(1));
         
         RowRecord rr1 = rra.getRow(4);
         
-        assertTrue("Row Record should not be null", rr1!=null);
-        assertTrue("Row number is 1",rr1.getRowNumber() == 4);
+        assertNotNull(rr1);
+        assertEquals("Row number is 1", 4, rr1.getRowNumber());
         assertTrue("Row record retrieved is identical ", rr1 == rr);
     }
-    
-     public static void main(String [] args) {
-        System.out
-        .println("Testing org.apache.poi.hssf.record.aggregates.RowRecordAggregate");
-        junit.textui.TestRunner.run(TestRowRecordsAggregate.class);
-    }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java Fri May 16 10:08:40 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
@@ -26,45 +25,31 @@
  *
  * @author Danny Mui (dmui at apache dot org)
  */
+public final class TestFuncPtg extends TestCase {
 
-public class TestFuncPtg extends TestCase
-{
-
-    public TestFuncPtg( String name )
-    {
-        super( name );
-    }
-
-
-    public static void main( java.lang.String[] args )
-    {
-        junit.textui.TestRunner.run( TestFuncPtg.class );
-    }
-
-    /**
-     * Make sure the left overs are re-serialized on excel file reads to avoid
-     * the "Warning: Data may have been lost" prompt in excel.
-     * <p/>
-     * This ptg represents a LEN function extracted from excel
-     */
-
-    public void testLeftOvers()
-    {
-        byte[] fakeData = new byte[4];
-
-        //fakeData[0] = (byte) 0x41;
-        fakeData[0] = (byte) 0x20;  //function index
-        fakeData[1] = (byte) 0;
-        fakeData[2] = (byte) 8;
+    public void testRead() {
+    	// This ptg represents a LEN function extracted from excel
+        byte[] fakeData = {
+            0x20,  //function index
+            0,
+        };
 
         FuncPtg ptg = new FuncPtg( new TestcaseRecordInputStream((short)0, (short)fakeData.length, fakeData) );
-        assertEquals( "Len formula index is not 32(20H)", (int) 0x20, ptg.getFunctionIndex() );
+        assertEquals( "Len formula index is not 32(20H)", 0x20, ptg.getFunctionIndex() );
         assertEquals( "Number of operands in the len formula", 1, ptg.getNumberOfOperands() );
         assertEquals( "Function Name", "LEN", ptg.getName() );
         assertEquals( "Ptg Size", 3, ptg.getSize() );
-        //assertEquals("first leftover byte is not 0", (byte)0, ptg.leftOvers[0]);
-        //assertEquals("second leftover byte is not 8", (byte)8, ptg.leftOvers[1]);
-
+    }
+    
+    public void testClone() {
+        FuncPtg funcPtg = new FuncPtg(27); // ROUND() - takes 2 args
+
+        FuncPtg clone = (FuncPtg) funcPtg.clone();
+        if (clone.getNumberOfOperands() == 0) {
+            fail("clone() did copy field numberOfOperands");
+        }
+        assertEquals(2, clone.getNumberOfOperands());
+        assertEquals("ROUND", clone.getName());
     }
 }
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java Fri May 16 10:08:40 2008
@@ -28,7 +28,8 @@
 public class AllFormulaEvalTests {
 	
 	public static Test suite() {
-		TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.record.formula.eval");
+		TestSuite result = new TestSuite(AllFormulaEvalTests.class.getName());
+		result.addTestSuite(TestAreaEval.class);
 		result.addTestSuite(TestCircularReferences.class);
 		result.addTestSuite(TestExternalFunction.class);
 		result.addTestSuite(TestFormulaBugs.class);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java Fri May 16 10:08:40 2008
@@ -61,7 +61,32 @@
 
 	private static final String SOURCE_DOC_FILE_NAME = "excelfileformat.odt";
 
+	/**
+	 * For simplicity, the output file is strictly simple ASCII.
+	 * This method detects any unexpected characters. 
+	 */
+	/* package */ static boolean isSimpleAscii(char c) {
+		
+		if (c>=0x21 && c<=0x7E) {
+			// everything from '!' to '~' (includes letters, digits, punctuation
+			return true;
+		}
+		// some specific whitespace chars below 0x21:
+		switch(c) {
+			case ' ':
+			case '\t':
+			case '\r':
+			case '\n':
+				return true;
+		}
+		return false;
+	}
+	
+	
 	private static final class FunctionData {
+		// special characters from the ooo document
+		private static final int CHAR_ELLIPSIS_8230 = 8230;
+		private static final int CHAR_NDASH_8211 = 8211;
 
 		private final int _index;
 		private final boolean _hasFootnote;
@@ -79,10 +104,30 @@
 			_name = funcName;
 			_minParams = minParams;
 			_maxParams = maxParams;
-			_returnClass = returnClass;
-			_paramClasses = paramClasses;
+			_returnClass = convertSpecialChars(returnClass);
+			_paramClasses = convertSpecialChars(paramClasses);
 			_isVolatile = isVolatile;
 		}
+		private static String convertSpecialChars(String ss) {
+			StringBuffer sb = new StringBuffer(ss.length() + 4);
+			for(int i=0; i<ss.length(); i++) {
+				char c = ss.charAt(i);
+				if (isSimpleAscii(c)) {
+					sb.append(c);
+					continue;
+				}
+				switch (c) {
+					case CHAR_NDASH_8211:
+						sb.append('-');
+						continue;
+					case CHAR_ELLIPSIS_8230:
+						sb.append("...");
+						continue;
+				}
+				throw new RuntimeException("bad char (" + ((int)c) + ") in string '" + ss + "'");
+			}
+			return sb.toString();
+		}
 		public int getIndex() {
 			return _index;
 		}
@@ -382,6 +427,33 @@
 			throw new RuntimeException(e);
 		}
 	}
+	/**
+	 * To be sure that no tricky unicode chars make it through to the output file.
+	 */
+	private static final class SimpleAsciiOutputStream extends OutputStream {
+
+		private final OutputStream _os;
+
+		public SimpleAsciiOutputStream(OutputStream os) {
+			_os = os;
+		}
+		public void write(int b) throws IOException {
+			checkByte(b);
+			_os.write(b);
+		}
+		private static void checkByte(int b) {
+			if (!isSimpleAscii((char)b)) {
+				throw new RuntimeException("Encountered char (" + b + ") which was not simple ascii as expected");
+			}
+		}
+		public void write(byte[] b, int off, int len) throws IOException {
+			for (int i = 0; i < len; i++) {
+				checkByte(b[i + off]);
+				
+			}
+			_os.write(b, off, len);
+		}
+	}
 
 	private static void processFile(File effDocFile, File outFile) {
 		OutputStream os;
@@ -390,10 +462,13 @@
 		} catch (FileNotFoundException e) {
 			throw new RuntimeException(e);
 		}
-		PrintStream ps = null;
+		os = new SimpleAsciiOutputStream(os);
+		PrintStream ps;
 		try {
-			ps = new PrintStream(os,true, "UTF-8");
-		} catch(UnsupportedEncodingException e) {}
+			ps = new PrintStream(os, true, "UTF-8");
+		} catch(UnsupportedEncodingException e) {
+			throw new RuntimeException(e);
+		}
 		
 		outputLicenseHeader(ps);
 		Class genClass = ExcelFileFormatDocFunctionExtractor.class;

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java Fri May 16 10:08:40 2008
@@ -67,7 +67,7 @@
 		args = new Eval[] {
 			EvalFactory.createAreaEval("D1:F5", 3, 5),	// 15
 			EvalFactory.createRefEval("A1"),	
-			EvalFactory.createAreaEval("A1:F6", 7, 6),	// 42
+			EvalFactory.createAreaEval("A1:G6", 7, 6),	// 42
 			new NumberEval(0),
 		};
 		confirmCountA(59, args);
@@ -87,7 +87,7 @@
 				BoolEval.TRUE,
 				BlankEval.INSTANCE,
 		};
-		range = createAreaEval("A1:B2", values);
+		range = createAreaEval("A1:B3", values);
 		confirmCountIf(2, range, BoolEval.TRUE);
 		
 		// when criteria is numeric
@@ -98,9 +98,8 @@
 				new NumberEval(2),	
 				new NumberEval(2),	
 				BoolEval.TRUE,
-				BlankEval.INSTANCE,
 		};
-		range = createAreaEval("A1:B2", values);
+		range = createAreaEval("A1:B3", values);
 		confirmCountIf(3, range, new NumberEval(2));
 		// note - same results when criteria is a string that parses as the number with the same value
 		confirmCountIf(3, range, new StringEval("2.00"));

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java Fri May 16 10:08:40 2008
@@ -14,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record.formula.functions;
 
@@ -33,10 +32,6 @@
  */
 public final class TestIndex extends TestCase {
 
-	public TestIndex(String testName) {
-		super(testName);
-	}
-	
 	private static final double[] TEST_VALUES0 = {
 			1, 2,
 			3, 4,
@@ -44,7 +39,6 @@
 			7, 8,
 			9, 10,
 			11, 12,
-			13, // excess array element. TODO - Area2DEval currently has no validation to ensure correct size of values array
 	};
 	
 	/**

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java Fri May 16 10:08:40 2008
@@ -38,10 +38,12 @@
 		result.addTestSuite(TestEscherGraphics2d.class);
 		result.addTestSuite(TestFontDetails.class);
 		result.addTestSuite(TestFormulas.class);
+		result.addTestSuite(TestFormulaEvaluatorBugs.class);
+		result.addTestSuite(TestFormulaEvaluatorDocs.class);
 		result.addTestSuite(TestHSSFCell.class);
 		result.addTestSuite(TestHSSFClientAnchor.class);
-		result.addTestSuite(TestHSSFConditionalFormatting.class);
 		result.addTestSuite(TestHSSFComment.class);
+		result.addTestSuite(TestHSSFConditionalFormatting.class);
 		result.addTestSuite(TestHSSFDateUtil.class);
 		result.addTestSuite(TestHSSFHeaderFooter.class);
 		result.addTestSuite(TestHSSFHyperlink.class);
@@ -54,17 +56,19 @@
 		result.addTestSuite(TestHSSFSheet.class);
 		result.addTestSuite(TestHSSFSheetOrder.class);
 		result.addTestSuite(TestHSSFSheetSetOrder.class);
+		result.addTestSuite(TestHSSFTextbox.class);
 		result.addTestSuite(TestHSSFWorkbook.class);
 		result.addTestSuite(TestNamedRange.class);
 		result.addTestSuite(TestOLE2Embeding.class);
+		result.addTestSuite(TestPOIFSProperties.class);
 		result.addTestSuite(TestReadWriteChart.class);
 		result.addTestSuite(TestSanityChecker.class);
 		result.addTestSuite(TestSheetHiding.class);
 		result.addTestSuite(TestSheetShiftRows.class);
 		if (false) { // deliberately avoiding this one
-            result.addTestSuite(TestUnfixedBugs.class);
-        }
-        result.addTestSuite(TestUnicodeWorkbook.class);
+			result.addTestSuite(TestUnfixedBugs.class);
+		}
+		result.addTestSuite(TestUnicodeWorkbook.class);
 		result.addTestSuite(TestUppercaseWorkbook.class);
 		result.addTestSuite(TestWorkbook.class);		
 		

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java Fri May 16 10:08:40 2008
@@ -22,12 +22,14 @@
 import java.util.Iterator;
 import java.util.List;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.formula.AreaPtg;
 import org.apache.poi.hssf.record.formula.FuncVarPtg;
+
 /**
  * 
  */
@@ -51,42 +53,41 @@
 	 */
 	public void test44636() throws Exception {
 		// Open the existing file, tweak one value and
-		//  re-calculate
+		// re-calculate
 
 		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("44636.xls");
-		HSSFSheet sheet = wb.getSheetAt (0);
-		HSSFRow row = sheet.getRow (0);
+		HSSFSheet sheet = wb.getSheetAt(0);
+		HSSFRow row = sheet.getRow(0);
 
-		row.getCell((short)0).setCellValue(4.2);
-		row.getCell((short)2).setCellValue(25);
+		row.getCell((short) 0).setCellValue(4.2);
+		row.getCell((short) 2).setCellValue(25);
 
 		HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
-		assertEquals(4.2*25, row.getCell((short)3).getNumericCellValue(), 0.0001);
+		assertEquals(4.2 * 25, row.getCell((short) 3).getNumericCellValue(), 0.0001);
 
 		// Save
-		File existing = new File(tmpDirName,"44636-existing.xls");
+		File existing = new File(tmpDirName, "44636-existing.xls");
 		FileOutputStream out = new FileOutputStream(existing);
 		wb.write(out);
 		out.close();
 		System.err.println("Existing file for bug #44636 written to " + existing.toString());
 
-
 		// Now, do a new file from scratch
 		wb = new HSSFWorkbook();
 		sheet = wb.createSheet();
 
 		row = sheet.createRow(0);
-		row.createCell((short)0).setCellValue(1.2);
-		row.createCell((short)1).setCellValue(4.2);
+		row.createCell((short) 0).setCellValue(1.2);
+		row.createCell((short) 1).setCellValue(4.2);
 
 		row = sheet.createRow(1);
-		row.createCell((short)0).setCellFormula("SUM(A1:B1)");
+		row.createCell((short) 0).setCellFormula("SUM(A1:B1)");
 
 		HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
-		assertEquals(5.4, row.getCell((short)0).getNumericCellValue(), 0.0001);
+		assertEquals(5.4, row.getCell((short) 0).getNumericCellValue(), 0.0001);
 
 		// Save
-		File scratch = new File(tmpDirName,"44636-scratch.xls");
+		File scratch = new File(tmpDirName, "44636-scratch.xls");
 		out = new FileOutputStream(scratch);
 		wb.write(out);
 		out.close();
@@ -105,62 +106,62 @@
 		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("44297.xls");
 
 		HSSFRow row;
-		HSSFCell  cell;
+		HSSFCell cell;
 
-		HSSFSheet sheet   = wb.getSheetAt(0);
+		HSSFSheet sheet = wb.getSheetAt(0);
 
 		HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(sheet, wb);
 
 		row = sheet.getRow(0);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("31+46", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(77, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(1);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("30+53", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(83, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(2);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("SUM(A1:A2)", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(160, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(4);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("32767+32768", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(65535, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(7);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("32744+42333", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(75077, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(8);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("327680.0/32768", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(10, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(9);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("32767+32769", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(65536, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(10);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("35000+36000", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(71000, eva.evaluate(cell).getNumberValue(), 0);
 
 		row = sheet.getRow(11);
-		cell = row.getCell((short)0);
+		cell = row.getCell((short) 0);
 		assertEquals("-1000000.0-3000000.0", cell.getCellFormula());
 		eva.setCurrentRow(row);
 		assertEquals(-4000000, eva.evaluate(cell).getNumberValue(), 0);
@@ -176,30 +177,29 @@
 
 		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SingleLetterRanges.xls");
 
-		HSSFSheet sheet   = wb.getSheetAt(0);
+		HSSFSheet sheet = wb.getSheetAt(0);
 
 		HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(sheet, wb);
 
-		// =index(C:C,2,1)   -> 2
+		// =index(C:C,2,1) -> 2
 		HSSFRow rowIDX = sheet.getRow(3);
-		// =sum(C:C)		 -> 6
+		// =sum(C:C) -> 6
 		HSSFRow rowSUM = sheet.getRow(4);
-		// =sum(C:D)		 -> 66
+		// =sum(C:D) -> 66
 		HSSFRow rowSUM2D = sheet.getRow(5);
 
 		// Test the sum
-		HSSFCell cellSUM = rowSUM.getCell((short)0);
+		HSSFCell cellSUM = rowSUM.getCell((short) 0);
 
-		FormulaRecordAggregate frec = 
-			(FormulaRecordAggregate)cellSUM.getCellValueRecord();
+		FormulaRecordAggregate frec = (FormulaRecordAggregate) cellSUM.getCellValueRecord();
 		List ops = frec.getFormulaRecord().getParsedExpression();
 		assertEquals(2, ops.size());
 		assertEquals(AreaPtg.class, ops.get(0).getClass());
 		assertEquals(FuncVarPtg.class, ops.get(1).getClass());
 
-		// Actually stored as C1 to C65536 
-		//  (last row is -1 === 65535)
-		AreaPtg ptg = (AreaPtg)ops.get(0);
+		// Actually stored as C1 to C65536
+		// (last row is -1 === 65535)
+		AreaPtg ptg = (AreaPtg) ops.get(0);
 		assertEquals(2, ptg.getFirstColumn());
 		assertEquals(2, ptg.getLastColumn());
 		assertEquals(0, ptg.getFirstRow());
@@ -207,26 +207,25 @@
 		assertEquals("C:C", ptg.toFormulaString(wb));
 
 		// Will show as C:C, but won't know how many
-		//  rows it covers as we don't have the sheet
-		//  to hand when turning the Ptgs into a string
+		// rows it covers as we don't have the sheet
+		// to hand when turning the Ptgs into a string
 		assertEquals("SUM(C:C)", cellSUM.getCellFormula());
 		eva.setCurrentRow(rowSUM);
 
 		// But the evaluator knows the sheet, so it
-		//  can do it properly
+		// can do it properly
 		assertEquals(6, eva.evaluate(cellSUM).getNumberValue(), 0);
 
-
 		// Test the index
 		// Again, the formula string will be right but
-		//  lacking row count, evaluated will be right
-		HSSFCell cellIDX = rowIDX.getCell((short)0);
+		// lacking row count, evaluated will be right
+		HSSFCell cellIDX = rowIDX.getCell((short) 0);
 		assertEquals("INDEX(C:C,2,1)", cellIDX.getCellFormula());
 		eva.setCurrentRow(rowIDX);
 		assertEquals(2, eva.evaluate(cellIDX).getNumberValue(), 0);
 
 		// Across two colums
-		HSSFCell cellSUM2D = rowSUM2D.getCell((short)0);
+		HSSFCell cellSUM2D = rowSUM2D.getCell((short) 0);
 		assertEquals("SUM(C:D)", cellSUM2D.getCellFormula());
 		eva.setCurrentRow(rowSUM2D);
 		assertEquals(66, eva.evaluate(cellSUM2D).getNumberValue(), 0);
@@ -240,7 +239,7 @@
 		HSSFSheet sheet = wb.createSheet();
 		wb.setSheetName(0, "Sheet1");
 		HSSFRow row = sheet.createRow(0);
-		HSSFCell cell = row.createCell((short)0);
+		HSSFCell cell = row.createCell((short) 0);
 
 		cell.setCellFormula("1=1");
 
@@ -253,29 +252,46 @@
 		}
 		assertEquals(true, cell.getBooleanCellValue());
 	}
-	
+
 	public void testClassCast_bug44861() throws Exception {
-		HSSFWorkbook wb = HSSFTestDataSamples.
-			openSampleWorkbook("44861.xls");
-		
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("44861.xls");
+
 		// Check direct
 		HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
-		
+
 		// And via calls
 		int numSheets = wb.getNumberOfSheets();
-		for(int i=0; i<numSheets; i++) {
+		for (int i = 0; i < numSheets; i++) {
 			HSSFSheet s = wb.getSheetAt(i);
-			HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s,wb);
-			
-			for(Iterator rows = s.rowIterator(); rows.hasNext();) {
-		        HSSFRow r = (HSSFRow)rows.next();
-		        eval.setCurrentRow(r);
-		        
-		        for(Iterator cells = r.cellIterator(); cells.hasNext();) {
-		        	HSSFCell c = (HSSFCell)cells.next();
-		        	eval.evaluateFormulaCell(c);
-		        }
+			HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s, wb);
+
+			for (Iterator rows = s.rowIterator(); rows.hasNext();) {
+				HSSFRow r = (HSSFRow) rows.next();
+				eval.setCurrentRow(r);
+
+				for (Iterator cells = r.cellIterator(); cells.hasNext();) {
+					HSSFCell c = (HSSFCell) cells.next();
+					eval.evaluateFormulaCell(c);
+				}
+			}
+		}
+	}
+
+	public void testEvaluateInCellWithErrorCode_bug44950() {
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet sheet = wb.createSheet("Sheet1");
+		HSSFRow row = sheet.createRow(1);
+		HSSFCell cell = row.createCell((short) 0);
+		cell.setCellFormula("na()"); // this formula evaluates to an Excel error code '#N/A'
+		HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
+		fe.setCurrentRow(row);
+		try {
+			fe.evaluateInCell(cell);
+		} catch (NumberFormatException e) {
+			if (e.getMessage().equals("You cannot get an error value from a non-error cell")) {
+				throw new AssertionFailedError("Identified bug 44950 b");
 			}
+			throw e;
 		}
 	}
 }
\ No newline at end of file

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java Fri May 16 10:08:40 2008
@@ -17,11 +17,10 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+
 /**
  * Test HSSFRow is okay.
  *
@@ -32,7 +31,7 @@
     public void testLastAndFirstColumns() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row = sheet.createRow((short) 0);
+        HSSFRow row = sheet.createRow(0);
         assertEquals(-1, row.getFirstCellNum());
         assertEquals(-1, row.getLastCellNum());
 
@@ -50,7 +49,35 @@
         assertEquals(4, row.getLastCellNum());
     }
 
-    public void testRemoveCell() throws Exception {
+    /**
+     * Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum
+     * This test was added in response to bug report 44987.
+     */
+    public void testBoundsInMultipleRows() {
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet sheet = workbook.createSheet();
+        HSSFRow rowA = sheet.createRow(0);
+
+        rowA.createCell((short) 10);
+        rowA.createCell((short) 5);
+        assertEquals(5, rowA.getFirstCellNum());
+        assertEquals(11, rowA.getLastCellNum());
+
+        HSSFRow rowB = sheet.createRow(1);
+        rowB.createCell((short) 15);
+        rowB.createCell((short) 30);
+        assertEquals(15, rowB.getFirstCellNum());
+        assertEquals(31, rowB.getLastCellNum());
+
+        assertEquals(5, rowA.getFirstCellNum());
+        assertEquals(11, rowA.getLastCellNum());
+        rowA.createCell((short) 50);
+        assertEquals(51, rowA.getLastCellNum());
+
+        assertEquals(31, rowB.getLastCellNum());
+    }
+
+    public void testRemoveCell() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
         HSSFRow row = sheet.createRow((short) 0);
@@ -76,16 +103,11 @@
         assertEquals(0, data[6]);
         assertEquals(0, data[8]);
 
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        workbook.write(baos);
-        baos.close();
-        ByteArrayInputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
-        workbook = new HSSFWorkbook(inputStream);
+        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
         sheet = workbook.getSheetAt(0);
-        inputStream.close();
 
-        assertEquals(-1, sheet.getRow((short) 0).getLastCellNum());
-        assertEquals(-1, sheet.getRow((short) 0).getFirstCellNum());
+        assertEquals(-1, sheet.getRow(0).getLastCellNum());
+        assertEquals(-1, sheet.getRow(0).getFirstCellNum());
     }
 
     public void testMoveCell() {
@@ -143,8 +165,9 @@
       try {
         sheet.createRow(-1);
         fail("IndexOutOfBoundsException should have been thrown");
-      } catch (IndexOutOfBoundsException ex) {
+      } catch (IllegalArgumentException e) {
         // expected during successful test
+        assertEquals("Invalid row number (-1) outside allowable range (0..65535)", e.getMessage());
       }
 
       //Test high row bound
@@ -153,8 +176,9 @@
       try {
         sheet.createRow(65536);
         fail("IndexOutOfBoundsException should have been thrown");
-      } catch (IndexOutOfBoundsException ex) {
+      } catch (IllegalArgumentException e) {
         // expected during successful test
+        assertEquals("Invalid row number (65536) outside allowable range (0..65535)", e.getMessage());
       }
     }
 

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=657135&r1=657134&r2=657135&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 Fri May 16 10:08:40 2008
@@ -23,6 +23,7 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -193,17 +194,29 @@
 	public void testCloneSheet() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet("Test Clone");
-		HSSFRow row = sheet.createRow((short) 0);
+		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short) 0);
-		cell.setCellValue("clone_test"); 
-		HSSFSheet cloned = workbook.cloneSheet(0);
-  
+		HSSFCell cell2 = row.createCell((short) 1);
+		cell.setCellValue(new HSSFRichTextString("clone_test")); 
+		cell2.setCellFormula("sin(1)"); 
+
+		HSSFSheet clonedSheet = workbook.cloneSheet(0);
+		HSSFRow clonedRow = clonedSheet.getRow(0);
+
 		//Check for a good clone
-		assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
+		assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "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");
+		cell.setCellValue(new HSSFRichTextString("Difference Check"));
+		cell2.setCellFormula("cos(2)");
+		if ("Difference Check".equals(clonedRow.getCell(0).getRichStringCellValue().getString())) {
+			fail("string cell not properly cloned");
+		}
+		if ("COS(2)".equals(clonedRow.getCell(1).getCellFormula())) {
+			fail("formula cell not properly cloned");
+		}
+		assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
+		assertEquals(clonedRow.getCell(1).getCellFormula(), "SIN(1)");
 	}
 
 	/** tests that the sheet name for multiple clones of the same sheet is unique
@@ -214,7 +227,7 @@
 		HSSFSheet sheet = workbook.createSheet("Test Clone");
 		HSSFRow row = sheet.createRow((short) 0);
 		HSSFCell cell = row.createCell((short) 0);
-		cell.setCellValue("clone_test");
+		cell.setCellValue(new HSSFRichTextString("clone_test"));
 		//Clone the sheet multiple times
 		workbook.cloneSheet(0);
 		workbook.cloneSheet(0);
@@ -517,11 +530,11 @@
 		HSSFSheet sheet = wb.createSheet();
 		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short)0);
-		cell.setCellValue("first row, first cell");
+		cell.setCellValue(new HSSFRichTextString("first row, first cell"));
 
 		row = sheet.createRow(1);
 		cell = row.createCell((short)1);
-		cell.setCellValue("second row, second cell");
+		cell.setCellValue(new HSSFRichTextString("second row, second cell"));
 
 		Region region = new Region(1, (short)0, 1, (short)1);   
 		sheet.addMergedRegion(region);
@@ -643,28 +656,28 @@
 
 	/** 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);
-   	r.createCell((short)0).setCellValue(1);
-   	r.createCell((short)1).setCellFormula("A1*2");
-   	HSSFSheet s1 = wb.cloneSheet(0);
-   	r=s1.getRow(0);
-   	assertEquals("double" ,r.getCell((short)0).getNumericCellValue(),(double)1,0); //sanity check
-   	assertNotNull(r.getCell((short)1)); 
-   	assertEquals("formula", r.getCell((short)1).getCellFormula(), "A1*2");
-   }
+
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet s = wb.createSheet("Sheet1");
+		HSSFRow r = s.createRow(0);
+		r.createCell((short) 0).setCellValue(1);
+		r.createCell((short) 1).setCellFormula("A1*2");
+		HSSFSheet s1 = wb.cloneSheet(0);
+		r = s1.getRow(0);
+		assertEquals("double", r.getCell((short) 0).getNumericCellValue(), 1, 0); // sanity check
+		assertNotNull(r.getCell((short) 1));
+		assertEquals("formula", r.getCell((short) 1).getCellFormula(), "A1*2");
+	}
 
 	/** test that new default column styles get applied */
 	public void testDefaultColumnStyle() {
-	HSSFWorkbook wb = new HSSFWorkbook();
-	HSSFCellStyle style = wb.createCellStyle();
-	HSSFSheet s = wb.createSheet();
-	s.setDefaultColumnStyle((short)0, style);
-	HSSFRow r = s.createRow(0);
-	HSSFCell c = r.createCell((short)0);
-	assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFCellStyle style = wb.createCellStyle();
+		HSSFSheet s = wb.createSheet();
+		s.setDefaultColumnStyle((short) 0, style);
+		HSSFRow r = s.createRow(0);
+		HSSFCell c = r.createCell((short) 0);
+		assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
 	}
 
 
@@ -814,11 +827,6 @@
 		assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation());
 	}
 
-
-	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
 		HSSFWorkbook wb = openSample("colwidth.xls");
@@ -870,11 +878,33 @@
 		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
+		//columns D-F have custom width
 		for (char i = 'D'; i <= 'F'; i++) {
 			short w = (short)(256*12);
 			assertEquals(w, sh.getColumnWidth((short)i));
 		}
+	}
+	
+	/**
+	 * Some utilities write Excel files without the ROW records.
+	 * Excel, ooo, and google docs are OK with this.
+	 * Now POI is too.
+	 */
+	public void testMissingRowRecords_bug41187() {
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls");
 
+		HSSFSheet sheet = wb.getSheetAt(0);
+		HSSFRow row = sheet.getRow(0);
+		if(row == null) {
+			throw new AssertionFailedError("Identified bug 41187 a");
+		}
+		if (row.getHeight() == 0) {
+			throw new AssertionFailedError("Identified bug 41187 b");
+		}
+		assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString());
+		// check row height for 'default' flag
+		assertEquals((short)0x8000, row.getHeight());
+		
+		HSSFTestDataSamples.writeOutAndReadBack(wb);
 	}
 }

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=657135&r1=657134&r2=657135&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 Fri May 16 10:08:40 2008
@@ -147,9 +147,10 @@
         // Single chart, two sheets
         b = openSample("44010-SingleChart.xls");
         assertEquals(2, b.getNumberOfSheets());
+        assertEquals("Graph2", b.getSheetName(1));
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         
         // Has chart on 1st sheet??
         // FIXME
@@ -166,7 +167,7 @@
         assertEquals(2, b.getNumberOfSheets());
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
 
         
         // Two charts, three sheets
@@ -175,10 +176,10 @@
         
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         s = b.getSheetAt(2);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         
         // Has chart on 1st sheet??
         // FIXME
@@ -197,13 +198,13 @@
         
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         s = b.getSheetAt(2);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
     }
     
     private static HSSFWorkbook writeRead(HSSFWorkbook b) {
-    	return HSSFTestDataSamples.writeOutAndReadBack(b);
+        return HSSFTestDataSamples.writeOutAndReadBack(b);
     }
 }
\ No newline at end of file

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Fri May 16 10:08:40 2008
@@ -17,6 +17,9 @@
 
 package org.apache.poi.poifs.filesystem;
 
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -115,6 +118,40 @@
 		assertTrue("input stream was not closed", testIS.isClosed()); // but still should close
 		
 	}
+	
+	/**
+	 * Test for bug # 48898 - problem opening an OLE2
+	 *  file where the last block is short (i.e. not a full
+	 *  multiple of 512 bytes)
+	 *  
+	 * As yet, this problem remains. One school of thought is
+	 *  not not issue an EOF when we discover the last block
+	 *  is short, but this seems a bit wrong.
+	 * The other is to fix the handling of the last block in
+	 *  POIFS, since it seems to be slight wrong
+	 */
+	public void DISABLEDtestShortLastBlock() throws Exception {
+		String[] files = new String[] {
+			"ShortLastBlock.qwp", "ShortLastBlock.wps"	
+		};
+		String pdirname = System.getProperty("POIFS.testdata.path");
+
+		for(int i=0; i<files.length; i++) {
+			File f = new File(pdirname, files[i]);
+			assertTrue(f.exists());
+			
+			// Open the file up
+			POIFSFileSystem fs = new POIFSFileSystem(
+					new FileInputStream(f)
+			);
+			
+			// Write it into a temp output array
+			ByteArrayOutputStream baos = new ByteArrayOutputStream();
+			fs.writeFilesystem(baos);
+			
+			// Check sizes
+		}
+	}
 
 	private static InputStream openSampleStream(String sampleFileName) {
 		return HSSFTestDataSamples.openSampleFileStream(sampleFileName);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java?rev=657135&r1=657134&r2=657135&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java Fri May 16 10:08:40 2008
@@ -152,7 +152,7 @@
 	            }
 	            
 	            assertEquals(
-	            		"7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document has probably been truncated!", 
+	            		"7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!", 
 	            		(String)(logger.logged.get(0))
 	            );
             } else {



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