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/03/04 17:53:38 UTC

svn commit: r633547 [4/4] - in /poi/trunk/src: java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/record/constant/ java/org/apache/poi/hssf/record/formula/ java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/u...

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,61 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.eval;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFName;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue;
+/**
+ * 
+ * @author Josh Micich
+ */
+public final class TestExternalFunction extends TestCase {
+
+	/**
+	 * Checks that an external function can get invoked from the formula evaluator. 
+	 */
+	public void testInvoke() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sheet = wb.createSheet();
+        wb.setSheetName(0, "Sheet1");
+        HSSFRow row = sheet.createRow(0);
+        HSSFCell cell = row.createCell((short)0);
+
+        HSSFName hssfName = wb.createName();
+        hssfName.setNameName("myFunc");
+        
+        cell.setCellFormula("myFunc()");
+        String actualFormula=cell.getCellFormula();
+        assertEquals("myFunc()", actualFormula);
+		
+		HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
+		fe.setCurrentRow(row);
+		CellValue evalResult = fe.evaluate(cell);
+		
+		// Check the return value from ExternalFunction.evaluate()
+		// TODO - make this test assert something more interesting as soon as ExternalFunction works a bit better
+		assertEquals(HSSFCell.CELL_TYPE_ERROR, evalResult.getCellType());
+		assertEquals(ErrorEval.FUNCTION_NOT_IMPLEMENTED.getErrorCode(), evalResult.getErrorValue());
+	}
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java Tue Mar  4 08:53:32 2008
@@ -31,10 +31,13 @@
 	// TODO - have this suite incorporated into a higher level one
 	public static Test suite() {
 		TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.record.formula.functions");
+		result.addTestSuite(TestAverage.class);
 		result.addTestSuite(TestCountFuncs.class);
 		result.addTestSuite(TestDate.class);
 		result.addTestSuite(TestFinanceLib.class);
 		result.addTestSuite(TestIndex.class);
+		result.addTestSuite(TestIsBlank.class);
+		result.addTestSuite(TestLen.class);
 		result.addTestSuite(TestMid.class);
 		result.addTestSuite(TestMathX.class);
 		result.addTestSuite(TestMatch.class);
@@ -43,6 +46,8 @@
 		result.addTestSuite(TestSumproduct.class);
 		result.addTestSuite(TestStatsLib.class);
 		result.addTestSuite(TestTFunc.class);
+		result.addTestSuite(TestTrim.class);
+		result.addTestSuite(TestXYNumericFunction.class);
 		return result;
 	}
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java Tue Mar  4 08:53:32 2008
@@ -58,6 +58,6 @@
 	 * Creates a single RefEval (with value zero)
 	 */
 	public static RefEval createRefEval(String refStr) {
-		return new Ref2DEval(new ReferencePtg(refStr), ZERO, true);
+		return new Ref2DEval(new ReferencePtg(refStr), ZERO);
 	}
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/NumericFunctionInvoker.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/NumericFunctionInvoker.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/NumericFunctionInvoker.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/NumericFunctionInvoker.java Tue Mar  4 08:53:32 2008
@@ -111,9 +111,6 @@
 		if(errorCodesAreEqual(ee, ErrorEval.FUNCTION_NOT_IMPLEMENTED)) {
 			return "Function not implemented";
 		}
-		if(errorCodesAreEqual(ee, ErrorEval.UNKNOWN_ERROR)) {
-			return "Unknown error";
-		}
 		if(errorCodesAreEqual(ee, ErrorEval.VALUE_INVALID)) {
 			return "Error code: #VALUE! (invalid value)";
 		}

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestAverage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestAverage.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestAverage.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestAverage.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,103 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.functions;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+/**
+ * Tests for Excel function AVERAGE()
+ * 
+ * @author Josh Micich
+ */
+public final class TestAverage extends TestCase {
+
+	
+	private static Eval invokeAverage(Eval[] args) {
+		return new Average().evaluate(args, -1, (short)-1);
+	}
+
+	private void confirmAverage(Eval[] args, double expected) {
+		Eval result = invokeAverage(args);
+		assertEquals(NumberEval.class, result.getClass());
+		assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
+	}
+
+	private void confirmAverage(Eval[] args, ErrorEval expectedError) {
+		Eval result = invokeAverage(args);
+		assertEquals(ErrorEval.class, result.getClass());
+		assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
+	}
+	
+	public void testBasic() {
+		
+		ValueEval[] values = {
+				new NumberEval(1),	
+				new NumberEval(2),	
+				new NumberEval(3),	
+				new NumberEval(4),	
+		};
+		
+		confirmAverage(values, 2.5);
+		
+		values = new ValueEval[] {
+				new NumberEval(1),	
+				new NumberEval(2),
+				BlankEval.INSTANCE,
+				new NumberEval(3),	
+				BlankEval.INSTANCE,
+				new NumberEval(4),	
+				BlankEval.INSTANCE,
+		};
+		
+		confirmAverage(values, 2.5);
+	}
+	
+	/**
+	 * Valid cases where values are not pure numbers
+	 */
+	public void testUnusualArgs() {
+		ValueEval[] values = {
+				new NumberEval(1),	
+				new NumberEval(2),	
+				BoolEval.TRUE,	
+				BoolEval.FALSE,	
+		};
+		
+		confirmAverage(values, 1.0);
+		
+	}
+
+	// currently disabled because MultiOperandNumericFunction.getNumberArray(Eval[], int, short)
+	// does not handle error values properly yet
+	public void XtestErrors() {
+		ValueEval[] values = {
+				new NumberEval(1),	
+				ErrorEval.NAME_INVALID,	
+				new NumberEval(3),	
+				ErrorEval.DIV_ZERO,	
+		};
+		confirmAverage(values, ErrorEval.NAME_INVALID);
+			
+	}
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestAverage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestAverage.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java Tue Mar  4 08:53:32 2008
@@ -125,7 +125,7 @@
 		};
 		Area2DEval arg0 = new Area2DEval(new AreaPtg("C1:C6"), values);
 		
-		Ref2DEval criteriaArg = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(25), true);
+		Ref2DEval criteriaArg = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(25));
 		Eval[] args=  { arg0, criteriaArg, };
 		
 		double actual = NumericFunctionInvoker.invoke(new Countif(), args);

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,62 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.functions;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue;
+/**
+ * Tests for Excel function ISBLANK()
+ * 
+ * @author Josh Micich
+ */
+public final class TestIsBlank extends TestCase {
+
+	
+
+	public void test3DArea() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        HSSFSheet sheet1 = wb.createSheet();
+        wb.setSheetName(0, "Sheet1");
+        wb.createSheet();
+        wb.setSheetName(1, "Sheet2");
+        HSSFRow row = sheet1.createRow(0);
+        HSSFCell cell = row.createCell((short)0);
+
+         
+        cell.setCellFormula("isblank(Sheet2!A1:A1)");
+        
+        HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet1, wb);
+        fe.setCurrentRow(row);
+        CellValue result = fe.evaluate(cell);
+        assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
+        assertEquals(true, result.getBooleanValue());
+        
+        cell.setCellFormula("isblank(D7:D7)");
+        
+        result = fe.evaluate(cell);
+        assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
+        assertEquals(true, result.getBooleanValue());
+        
+   }
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestLen.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestLen.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestLen.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestLen.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,73 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.functions;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+/**
+ * Tests for Excel function LEN()
+ * 
+ * @author Josh Micich
+ */
+public final class TestLen extends TestCase {
+
+	
+	private static Eval invokeLen(Eval text) {
+		Eval[] args = new Eval[] { text, };
+		return new Len().evaluate(args, -1, (short)-1);
+	}
+
+	private void confirmLen(Eval text, int expected) {
+		Eval result = invokeLen(text);
+		assertEquals(NumberEval.class, result.getClass());
+		assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
+	}
+
+	private void confirmLen(Eval text, ErrorEval expectedError) {
+		Eval result = invokeLen(text);
+		assertEquals(ErrorEval.class, result.getClass());
+		assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
+	}
+	
+	public void testBasic() {
+		
+		confirmLen(new StringEval("galactic"), 8);
+	}
+	
+	/**
+	 * Valid cases where text arg is not exactly a string
+	 */
+	public void testUnusualArgs() {
+		
+		// text (first) arg type is number, other args are strings with fractional digits 
+		confirmLen(new NumberEval(123456), 6);
+		confirmLen(BoolEval.FALSE, 5);
+		confirmLen(BoolEval.TRUE, 4);
+		confirmLen(BlankEval.INSTANCE, 0);
+	}
+
+	public void testErrors() {
+		confirmLen(ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
+	}
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestLen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestLen.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestMid.java Tue Mar  4 08:53:32 2008
@@ -77,13 +77,14 @@
 		
 		// startPos is 1x1 area ref, numChars is cell ref
 		AreaEval aeStart = new Area2DEval(new AreaPtg("A1:A1"), new ValueEval[] { new NumberEval(2), } );
-		RefEval reNumChars = new Ref2DEval(new ReferencePtg("B1"), new NumberEval(3),false);
+		RefEval reNumChars = new Ref2DEval(new ReferencePtg("B1"), new NumberEval(3));
 		confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
 
 		confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.INSTANCE, "");
 
 		confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.FALSE, "");
 		confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.TRUE, "l");
+		confirmMid(BlankEval.INSTANCE, new NumberEval(3), BoolEval.TRUE, "");
 	
 	}
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestSumproduct.java Tue Mar  4 08:53:32 2008
@@ -50,7 +50,7 @@
 
 	public void testScalarSimple() {
 		
-		RefEval refEval = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(3), true);
+		RefEval refEval = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(3));
 		Eval[] args = {
 			refEval, 
 			new NumberEval(2),

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java Tue Mar  4 08:53:32 2008
@@ -50,7 +50,7 @@
 	 * where cell A1 has the specified innerValue
 	 */
 	private Eval invokeTWithReference(ValueEval innerValue) {
-		Eval arg = new Ref2DEval(new ReferencePtg((short)1, (short)1, false, false), innerValue, true);
+		Eval arg = new Ref2DEval(new ReferencePtg((short)1, (short)1, false, false), innerValue);
 		return invokeT(arg);
 	}
 	

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTrim.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTrim.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTrim.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTrim.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,78 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.functions;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+/**
+ * Tests for Excel function TRIM()
+ * 
+ * @author Josh Micich
+ */
+public final class TestTrim extends TestCase {
+
+	
+	private static Eval invokeTrim(Eval text) {
+		Eval[] args = new Eval[] { text, };
+		return new Trim().evaluate(args, -1, (short)-1);
+	}
+
+	private void confirmTrim(Eval text, String expected) {
+		Eval result = invokeTrim(text);
+		assertEquals(StringEval.class, result.getClass());
+		assertEquals(expected, ((StringEval)result).getStringValue());
+	}
+
+	private void confirmTrim(Eval text, ErrorEval expectedError) {
+		Eval result = invokeTrim(text);
+		assertEquals(ErrorEval.class, result.getClass());
+		assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
+	}
+	
+	public void testBasic() {
+		
+		confirmTrim(new StringEval(" hi "), "hi");
+		confirmTrim(new StringEval("hi "), "hi");
+		confirmTrim(new StringEval("  hi"), "hi");
+		confirmTrim(new StringEval(" hi there  "), "hi there");
+		confirmTrim(new StringEval(""), "");
+		confirmTrim(new StringEval("   "), "");
+	}
+	
+	/**
+	 * Valid cases where text arg is not exactly a string
+	 */
+	public void testUnusualArgs() {
+		
+		// text (first) arg type is number, other args are strings with fractional digits 
+		confirmTrim(new NumberEval(123456), "123456");
+		confirmTrim(BoolEval.FALSE, "FALSE");
+		confirmTrim(BoolEval.TRUE, "TRUE");
+		confirmTrim(BlankEval.INSTANCE, "");
+	}
+
+	public void testErrors() {
+		confirmTrim(ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
+	}
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTrim.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestTrim.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestXYNumericFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestXYNumericFunction.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestXYNumericFunction.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestXYNumericFunction.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,139 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.functions;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.record.formula.AreaPtg;
+import org.apache.poi.hssf.record.formula.eval.Area2DEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+/**
+ * Tests for Excel functions SUMX2MY2(), SUMX2PY2(), SUMXMY2()
+ * 
+ * @author Josh Micich
+ */
+public final class TestXYNumericFunction extends TestCase {
+	private static final Function SUM_SQUARES = new Sumx2py2();
+	private static final Function DIFF_SQUARES = new Sumx2my2();
+	private static final Function SUM_SQUARES_OF_DIFFS = new Sumxmy2();
+	
+	private static Eval invoke(Function function, Eval xArray, Eval yArray) {
+		Eval[] args = new Eval[] { xArray, yArray, };
+		return function.evaluate(args, -1, (short)-1);
+	}
+
+	private void confirm(Function function, Eval xArray, Eval yArray, double expected) {
+		Eval result = invoke(function, xArray, yArray);
+		assertEquals(NumberEval.class, result.getClass());
+		assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
+	}
+	private void confirmError(Function function, Eval xArray, Eval yArray, ErrorEval expectedError) {
+		Eval result = invoke(function, xArray, yArray);
+		assertEquals(ErrorEval.class, result.getClass());
+		assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
+	}
+
+	private void confirmError(Eval xArray, Eval yArray, ErrorEval expectedError) {
+		confirmError(SUM_SQUARES, xArray, yArray, expectedError);
+		confirmError(DIFF_SQUARES, xArray, yArray, expectedError);
+		confirmError(SUM_SQUARES_OF_DIFFS, xArray, yArray, expectedError);
+	}
+	
+	public void testBasic() {
+		ValueEval[] xValues = {
+			new NumberEval(1),	
+			new NumberEval(2),	
+		};
+		ValueEval areaEvalX = createAreaEval(xValues);
+		confirm(SUM_SQUARES, areaEvalX, areaEvalX, 10.0);
+		confirm(DIFF_SQUARES, areaEvalX, areaEvalX, 0.0);
+		confirm(SUM_SQUARES_OF_DIFFS, areaEvalX, areaEvalX, 0.0);
+
+		ValueEval[] yValues = {
+			new NumberEval(3),	
+			new NumberEval(4),	
+		};
+		ValueEval areaEvalY = createAreaEval(yValues);
+		confirm(SUM_SQUARES, areaEvalX, areaEvalY, 30.0);
+		confirm(DIFF_SQUARES, areaEvalX, areaEvalY, -20.0);
+		confirm(SUM_SQUARES_OF_DIFFS, areaEvalX, areaEvalY, 8.0);
+	}
+	
+	/**
+	 * number of items in array is not limited to 30
+	 */
+	public void testLargeArrays() {
+		ValueEval[] xValues = createMockNumberArray(100, 3);
+		ValueEval[] yValues = createMockNumberArray(100, 2);
+		
+		confirm(SUM_SQUARES, createAreaEval(xValues), createAreaEval(yValues), 1300.0);
+		confirm(DIFF_SQUARES, createAreaEval(xValues), createAreaEval(yValues), 500.0);
+		confirm(SUM_SQUARES_OF_DIFFS, createAreaEval(xValues), createAreaEval(yValues), 100.0);
+	}
+	
+
+	private ValueEval[] createMockNumberArray(int size, double value) {
+		ValueEval[] result = new ValueEval[size];
+		for (int i = 0; i < result.length; i++) {
+			result[i] = new NumberEval(value);
+		}
+		return result;
+	}
+
+	private static ValueEval createAreaEval(ValueEval[] values) {
+		String refStr = "A1:A" + values.length;
+		return new Area2DEval(new AreaPtg(refStr), values);
+	}
+
+	public void testErrors() {
+		ValueEval[] xValues = {
+				ErrorEval.REF_INVALID,	
+				new NumberEval(2),	
+		};
+		ValueEval areaEvalX = createAreaEval(xValues);
+		ValueEval[] yValues = {
+				new NumberEval(2),	
+				ErrorEval.NULL_INTERSECTION,	
+		};
+		ValueEval areaEvalY = createAreaEval(yValues);
+		ValueEval[] zValues = { // wrong size
+				new NumberEval(2),	
+		};
+		ValueEval areaEvalZ = createAreaEval(zValues);
+		
+		// if either arg is an error, that error propagates
+		confirmError(ErrorEval.REF_INVALID, ErrorEval.NAME_INVALID, ErrorEval.REF_INVALID);
+		confirmError(areaEvalX, ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
+		confirmError(ErrorEval.NAME_INVALID, areaEvalX, ErrorEval.NAME_INVALID);
+
+		// array sizes must match
+		confirmError(areaEvalX, areaEvalZ, ErrorEval.NA);
+		confirmError(areaEvalZ, areaEvalY, ErrorEval.NA);
+
+		// any error in an array item propagates up
+		confirmError(areaEvalX, areaEvalX, ErrorEval.REF_INVALID);
+		
+		// search for errors array by array, not pair by pair
+		confirmError(areaEvalX, areaEvalY, ErrorEval.REF_INVALID);
+		confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION);
+		
+	}
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestXYNumericFunction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestXYNumericFunction.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTests.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTests.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTests.java Tue Mar  4 08:53:32 2008
@@ -14,7 +14,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
+
 package org.apache.poi.hssf;
 
 import junit.framework.Test;
@@ -25,80 +25,8 @@
 import org.apache.poi.hssf.model.TestDrawingManager;
 import org.apache.poi.hssf.model.TestFormulaParser;
 import org.apache.poi.hssf.model.TestSheet;
-import org.apache.poi.hssf.record.TestAreaFormatRecord;
-import org.apache.poi.hssf.record.TestAreaRecord;
-import org.apache.poi.hssf.record.TestAxisLineFormatRecord;
-import org.apache.poi.hssf.record.TestAxisOptionsRecord;
-import org.apache.poi.hssf.record.TestAxisParentRecord;
-import org.apache.poi.hssf.record.TestAxisRecord;
-import org.apache.poi.hssf.record.TestAxisUsedRecord;
-import org.apache.poi.hssf.record.TestBarRecord;
-import org.apache.poi.hssf.record.TestBoundSheetRecord;
-import org.apache.poi.hssf.record.TestCategorySeriesAxisRecord;
-import org.apache.poi.hssf.record.TestChartRecord;
-import org.apache.poi.hssf.record.TestDatRecord;
-import org.apache.poi.hssf.record.TestDataFormatRecord;
-import org.apache.poi.hssf.record.TestDefaultDataLabelTextPropertiesRecord;
-import org.apache.poi.hssf.record.TestFontBasisRecord;
-import org.apache.poi.hssf.record.TestFontIndexRecord;
-import org.apache.poi.hssf.record.TestFormulaRecord;
-import org.apache.poi.hssf.record.TestFrameRecord;
-import org.apache.poi.hssf.record.TestLegendRecord;
-import org.apache.poi.hssf.record.TestLineFormatRecord;
-import org.apache.poi.hssf.record.TestLinkedDataRecord;
-import org.apache.poi.hssf.record.TestNameRecord;
-import org.apache.poi.hssf.record.TestNumberFormatIndexRecord;
-import org.apache.poi.hssf.record.TestObjectLinkRecord;
-import org.apache.poi.hssf.record.TestPaletteRecord;
-import org.apache.poi.hssf.record.TestPlotAreaRecord;
-import org.apache.poi.hssf.record.TestPlotGrowthRecord;
-import org.apache.poi.hssf.record.TestRecordFactory;
-import org.apache.poi.hssf.record.TestSCLRecord;
-import org.apache.poi.hssf.record.TestSSTDeserializer;
-import org.apache.poi.hssf.record.TestSSTRecord;
-import org.apache.poi.hssf.record.TestSSTRecordSizeCalculator;
-import org.apache.poi.hssf.record.TestSeriesChartGroupIndexRecord;
-import org.apache.poi.hssf.record.TestSeriesIndexRecord;
-import org.apache.poi.hssf.record.TestSeriesLabelsRecord;
-import org.apache.poi.hssf.record.TestSeriesListRecord;
-import org.apache.poi.hssf.record.TestSeriesRecord;
-import org.apache.poi.hssf.record.TestSeriesTextRecord;
-import org.apache.poi.hssf.record.TestSeriesToChartGroupRecord;
-import org.apache.poi.hssf.record.TestSheetPropertiesRecord;
-import org.apache.poi.hssf.record.TestStringRecord;
-import org.apache.poi.hssf.record.TestSupBookRecord;
-import org.apache.poi.hssf.record.TestTextRecord;
-import org.apache.poi.hssf.record.TestTickRecord;
-import org.apache.poi.hssf.record.TestUnicodeString;
-import org.apache.poi.hssf.record.TestUnitsRecord;
-import org.apache.poi.hssf.record.TestValueRangeRecord;
-import org.apache.poi.hssf.record.aggregates.TestRowRecordsAggregate;
-import org.apache.poi.hssf.record.aggregates.TestValueRecordsAggregate;
-import org.apache.poi.hssf.record.formula.AllFormulaTests;
-import org.apache.poi.hssf.usermodel.TestBugs;
-import org.apache.poi.hssf.usermodel.TestCellStyle;
-import org.apache.poi.hssf.usermodel.TestCloneSheet;
-import org.apache.poi.hssf.usermodel.TestEscherGraphics;
-import org.apache.poi.hssf.usermodel.TestEscherGraphics2d;
-import org.apache.poi.hssf.usermodel.TestFontDetails;
-import org.apache.poi.hssf.usermodel.TestFormulas;
-import org.apache.poi.hssf.usermodel.TestHSSFCell;
-import org.apache.poi.hssf.usermodel.TestHSSFClientAnchor;
-import org.apache.poi.hssf.usermodel.TestHSSFComment;
-import org.apache.poi.hssf.usermodel.TestHSSFDateUtil;
-import org.apache.poi.hssf.usermodel.TestHSSFHeaderFooter;
-import org.apache.poi.hssf.usermodel.TestHSSFPalette;
-import org.apache.poi.hssf.usermodel.TestHSSFRichTextString;
-import org.apache.poi.hssf.usermodel.TestHSSFRow;
-import org.apache.poi.hssf.usermodel.TestHSSFSheet;
-import org.apache.poi.hssf.usermodel.TestHSSFSheetOrder;
-import org.apache.poi.hssf.usermodel.TestHSSFSheetSetOrder;
-import org.apache.poi.hssf.usermodel.TestHSSFWorkbook;
-import org.apache.poi.hssf.usermodel.TestNamedRange;
-import org.apache.poi.hssf.usermodel.TestReadWriteChart;
-import org.apache.poi.hssf.usermodel.TestSanityChecker;
-import org.apache.poi.hssf.usermodel.TestSheetShiftRows;
-import org.apache.poi.hssf.usermodel.TestWorkbook;
+import org.apache.poi.hssf.record.AllRecordTests;
+import org.apache.poi.hssf.usermodel.AllUserModelTests;
 import org.apache.poi.hssf.util.TestAreaReference;
 import org.apache.poi.hssf.util.TestCellReference;
 import org.apache.poi.hssf.util.TestRKUtil;
@@ -112,113 +40,30 @@
  * 
  * @author Andrew C. Oliver acoliver@apache.org
  */
-public final class HSSFTests
-{
+public final class HSSFTests {
 
-    public static void main(String[] args)
-    {
+    public static void main(String[] args) {
         junit.textui.TestRunner.run(suite());
     }
 
-    public static Test suite()
-    {
-        TestSuite suite =
-            new TestSuite("Tests for org.apache.poi.hssf");
-        //$JUnit-BEGIN$
-
-    suite.addTest(new TestSuite(TestBugs.class));
-    suite.addTest(new TestSuite(TestCloneSheet.class));
-    suite.addTest(new TestSuite(TestEscherGraphics.class));
-    suite.addTest(new TestSuite(TestEscherGraphics2d.class));
-    suite.addTest(new TestSuite(TestFontDetails.class));
-    suite.addTest(new TestSuite(TestHSSFClientAnchor.class));
-    suite.addTest(new TestSuite(TestHSSFHeaderFooter.class));
-    suite.addTest(new TestSuite(TestHSSFRichTextString.class));
-    suite.addTest(new TestSuite(TestHSSFSheetOrder.class));
-    suite.addTest(new TestSuite(TestHSSFSheetSetOrder.class));
-    suite.addTest(new TestSuite(TestHSSFWorkbook.class));
-    suite.addTest(new TestSuite(TestSanityChecker.class));
-    suite.addTest(new TestSuite(TestSheetShiftRows.class));
-
-        suite.addTest(new TestSuite(TestCellStyle.class));
-        suite.addTest(new TestSuite(TestFormulas.class));
-        suite.addTest(new TestSuite(TestHSSFCell.class));
-        suite.addTest(new TestSuite(TestHSSFDateUtil.class));
-        suite.addTest(new TestSuite(TestHSSFPalette.class));
-        suite.addTest(new TestSuite(TestHSSFRow.class));
-        suite.addTest(new TestSuite(TestHSSFSheet.class));
-        suite.addTest(new TestSuite(TestNamedRange.class));
-        suite.addTest(new TestSuite(TestReadWriteChart.class));
-        suite.addTest(new TestSuite(TestWorkbook.class));
-
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Tests for org.apache.poi.hssf");
+        // $JUnit-BEGIN$
 
+        suite.addTest(AllUserModelTests.suite());
+        suite.addTest(AllRecordTests.suite());
 
         suite.addTest(new TestSuite(TestFormulaParser.class));
-        suite.addTest(new TestSuite(TestAreaFormatRecord.class));
-        suite.addTest(new TestSuite(TestAreaRecord.class));
-        suite.addTest(new TestSuite(TestAxisLineFormatRecord.class));
-        suite.addTest(new TestSuite(TestAxisOptionsRecord.class));
-        suite.addTest(new TestSuite(TestAxisParentRecord.class));
-        suite.addTest(new TestSuite(TestAxisRecord.class));
-        suite.addTest(new TestSuite(TestAxisUsedRecord.class));
-        suite.addTest(new TestSuite(TestBarRecord.class));
-        suite.addTest(new TestSuite(TestBoundSheetRecord.class));
-        suite.addTest(new TestSuite(TestCategorySeriesAxisRecord.class));
-        suite.addTest(new TestSuite(TestChartRecord.class));
-        suite.addTest(new TestSuite(TestDatRecord.class));
-        suite.addTest(new TestSuite(TestDataFormatRecord.class));
-        suite.addTest(
-            new TestSuite(TestDefaultDataLabelTextPropertiesRecord.class));
-        suite.addTest(new TestSuite(TestFontBasisRecord.class));
-        suite.addTest(new TestSuite(TestFontIndexRecord.class));
-        suite.addTest(new TestSuite(TestFormulaRecord.class));
-        suite.addTest(new TestSuite(TestFrameRecord.class));
-        suite.addTest(new TestSuite(TestLegendRecord.class));
-        suite.addTest(new TestSuite(TestLineFormatRecord.class));
-        suite.addTest(new TestSuite(TestLinkedDataRecord.class));
-        suite.addTest(new TestSuite(TestNumberFormatIndexRecord.class));
-        suite.addTest(new TestSuite(TestObjectLinkRecord.class));
-        suite.addTest(new TestSuite(TestPaletteRecord.class));
-        suite.addTest(new TestSuite(TestPlotAreaRecord.class));
-        suite.addTest(new TestSuite(TestPlotGrowthRecord.class));
-        suite.addTest(new TestSuite(TestRecordFactory.class));
-        suite.addTest(new TestSuite(TestSCLRecord.class));
-        suite.addTest(new TestSuite(TestSSTDeserializer.class));
-        suite.addTest(new TestSuite(TestSSTRecord.class));
-        suite.addTest(new TestSuite(TestSSTRecordSizeCalculator.class));
-        suite.addTest(new TestSuite(TestSeriesChartGroupIndexRecord.class));
-        suite.addTest(new TestSuite(TestSeriesIndexRecord.class));
-        suite.addTest(new TestSuite(TestSeriesLabelsRecord.class));
-        suite.addTest(new TestSuite(TestSeriesListRecord.class));
-        suite.addTest(new TestSuite(TestSeriesRecord.class));
-        suite.addTest(new TestSuite(TestSeriesTextRecord.class));
-        suite.addTest(new TestSuite(TestSeriesToChartGroupRecord.class));
-        suite.addTest(new TestSuite(TestSheetPropertiesRecord.class));
-        suite.addTest(new TestSuite(TestStringRecord.class));
-        suite.addTest(new TestSuite(TestSupBookRecord.class));
-        suite.addTest(new TestSuite(TestTextRecord.class));
-        suite.addTest(new TestSuite(TestTickRecord.class));
-        suite.addTest(new TestSuite(TestUnicodeString.class));
-        suite.addTest(new TestSuite(TestUnitsRecord.class));
-        suite.addTest(new TestSuite(TestValueRangeRecord.class));
-        suite.addTest(new TestSuite(TestRowRecordsAggregate.class));
         suite.addTest(new TestSuite(TestAreaReference.class));
         suite.addTest(new TestSuite(TestCellReference.class));
-		  suite.addTest(new TestSuite(TestRangeAddress.class));		
+        suite.addTest(new TestSuite(TestRangeAddress.class));
         suite.addTest(new TestSuite(TestRKUtil.class));
         suite.addTest(new TestSuite(TestSheetReferences.class));
-        
-        
-        suite.addTest(AllFormulaTests.suite());
-		  suite.addTest(new TestSuite(TestValueRecordsAggregate.class));
-		  suite.addTest(new TestSuite(TestNameRecord.class));
-                  suite.addTest(new TestSuite(TestEventRecordFactory.class));
-                  suite.addTest(new TestSuite(TestModelFactory.class));
-                  suite.addTest(new TestSuite(TestDrawingManager.class));
-                  suite.addTest(new TestSuite(TestSheet.class));
-
-        suite.addTest(new TestSuite(TestHSSFComment.class));
-        //$JUnit-END$
+        suite.addTest(new TestSuite(TestEventRecordFactory.class));
+        suite.addTest(new TestSuite(TestModelFactory.class));
+        suite.addTest(new TestSuite(TestDrawingManager.class));
+        suite.addTest(new TestSuite(TestSheet.class));
+        // $JUnit-END$
         return suite;
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
Binary files - no diff available.

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/externalFunctionExample.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/externalFunctionExample.xls?rev=633547&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/externalFunctionExample.xls
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/externalFunctionExample.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/logoKarmokar4.png
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/logoKarmokar4.png?rev=633547&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/logoKarmokar4.png
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/logoKarmokar4.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java Tue Mar  4 08:53:32 2008
@@ -18,27 +18,34 @@
         
 package org.apache.poi.hssf.model;
 
-import java.util.List;
-
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
 import org.apache.poi.hssf.record.formula.AddPtg;
+import org.apache.poi.hssf.record.formula.AreaPtg;
 import org.apache.poi.hssf.record.formula.AttrPtg;
 import org.apache.poi.hssf.record.formula.BoolPtg;
+import org.apache.poi.hssf.record.formula.ConcatPtg;
 import org.apache.poi.hssf.record.formula.DividePtg;
 import org.apache.poi.hssf.record.formula.EqualPtg;
+import org.apache.poi.hssf.record.formula.ErrPtg;
 import org.apache.poi.hssf.record.formula.FuncPtg;
 import org.apache.poi.hssf.record.formula.FuncVarPtg;
 import org.apache.poi.hssf.record.formula.IntPtg;
 import org.apache.poi.hssf.record.formula.LessEqualPtg;
 import org.apache.poi.hssf.record.formula.LessThanPtg;
+import org.apache.poi.hssf.record.formula.MissingArgPtg;
+import org.apache.poi.hssf.record.formula.MultiplyPtg;
 import org.apache.poi.hssf.record.formula.NamePtg;
 import org.apache.poi.hssf.record.formula.NotEqualPtg;
 import org.apache.poi.hssf.record.formula.NumberPtg;
+import org.apache.poi.hssf.record.formula.PercentPtg;
+import org.apache.poi.hssf.record.formula.PowerPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.record.formula.ReferencePtg;
 import org.apache.poi.hssf.record.formula.StringPtg;
+import org.apache.poi.hssf.record.formula.SubtractPtg;
 import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
 import org.apache.poi.hssf.record.formula.UnaryPlusPtg;
 import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -64,15 +71,25 @@
     public void tearDown() {
         
     }
+    /**
+     * @return parsed token array already confirmed not <code>null</code>
+     */
+    private static Ptg[] parseFormula(String s) {
+        FormulaParser fp = new FormulaParser(s, null);
+        fp.parse();
+        Ptg[] result = fp.getRPNPtg();
+        assertNotNull("Ptg array should not be null", result);
+        return result;
+    }
     
     public void testSimpleFormula() {
-        FormulaParser fp = new FormulaParser("2+2;",null);
+        FormulaParser fp = new FormulaParser("2+2",null);
         fp.parse();
         Ptg[] ptgs = fp.getRPNPtg();
         assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3);
     }
     public void testFormulaWithSpace1() {
-        FormulaParser fp = new FormulaParser(" 2 + 2 ;",null);
+        FormulaParser fp = new FormulaParser(" 2 + 2 ",null);
         fp.parse();
         Ptg[] ptgs = fp.getRPNPtg();
         assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3);
@@ -85,7 +102,7 @@
     public void testFormulaWithSpace2() {
         Ptg[] ptgs;
         FormulaParser fp;
-        fp = new FormulaParser("2+ sum( 3 , 4) ;",null);
+        fp = new FormulaParser("2+ sum( 3 , 4) ",null);
         fp.parse();
         ptgs = fp.getRPNPtg();
         assertTrue("five tokens expected, got "+ptgs.length,ptgs.length == 5);
@@ -94,7 +111,7 @@
      public void testFormulaWithSpaceNRef() {
         Ptg[] ptgs;
         FormulaParser fp;
-        fp = new FormulaParser("sum( A2:A3 );",null);
+        fp = new FormulaParser("sum( A2:A3 )",null);
         fp.parse();
         ptgs = fp.getRPNPtg();
         assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
@@ -103,7 +120,7 @@
     public void testFormulaWithString() {
         Ptg[] ptgs;
         FormulaParser fp;
-        fp = new FormulaParser("\"hello\" & \"world\" ;",null);
+        fp = new FormulaParser("\"hello\" & \"world\" ",null);
         fp.parse();
         ptgs = fp.getRPNPtg();
         assertTrue("three token expected, got " + ptgs.length, ptgs.length == 3);
@@ -276,20 +293,21 @@
 	}
 	    
     public void testMacroFunction() {
-        Workbook w = new Workbook();
+        Workbook w = Workbook.createWorkbook();
         FormulaParser fp = new FormulaParser("FOO()", w);
         fp.parse();
         Ptg[] ptg = fp.getRPNPtg();
 
-        AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[0];
-        assertEquals("externalflag", tfunc.getName());
-
-        NamePtg tname = (NamePtg) ptg[1];
+        // the name gets encoded as the first arg
+        NamePtg tname = (NamePtg) ptg[0];
         assertEquals("FOO", tname.toFormulaString(w));
+        
+        AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[1];
+        assertEquals("externalflag", tfunc.getName());
     }
 
     public void testEmbeddedSlash() {
-        FormulaParser fp = new FormulaParser("HYPERLINK(\"http://www.jakarta.org\",\"Jakarta\");",null);
+        FormulaParser fp = new FormulaParser("HYPERLINK(\"http://www.jakarta.org\",\"Jakarta\")",null);
         fp.parse();
         Ptg[] ptg = fp.getRPNPtg();
         assertTrue("first ptg is string",ptg[0] instanceof StringPtg);
@@ -588,5 +606,235 @@
                 new FuncPtg(10, 0),
         };
         assertEquals("NA()", FormulaParser.toFormulaString(book, ptgs));
+    }
+
+    public void testPercent() {
+        Ptg[] ptgs;
+        ptgs = parseFormula("5%");
+        assertEquals(2, ptgs.length);
+        assertEquals(ptgs[0].getClass(), IntPtg.class);
+        assertEquals(ptgs[1].getClass(), PercentPtg.class);
+
+        // spaces OK
+        ptgs = parseFormula(" 250 % ");
+        assertEquals(2, ptgs.length);
+        assertEquals(ptgs[0].getClass(), IntPtg.class);
+        assertEquals(ptgs[1].getClass(), PercentPtg.class);
+        
+        
+        // double percent OK 
+        ptgs = parseFormula("12345.678%%");
+        assertEquals(3, ptgs.length);
+        assertEquals(ptgs[0].getClass(), NumberPtg.class);
+        assertEquals(ptgs[1].getClass(), PercentPtg.class);
+        assertEquals(ptgs[2].getClass(), PercentPtg.class);
+        
+        // percent of a bracketed expression
+        ptgs = parseFormula("(A1+35)%*B1%");
+        assertEquals(8, ptgs.length);
+        assertEquals(ptgs[4].getClass(), PercentPtg.class);
+        assertEquals(ptgs[6].getClass(), PercentPtg.class);
+        
+        // percent of a text quantity
+        ptgs = parseFormula("\"8.75\"%");
+        assertEquals(2, ptgs.length);
+        assertEquals(ptgs[0].getClass(), StringPtg.class);
+        assertEquals(ptgs[1].getClass(), PercentPtg.class);
+
+        // percent to the power of
+        ptgs = parseFormula("50%^3");
+        assertEquals(4, ptgs.length);
+        assertEquals(ptgs[0].getClass(), IntPtg.class);
+        assertEquals(ptgs[1].getClass(), PercentPtg.class);
+        assertEquals(ptgs[2].getClass(), IntPtg.class);
+        assertEquals(ptgs[3].getClass(), PowerPtg.class);
+
+        //
+        // things that parse OK but would *evaluate* to an error
+        
+        ptgs = parseFormula("\"abc\"%");
+        assertEquals(2, ptgs.length);
+        assertEquals(ptgs[0].getClass(), StringPtg.class);
+        assertEquals(ptgs[1].getClass(), PercentPtg.class);
+        
+        ptgs = parseFormula("#N/A%");
+        assertEquals(2, ptgs.length);
+        assertEquals(ptgs[0].getClass(), ErrPtg.class);
+        assertEquals(ptgs[1].getClass(), PercentPtg.class);
+    }
+    
+    /**
+     * Tests combinations of various operators in the absence of brackets
+     */
+    public void testPrecedenceAndAssociativity() {
+
+        Class[] expClss;
+        
+        // TRUE=TRUE=2=2  evaluates to FALSE
+        expClss = new Class[] { BoolPtg.class, BoolPtg.class, EqualPtg.class, 
+                IntPtg.class, EqualPtg.class, IntPtg.class, EqualPtg.class,  };
+        confirmTokenClasses("TRUE=TRUE=2=2", expClss);
+       
+
+        //  2^3^2    evaluates to 64 not 512
+        expClss = new Class[] { IntPtg.class, IntPtg.class, PowerPtg.class, 
+                IntPtg.class, PowerPtg.class, };
+        confirmTokenClasses("2^3^2", expClss);
+        
+        // "abc" & 2 + 3 & "def"   evaluates to "abc5def"
+        expClss = new Class[] { StringPtg.class, IntPtg.class, IntPtg.class, 
+                AddPtg.class, ConcatPtg.class, StringPtg.class, ConcatPtg.class, };
+        confirmTokenClasses("\"abc\"&2+3&\"def\"", expClss);
+        
+        
+        //  (1 / 2) - (3 * 4)
+        expClss = new Class[] { IntPtg.class, IntPtg.class, DividePtg.class, 
+                IntPtg.class, IntPtg.class, MultiplyPtg.class, SubtractPtg.class, };
+        confirmTokenClasses("1/2-3*4", expClss);
+        
+        // 2 * (2^2)
+        expClss = new Class[] { IntPtg.class, IntPtg.class, IntPtg.class, PowerPtg.class, MultiplyPtg.class, };
+        // NOT: (2 *2) ^ 2 -> int int multiply int power
+        confirmTokenClasses("2*2^2", expClss);
+        
+        //  2^200% -> 2 not 1.6E58
+        expClss = new Class[] { IntPtg.class, IntPtg.class, PercentPtg.class, PowerPtg.class, };
+        confirmTokenClasses("2^200%", expClss);
+    }
+    
+    private static void confirmTokenClasses(String formula, Class[] expectedClasses) {
+        Ptg[] ptgs = parseFormula(formula);
+        assertEquals(expectedClasses.length, ptgs.length);
+        for (int i = 0; i < expectedClasses.length; i++) {
+            if(expectedClasses[i] != ptgs[i].getClass()) {
+                fail("difference at token[" + i + "]: expected ("
+                    + expectedClasses[i].getName() + ") but got (" 
+                    + ptgs[i].getClass().getName() + ")");
+            }
+        }
+    }
+
+    public void testPower() {
+        confirmTokenClasses("2^5", new Class[] { IntPtg.class, IntPtg.class, PowerPtg.class, });
+    }
+
+    private static Ptg parseSingleToken(String formula, Class ptgClass) {
+        Ptg[] ptgs = parseFormula(formula);
+        assertEquals(1, ptgs.length);
+        Ptg result = ptgs[0];
+        assertEquals(ptgClass, result.getClass());
+        return result;
+    }
+
+    public void testParseNumber() {
+        IntPtg ip;
+        
+        // bug 33160
+        ip = (IntPtg) parseSingleToken("40", IntPtg.class);
+        assertEquals(40, ip.getValue());
+        ip = (IntPtg) parseSingleToken("40000", IntPtg.class);
+        assertEquals(40000, ip.getValue());
+        
+        // check the upper edge of the IntPtg range:
+        ip = (IntPtg) parseSingleToken("65535", IntPtg.class);
+        assertEquals(65535, ip.getValue());
+        NumberPtg np = (NumberPtg) parseSingleToken("65536", NumberPtg.class);
+        assertEquals(65536, np.getValue(), 0);
+        
+        np = (NumberPtg) parseSingleToken("65534.6", NumberPtg.class);
+        assertEquals(65534.6, np.getValue(), 0);
+    }
+    
+    public void testMissingArgs() {
+        
+        Class[] expClss;
+        
+        expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class, 
+                FuncVarPtg.class, };
+        confirmTokenClasses("if(A1, ,C1)", expClss);
+        
+        expClss = new Class[] { MissingArgPtg.class, AreaPtg.class, MissingArgPtg.class,
+                FuncVarPtg.class, };
+        confirmTokenClasses("counta( , A1:B2, )", expClss);
+    }
+
+    public void testParseErrorLiterals() {
+        
+        confirmParseErrorLiteral(ErrPtg.NULL_INTERSECTION, "#NULL!");
+        confirmParseErrorLiteral(ErrPtg.DIV_ZERO, "#DIV/0!");
+        confirmParseErrorLiteral(ErrPtg.VALUE_INVALID, "#VALUE!");
+        confirmParseErrorLiteral(ErrPtg.REF_INVALID, "#REF!");
+        confirmParseErrorLiteral(ErrPtg.NAME_INVALID, "#NAME?");
+        confirmParseErrorLiteral(ErrPtg.NUM_ERROR, "#NUM!");
+        confirmParseErrorLiteral(ErrPtg.N_A, "#N/A");
+    }
+
+    private static void confirmParseErrorLiteral(ErrPtg expectedToken, String formula) {
+        assertEquals(expectedToken, parseSingleToken(formula, ErrPtg.class));
+    }
+    
+    /**
+     * To aid readability the parameters have been encoded with single quotes instead of double
+     * quotes.  This method converts single quotes to double quotes before performing the parse
+     * and result check.
+     */
+    private static void confirmStringParse(String singleQuotedValue) {
+        // formula: internal quotes become double double, surround with double quotes
+        String formula = '"' + singleQuotedValue.replaceAll("'", "\"\"") + '"';
+        String expectedValue = singleQuotedValue.replace('\'', '"');
+        
+        StringPtg sp = (StringPtg) parseSingleToken(formula, StringPtg.class);
+        assertEquals(expectedValue, sp.getValue());
+    }
+    
+    public void testPaseStringLiterals() {
+        confirmStringParse("goto considered harmful");
+        
+        confirmStringParse("goto 'considered' harmful");
+        
+        confirmStringParse("");
+        confirmStringParse("'");
+        confirmStringParse("''");
+        confirmStringParse("' '");
+        confirmStringParse(" ' ");
+    }
+    
+    public void testParseSumIfSum() {
+        String formulaString;
+        Ptg[] ptgs;
+        ptgs = parseFormula("sum(5, 2, if(3>2, sum(A1:A2), 6))");
+        formulaString = FormulaParser.toFormulaString(null, ptgs);
+        assertEquals("SUM(5,2,IF(3>2,SUM(A1:A2),6))", formulaString);
+
+        ptgs = parseFormula("if(1<2,sum(5, 2, if(3>2, sum(A1:A2), 6)),4)");
+        formulaString = FormulaParser.toFormulaString(null, ptgs);
+        assertEquals("IF(1<2,SUM(5,2,IF(3>2,SUM(A1:A2),6)),4)", formulaString);
+    }
+    public void testParserErrors() {
+        parseExpectedException("1 2");
+        parseExpectedException(" 12 . 345  ");
+        parseExpectedException("1 .23  ");
+
+        parseExpectedException("sum(#NAME)");
+        parseExpectedException("1 + #N / A * 2");
+        parseExpectedException("#value?");
+        parseExpectedException("#DIV/ 0+2");
+        
+        
+        if (false) { // TODO - add functionality to detect func arg count mismatch
+            parseExpectedException("IF(TRUE)");
+            parseExpectedException("countif(A1:B5, C1, D1)");
+        }
+    }
+    
+    private static void parseExpectedException(String formula) {
+        try {
+            parseFormula(formula);
+            throw new AssertionFailedError("expected parse exception");
+        } catch (RuntimeException e) {
+            // TODO - catch more specific exception
+            // expected during successful test
+            return;
+        }
     }
 }

Added: poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,104 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+        
+
+package org.apache.poi.hssf.record;
+
+import org.apache.poi.hssf.record.formula.AllFormulaTests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Collects all tests for package <tt>org.apache.poi.hssf.record</tt>.
+ * 
+ * @author Josh Micich
+ */
+public class AllRecordTests {
+	
+	public static Test suite() {
+		TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.record");
+
+		result.addTest(AllFormulaTests.suite());
+		
+		result.addTestSuite(TestAreaFormatRecord.class);
+		result.addTestSuite(TestAreaRecord.class);
+		result.addTestSuite(TestAxisLineFormatRecord.class);
+		result.addTestSuite(TestAxisOptionsRecord.class);
+		result.addTestSuite(TestAxisParentRecord.class);
+		result.addTestSuite(TestAxisRecord.class);
+		result.addTestSuite(TestAxisUsedRecord.class);
+		result.addTestSuite(TestBOFRecord.class);
+		result.addTestSuite(TestBarRecord.class);
+		result.addTestSuite(TestBoundSheetRecord.class);
+		result.addTestSuite(TestCategorySeriesAxisRecord.class);
+		result.addTestSuite(TestChartRecord.class);
+		result.addTestSuite(TestChartTitleFormatRecord.class);
+		result.addTestSuite(TestCommonObjectDataSubRecord.class);
+		result.addTestSuite(TestDatRecord.class);
+		result.addTestSuite(TestDataFormatRecord.class);
+		result.addTestSuite(TestDefaultDataLabelTextPropertiesRecord.class);
+		result.addTestSuite(TestDrawingGroupRecord.class);
+		result.addTestSuite(TestEmbeddedObjectRefSubRecord.class);
+		result.addTestSuite(TestEndSubRecord.class);
+		result.addTestSuite(TestEscherAggregate.class);
+		result.addTestSuite(TestFontBasisRecord.class);
+		result.addTestSuite(TestFontIndexRecord.class);
+		result.addTestSuite(TestFormulaRecord.class);
+		result.addTestSuite(TestFrameRecord.class);
+		result.addTestSuite(TestHyperlinkRecord.class);
+		result.addTestSuite(TestLegendRecord.class);
+		result.addTestSuite(TestLineFormatRecord.class);
+		result.addTestSuite(TestLinkedDataRecord.class);
+		result.addTestSuite(TestMergeCellsRecord.class);
+		result.addTestSuite(TestNameRecord.class);
+		result.addTestSuite(TestNoteRecord.class);
+		result.addTestSuite(TestNoteStructureSubRecord.class);
+		result.addTestSuite(TestNumberFormatIndexRecord.class);
+		result.addTestSuite(TestObjRecord.class);
+		result.addTestSuite(TestObjectLinkRecord.class);
+		result.addTestSuite(TestPaletteRecord.class);
+		result.addTestSuite(TestPaneRecord.class);
+		result.addTestSuite(TestPlotAreaRecord.class);
+		result.addTestSuite(TestPlotGrowthRecord.class);
+		result.addTestSuite(TestRecordFactory.class);
+		result.addTestSuite(TestSCLRecord.class);
+		result.addTestSuite(TestSSTDeserializer.class);
+		result.addTestSuite(TestSSTRecord.class);
+		result.addTestSuite(TestSSTRecordSizeCalculator.class);
+		result.addTestSuite(TestSeriesChartGroupIndexRecord.class);
+		result.addTestSuite(TestSeriesIndexRecord.class);
+		result.addTestSuite(TestSeriesLabelsRecord.class);
+		result.addTestSuite(TestSeriesListRecord.class);
+		result.addTestSuite(TestSeriesRecord.class);
+		result.addTestSuite(TestSeriesTextRecord.class);
+		result.addTestSuite(TestSeriesToChartGroupRecord.class);
+		result.addTestSuite(TestSheetPropertiesRecord.class);
+		result.addTestSuite(TestStringRecord.class);
+		result.addTestSuite(TestSubRecord.class);
+		result.addTestSuite(TestSupBookRecord.class);
+		result.addTestSuite(TestTextObjectBaseRecord.class);
+		result.addTestSuite(TestTextObjectRecord.class);
+		result.addTestSuite(TestTextRecord.class);
+		result.addTestSuite(TestTickRecord.class);
+		result.addTestSuite(TestUnicodeNameRecord.class);
+		result.addTestSuite(TestUnicodeString.class);
+		result.addTestSuite(TestUnitsRecord.class);
+		result.addTestSuite(TestValueRangeRecord.class);
+		return result;
+	}
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java Tue Mar  4 08:53:32 2008
@@ -29,15 +29,25 @@
  *
  * @author Andrew C. Oliver (acoliver at apache dot org)
  */
-public class TestSupBookRecord
-        extends TestCase
-{
+public final class TestSupBookRecord extends TestCase {
     /**
      * This contains a fake data section of a SubBookRecord
      */
-    byte[] data = new byte[] {
-        (byte)0x04,(byte)0x00,(byte)0x01,(byte)0x04
+    byte[] dataIR = new byte[] {
+        (byte)0x04,(byte)0x00,(byte)0x01,(byte)0x04,
     };
+    byte[] dataAIF = new byte[] {
+        (byte)0x01,(byte)0x00,(byte)0x01,(byte)0x3A,
+    };
+    byte[] dataER = new byte[] {
+        (byte)0x02,(byte)0x00,
+        (byte)0x07,(byte)0x00,   (byte)0x00,   
+                (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)'U', (byte)'R', (byte)'L',  
+        (byte)0x06,(byte)0x00,   (byte)0x00,   
+                (byte)'S', (byte)'h', (byte)'e', (byte)'e', (byte)'t', (byte)'1', 
+        (byte)0x06,(byte)0x00,   (byte)0x00,   
+                (byte)'S', (byte)'h', (byte)'e', (byte)'e', (byte)'t', (byte)'2', 
+   };
 
     public TestSupBookRecord(String name)
     {
@@ -47,36 +57,67 @@
     /**
      * tests that we can load the record
      */
-    public void testLoad()
-            throws Exception
-    {
+    public void testLoadIR() {
 
-        SupBookRecord record = new SupBookRecord(new TestcaseRecordInputStream((short)0x01AE, (short)data.length, data));      
-        assertEquals( 0x401, record.getFlag());             //expected flag
+        SupBookRecord record = new SupBookRecord(new TestcaseRecordInputStream((short)0x01AE, dataIR));      
+        assertTrue( record.isInternalReferences() );             //expected flag
         assertEquals( 0x4, record.getNumberOfSheets() );    //expected # of sheets
 
         assertEquals( 8, record.getRecordSize() );  //sid+size+data
 
         record.validateSid((short)0x01AE);
     }
-    
+    /**
+     * tests that we can load the record
+     */
+    public void testLoadER() {
+
+        SupBookRecord record = new SupBookRecord(new TestcaseRecordInputStream((short)0x01AE, dataER));      
+        assertTrue( record.isExternalReferences() );             //expected flag
+        assertEquals( 0x2, record.getNumberOfSheets() );    //expected # of sheets
+
+        assertEquals( 34, record.getRecordSize() );  //sid+size+data
+        
+        assertEquals("testURL", record.getURL().getString());
+        UnicodeString[] sheetNames = record.getSheetNames();
+        assertEquals(2, sheetNames.length);
+        assertEquals("Sheet1", sheetNames[0].getString());
+        assertEquals("Sheet2", sheetNames[1].getString());
+
+        record.validateSid((short)0x01AE);
+    }
     
     /**
+     * tests that we can load the record
+     */
+    public void testLoadAIF() {
+
+        SupBookRecord record = new SupBookRecord(new TestcaseRecordInputStream((short)0x01AE, dataAIF));      
+        assertTrue( record.isAddInFunctions() );             //expected flag
+        assertEquals( 0x1, record.getNumberOfSheets() );    //expected # of sheets
+        assertEquals( 8, record.getRecordSize() );  //sid+size+data
+        record.validateSid((short)0x01AE);
+    }
+   
+    /**
      * Tests that we can store the record
      *
      */
-    public void testStore()
-    {
-        SupBookRecord record = new SupBookRecord();
-        record.setFlag( (short) 0x401 );
-        record.setNumberOfSheets( (short)0x4 );
-        
+    public void testStoreIR() {
+        SupBookRecord record = SupBookRecord.createInternalReferences((short)4);
 
+        TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataIR, record.serialize());
+    }   
+    
+    public void testStoreER() {
+        UnicodeString url = new UnicodeString("testURL");
+        UnicodeString[] sheetNames = {
+                new UnicodeString("Sheet1"),
+                new UnicodeString("Sheet2"),
+        };
+        SupBookRecord record = SupBookRecord.createExternalReferences(url, sheetNames);
 
-        byte [] recordBytes = record.serialize();
-        assertEquals(recordBytes.length - 4, data.length);
-        for (int i = 0; i < data.length; i++)
-            assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+        TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataER, record.serialize());
     }    
     
     public static void main(String [] args) {
@@ -84,6 +125,4 @@
         .println("Testing org.apache.poi.hssf.record.SupBookRecord");
         junit.textui.TestRunner.run(TestSupBookRecord.class);
     }
-    
-
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java Tue Mar  4 08:53:32 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
@@ -16,11 +15,12 @@
    limitations under the License.
 ==================================================================== */
 
-
-
 package org.apache.poi.hssf.record;
 
 import java.io.ByteArrayInputStream;
+
+import junit.framework.Assert;
+
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -33,6 +33,14 @@
 public class TestcaseRecordInputStream
         extends RecordInputStream
 {
+    /**
+     * Convenience constructor
+     */
+    public TestcaseRecordInputStream(int sid, byte[] data)
+    {
+      super(new ByteArrayInputStream(mergeDataAndSid((short)sid, (short)data.length, data)));
+      nextRecord();
+    }
     public TestcaseRecordInputStream(short sid, short length, byte[] data)
     {
       super(new ByteArrayInputStream(mergeDataAndSid(sid, length, data)));
@@ -45,5 +53,19 @@
       LittleEndian.putShort(result, 2, length);
       System.arraycopy(data, 0, result, 4, data.length);
       return result;
+    }
+    /**
+     * Confirms data sections are equal
+     * @param expectedData - just raw data (without sid or size short ints)
+     * @param actualRecordBytes this includes 4 prefix bytes (sid & size)
+     */
+    public static void confirmRecordEncoding(int expectedSid, byte[] expectedData, byte[] actualRecordBytes) {
+        int expectedDataSize = expectedData.length;
+        Assert.assertEquals(actualRecordBytes.length - 4, expectedDataSize);
+        Assert.assertEquals(expectedSid, LittleEndian.getShort(actualRecordBytes, 0));
+        Assert.assertEquals(expectedDataSize, LittleEndian.getShort(actualRecordBytes, 2));
+        for (int i = 0; i < expectedDataSize; i++)
+            Assert.assertEquals("At offset " + i, expectedData[i], actualRecordBytes[i+4]);
+        
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java Tue Mar  4 08:53:32 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
@@ -28,6 +27,7 @@
 
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
 /**
  * Convenient abstract class to reduce the amount of boilerplate code needed
@@ -35,8 +35,7 @@
  *
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
-public abstract class AbstractPtgTestCase extends TestCase
-{
+public abstract class AbstractPtgTestCase extends TestCase {
     /** Directory containing the test data. */
     private static String dataDir = System.getProperty("HSSF.testdata.path");
 
@@ -51,16 +50,16 @@
             throws IOException {
         File file = new File(dataDir, filename);
         InputStream stream = new BufferedInputStream(new FileInputStream(file));
-        try
-        {
-            return new HSSFWorkbook(stream);
-        }
-        finally
-        {
+        // TODO - temp workaround to keep stdout quiet due to warning msg in POIFS 
+        // When that warning msg is disabled, remove this wrapper and the close() call, 
+        InputStream wrappedStream = POIFSFileSystem.createNonClosingInputStream(stream);
+        try {
+            return new HSSFWorkbook(wrappedStream);
+        } finally {
             stream.close();
         }
     }
-    
+
     /**
      * Creates a new Workbook and adds one sheet with the specified name
      */
@@ -73,5 +72,4 @@
 		book.setSheetName(0, sheetName); 
 		return book;
 	}
-    
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java Tue Mar  4 08:53:32 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;
 
@@ -33,7 +32,8 @@
 		result.addTestSuite(TestArea3DPtg.class);
 		result.addTestSuite(TestAreaErrPtg.class);
         result.addTestSuite(TestAreaPtg.class);
-		result.addTestSuite(TestErrPtg.class);
+        result.addTestSuite(TestErrPtg.class);
+        result.addTestSuite(TestExternalFunctionFormulas.class);
 		result.addTestSuite(TestFuncPtg.class);
 		result.addTestSuite(TestIntersectionPtg.class);
 		result.addTestSuite(TestPercentPtg.class);

Added: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,56 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+/**
+ * Tests for functions from external workbooks (e.g. YEARFRAC).
+ * 
+ * 
+ * @author Josh Micich
+ */
+public final class TestExternalFunctionFormulas extends TestCase {
+
+    
+    /**
+     * tests <tt>NameXPtg.toFormulaString(Workbook)</tt> and logic in Workbook below that   
+     */
+    public void testReadFormulaContainingExternalFunction() {
+        String filePath = System.getProperty("HSSF.testdata.path")+ "/" 
+        + "externalFunctionExample.xls";
+        HSSFWorkbook wb;
+        try {
+            FileInputStream fin = new FileInputStream(filePath);
+            wb = new HSSFWorkbook( fin );
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        
+        String expectedFormula = "YEARFRAC(B1,C1)";
+        HSSFSheet sht = wb.getSheetAt(0);
+        String cellFormula = sht.getRow(0).getCell((short)0).getCellFormula();
+        assertEquals(expectedFormula, cellFormula);
+    }
+    
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java?rev=633547&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java Tue Mar  4 08:53:32 2008
@@ -0,0 +1,71 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+       
+package org.apache.poi.hssf.usermodel;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Collects all tests for the <tt>org.apache.poi.hssf.usermodel</tt> package.
+ * 
+ * @author Josh Micich
+ */
+public class AllUserModelTests {
+	
+	public static Test suite() {
+		TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.usermodel");
+		
+		result.addTestSuite(TestBugs.class);
+		result.addTestSuite(TestCellStyle.class);
+		result.addTestSuite(TestCloneSheet.class);
+		result.addTestSuite(TestDataValidation.class);
+		result.addTestSuite(TestEscherGraphics.class);
+		result.addTestSuite(TestEscherGraphics2d.class);
+		result.addTestSuite(TestFontDetails.class);
+		result.addTestSuite(TestFormulas.class);
+		result.addTestSuite(TestHSSFCell.class);
+		result.addTestSuite(TestHSSFClientAnchor.class);
+		result.addTestSuite(TestHSSFComment.class);
+		result.addTestSuite(TestHSSFDateUtil.class);
+		result.addTestSuite(TestHSSFHeaderFooter.class);
+		result.addTestSuite(TestHSSFHyperlink.class);
+		result.addTestSuite(TestHSSFPalette.class);
+		result.addTestSuite(TestHSSFPicture.class);
+		result.addTestSuite(TestHSSFPictureData.class);
+		result.addTestSuite(TestHSSFRichTextString.class);
+		result.addTestSuite(TestHSSFRow.class);
+		result.addTestSuite(TestHSSFSheet.class);
+		result.addTestSuite(TestHSSFSheetOrder.class);
+		result.addTestSuite(TestHSSFSheetSetOrder.class);
+		result.addTestSuite(TestHSSFWorkbook.class);
+		result.addTestSuite(TestNamedRange.class);
+		result.addTestSuite(TestOLE2Embeding.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(TestUppercaseWorkbook.class);
+		result.addTestSuite(TestWorkbook.class);		
+		
+		return result;
+	}
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java?rev=633547&r1=633546&r2=633547&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java Tue Mar  4 08:53:32 2008
@@ -16,25 +16,28 @@
 */
 package org.apache.poi.hssf.usermodel;
 
-import junit.framework.TestCase;
-
-import java.io.IOException;
-import java.io.FileInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
 
 /**
  * Test <code>HSSFPicture</code>.
  *
  * @author Yegor Kozlov (yegor at apache.org)
  */
-public class TestHSSFPicture extends TestCase{
+public final class TestHSSFPicture extends TestCase{
 
-    public void testResize() throws Exception {
+    public void testResize() {
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sh1 = wb.createSheet();
         HSSFPatriarch p1 = sh1.createDrawingPatriarch();
 
-        int idx1 = loadPicture( "src/resources/logos/logoKarmokar4.png", wb);
+        byte[] pictureData = getTestDataFileContent("logoKarmokar4.png");
+        int idx1 = wb.addPicture( pictureData, HSSFWorkbook.PICTURE_TYPE_PNG );
         HSSFPicture picture1 = p1.createPicture(new HSSFClientAnchor(), idx1);
         HSSFClientAnchor anchor1 = picture1.getPreferredSize();
 
@@ -52,28 +55,25 @@
     /**
      * Copied from org.apache.poi.hssf.usermodel.examples.OfficeDrawing
      */
-    private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException
-    {
-        int pictureIndex;
-        FileInputStream fis = null;
-        ByteArrayOutputStream bos = null;
-        try
-        {
-            fis = new FileInputStream( path);
-            bos = new ByteArrayOutputStream( );
-            int c;
-            while ( (c = fis.read()) != -1)
-                bos.write( c );
-            pictureIndex = wb.addPicture( bos.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG );
-        }
-        finally
-        {
-            if (fis != null)
-                fis.close();
-            if (bos != null)
-                bos.close();
-        }
-        return pictureIndex;
-    }
+     private static byte[] getTestDataFileContent(String fileName) {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
 
+        String readFilename = System.getProperty("HSSF.testdata.path");
+        try {
+            InputStream fis = new FileInputStream(readFilename+File.separator+fileName);
+
+            byte[] buf = new byte[512];
+            while(true) {
+                int bytesRead = fis.read(buf);
+                if(bytesRead < 1) {
+                    break;
+                }
+                bos.write(buf, 0, bytesRead);
+            }
+            fis.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return bos.toByteArray();
+     }
 }



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