poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r643625 - in /poi/trunk/src: resources/main/org/apache/poi/hssf/record/formula/function/ testcases/org/apache/poi/hssf/data/ testcases/org/apache/poi/hssf/record/formula/ testcases/org/apache/poi/hssf/record/formula/function/
Date Tue, 01 Apr 2008 22:18:32 GMT
Author: josh
Date: Tue Apr  1 15:18:25 2008
New Revision: 643625

URL: http://svn.apache.org/viewvc?rev=643625&view=rev
Log:
Bug #44733 - DPRODUCT function should be index 189, not 191

Modified:
    poi/trunk/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt
    poi/trunk/src/testcases/org/apache/poi/hssf/data/missingFuncs44675.xls
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java

Modified: poi/trunk/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt
URL: http://svn.apache.org/viewvc/poi/trunk/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt?rev=643625&r1=643624&r2=643625&view=diff
==============================================================================
--- poi/trunk/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt
(original)
+++ poi/trunk/src/resources/main/org/apache/poi/hssf/record/formula/function/functionMetadata.txt
Tue Apr  1 15:18:25 2008
@@ -143,8 +143,8 @@
 169	COUNTA	0	30	V	R		
 183	PRODUCT	0	30	V	R		
 184	FACT	1	1	V	V		
+189	DPRODUCT	3	3	V	R R R		
 190	ISNONTEXT	1	1	V	V		
-191	DPRODUCT	3	3	V	R R R		
 193	STDEVP	1	30	V	R		
 194	VARP	1	30	V	R		
 195	DSTDEVP	3	3	V	R R R		

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

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=643625&r1=643624&r2=643625&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 Apr
 1 15:18:25 2008
@@ -29,7 +29,7 @@
  * 
  * @author Josh Micich
  */
-public class AllFormulaTests {
+public final class AllFormulaTests {
 	
 	public static Test suite() {
 		TestSuite result = new TestSuite(AllFormulaTests.class.getName());
@@ -50,7 +50,6 @@
 		result.addTestSuite(TestReferencePtg.class);
 		result.addTestSuite(TestSheetNameFormatter.class);
 		result.addTestSuite(TestUnionPtg.class);
-		result.addTest(AllFormulaFunctionTests.suite());
 		return result;
 	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java?rev=643625&r1=643624&r2=643625&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
Tue Apr  1 15:18:25 2008
@@ -27,6 +27,9 @@
 import org.apache.poi.hssf.record.formula.FuncVarPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
 /**
+ * Tests parsing of some built-in functions that were not properly
+ * registered in POI as bug #44675, #44733 (March/April 2008).
+ * 
  * @author Josh Micich
  */
 public final class TestParseMissingBuiltInFuncs extends TestCase {
@@ -39,6 +42,7 @@
 		Ptg[] ptgs = parse(formula);
 		Ptg ptgF = ptgs[ptgs.length-1];  // func is last RPN token in all these formulas
 		
+		// Check critical things in the Ptg array encoding.
 		if(!(ptgF instanceof AbstractFunctionPtg)) {
 		    throw new RuntimeException("function token missing");
 		}
@@ -47,11 +51,15 @@
 			throw new AssertionFailedError("Failed to recognise built-in function in formula '" 
 					+ formula + "'");
 		}
-		
 		assertEquals(expPtgArraySize, ptgs.length);
 		assertEquals(funcIx, func.getFunctionIndex());
 		Class expCls = isVarArgFunc ? FuncVarPtg.class : FuncPtg.class;
 		assertEquals(expCls, ptgF.getClass());
+		
+		// check that parsed Ptg array converts back to formula text OK
+		Workbook book = Workbook.createWorkbook();
+		String reRenderedFormula = FormulaParser.toFormulaString(book, ptgs);
+		assertEquals(formula, reRenderedFormula);
 	}
 	
 	public void testDatedif() {
@@ -75,5 +83,8 @@
 	}
 	public void testIsnontext() {
 		confirmFunc("ISNONTEXT(\"abc\")", 2, false, 190);
+	}
+	public void testDproduct() {
+		confirmFunc("DPRODUCT(C1:E5,\"HarvestYield\",G1:H2)", 4, false, 189);
 	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java?rev=643625&r1=643624&r2=643625&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
Tue Apr  1 15:18:25 2008
@@ -21,7 +21,9 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
 
+import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
@@ -29,24 +31,31 @@
 import junit.framework.TestCase;
 /**
  * Tests reading from a sample spreadsheet some built-in functions that were not properly
- * registered in POI as bug #44675 (March 2008).
+ * registered in POI as bug #44675, #44733 (March/April 2008).
  * 
  * @author Josh Micich
  */
 public final class TestReadMissingBuiltInFuncs extends TestCase {
 
-	private HSSFSheet sht;
-
-	protected void setUp() {
-		String cwd = System.getProperty("HSSF.testdata.path");
-		HSSFWorkbook wb;
-		try {
-			InputStream is = new FileInputStream(new File(cwd, "missingFuncs44675.xls"));
-			wb = new HSSFWorkbook(is);
-		} catch (IOException e) {
-			throw new RuntimeException(e);
+	/**
+	 * This spreadsheet has examples of calls to the interesting built-in functions in cells
A1:A7
+	 */
+	private static final String SAMPLE_SPREADSHEET_FILE_NAME = "missingFuncs44675.xls";
+	private static HSSFSheet _sheet;
+
+	private static HSSFSheet getSheet() {
+		if (_sheet == null) {
+			String cwd = System.getProperty("HSSF.testdata.path");
+			HSSFWorkbook wb;
+			try {
+				InputStream is = new FileInputStream(new File(cwd, SAMPLE_SPREADSHEET_FILE_NAME));
+				wb = new HSSFWorkbook(is);
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+			_sheet = wb.getSheetAt(0);
 		}
-		sht = wb.getSheetAt(0);
+		return _sheet;
 	}
 
 	public void testDatedif() {
@@ -128,9 +137,30 @@
 		}
 		assertEquals("ISNONTEXT(\"abc\")", formula);
 	}
+	public void testDproduct() {
+		
+		String formula = getCellFormula(6);
+		assertEquals("DPRODUCT(C1:E5,\"HarvestYield\",G1:H2)", formula);
+	}
 
 	private String getCellFormula(int rowIx) {
-		String result = sht.getRow(rowIx).getCell((short)0).getCellFormula();
+		HSSFSheet sheet;
+		try {
+			sheet = getSheet();
+		} catch (RecordFormatException e) {
+			if(e.getCause() instanceof InvocationTargetException) {
+				InvocationTargetException ite = (InvocationTargetException) e.getCause();
+				if(ite.getTargetException() instanceof RuntimeException) {
+					RuntimeException re = (RuntimeException) ite.getTargetException();
+					if(re.getMessage().equals("Invalid built-in function index (189)")) {
+						throw afe("DPRODUCT() registered with wrong index");
+					}
+				}
+			}
+			// some other unexpected error
+			throw e;
+		}
+		String result = sheet.getRow(rowIx).getCell((short)0).getCellFormula();
 		if (false) {
 			System.err.println(result);
 		}



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


Mime
View raw message