]> source.dussan.org Git - poi.git/commitdiff
Add a unit test for the formula evaluation caching/updating, which ensures that HSSF...
authorNick Burch <nick@apache.org>
Sun, 1 May 2011 08:00:56 +0000 (08:00 +0000)
committerNick Burch <nick@apache.org>
Sun, 1 May 2011 08:00:56 +0000 (08:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1098227 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java

index 1cc964f037c385bae902f314e96661af7914c34d..f8d71f94c50d6fa0b65233ca4d85a3c8e01e6f36 100644 (file)
@@ -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);