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
This commit is contained in:
Nick Burch 2011-05-01 08:00:56 +00:00
parent 8e0241ff83
commit 692bab9b9e
1 changed files with 38 additions and 0 deletions

View File

@ -194,6 +194,44 @@ public abstract class BaseTestFormulaEvaluator extends TestCase {
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);
if (row == null) {