From: Nick Burch Date: Sun, 1 May 2011 08:00:56 +0000 (+0000) Subject: Add a unit test for the formula evaluation caching/updating, which ensures that HSSF... X-Git-Tag: REL_3_8_BETA3~51 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=692bab9b9ee10e507e930f92b440351bf7c409bc;p=poi.git Add a unit test for the formula evaluation caching/updating, which ensures that HSSF and XSSF behave the same git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1098227 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java index 1cc964f037..f8d71f94c5 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java @@ -193,6 +193,44 @@ public abstract class BaseTestFormulaEvaluator extends TestCase { 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);