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 2011/05/01 10:00:56 UTC
svn commit: r1098227 -
/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
Author: nick
Date: Sun May 1 08:00:56 2011
New Revision: 1098227
URL: http://svn.apache.org/viewvc?rev=1098227&view=rev
Log:
Add a unit test for the formula evaluation caching/updating, which ensures that HSSF and XSSF behave the same
Modified:
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java?rev=1098227&r1=1098226&r2=1098227&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java Sun May 1 08:00:56 2011
@@ -193,6 +193,44 @@ public abstract class BaseTestFormulaEva
assertEquals(26.0, fe.evaluate(cell0).getNumberValue(), 0.0);
assertEquals(56.0, fe.evaluate(cell1).getNumberValue(), 0.0);
}
+
+ public void testRepeatedEvaluation() {
+ Workbook wb = _testDataProvider.createWorkbook();
+ FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
+ Sheet sheet = wb.createSheet("Sheet1");
+ Row r = sheet.createRow(0);
+ Cell c = r.createCell(0, Cell.CELL_TYPE_FORMULA);
+
+ // Create a value and check it
+ c.setCellFormula("Date(2011,10,6)");
+ CellValue cellValue = fe.evaluate(c);
+ assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
+ cellValue = fe.evaluate(c);
+ assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
+
+ // Change it
+ c.setCellFormula("Date(2011,10,4)");
+
+ // Evaluate it, no change as the formula evaluator
+ // won't know to clear the cache
+ cellValue = fe.evaluate(c);
+ assertEquals(40822.0, cellValue.getNumberValue(), 0.0);
+
+ // Manually flush for this cell, and check
+ fe.notifySetFormula(c);
+ cellValue = fe.evaluate(c);
+ assertEquals(40820.0, cellValue.getNumberValue(), 0.0);
+
+ // Change again, without notifying
+ c.setCellFormula("Date(2010,10,4)");
+ cellValue = fe.evaluate(c);
+ assertEquals(40820.0, cellValue.getNumberValue(), 0.0);
+
+ // Now manually clear all, will see the new value
+ fe.clearAllCachedResultValues();
+ cellValue = fe.evaluate(c);
+ assertEquals(40455.0, cellValue.getNumberValue(), 0.0);
+ }
private static void setValue(Sheet sheet, int rowIndex, int colIndex, double value) {
Row row = sheet.getRow(rowIndex);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org