aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-03-30 20:46:51 +0000
committerJosh Micich <josh@apache.org>2009-03-30 20:46:51 +0000
commitd92e7179bf59e146d7aef4e1621d72aeb0fd4556 (patch)
treecd52493103327bd36f89ba9f375d5068b346faa7 /src/testcases/org
parente47dd63c80d7807381f77ee0d8879332737368cf (diff)
downloadpoi-d92e7179bf59e146d7aef4e1621d72aeb0fd4556.tar.gz
poi-d92e7179bf59e146d7aef4e1621d72aeb0fd4556.zip
Fix for bug 46898 - Formula evaluator should not cache intermediate circular-reference error results
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@760162 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
index 669bb4b1b9..fb11b4c1b6 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
@@ -25,7 +25,9 @@ import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.ErrorConstants;
/**
* Tests HSSFFormulaEvaluator for its handling of cell formula circular references.
*
@@ -118,4 +120,51 @@ public final class TestCircularReferences extends TestCase {
confirmCycleErrorCode(cellValue);
}
+
+ public void testIntermediateCircularReferenceResults_bug46898() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+
+ HSSFRow row = sheet.createRow(0);
+
+ HSSFCell cellA1 = row.createCell(0);
+ HSSFCell cellB1 = row.createCell(1);
+ HSSFCell cellC1 = row.createCell(2);
+ HSSFCell cellD1 = row.createCell(3);
+ HSSFCell cellE1 = row.createCell(4);
+
+ cellA1.setCellFormula("IF(FALSE, 1+B1, 42)");
+ cellB1.setCellFormula("1+C1");
+ cellC1.setCellFormula("1+D1");
+ cellD1.setCellFormula("1+E1");
+ cellE1.setCellFormula("1+A1");
+
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ CellValue cv;
+
+ // Happy day flow - evaluate A1 first
+ cv = fe.evaluate(cellA1);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(42.0, cv.getNumberValue(), 0.0);
+ cv = fe.evaluate(cellB1); // no circ-ref-error because A1 result is cached
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(46.0, cv.getNumberValue(), 0.0);
+
+ // Show the bug - evaluate another cell from the loop first
+ fe.clearAllCachedResultValues();
+ cv = fe.evaluate(cellB1);
+ if (cv.getCellType() == ErrorEval.CIRCULAR_REF_ERROR.getErrorCode()) {
+ throw new AssertionFailedError("Identified bug 46898");
+ }
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(46.0, cv.getNumberValue(), 0.0);
+
+ // start evaluation on another cell
+ fe.clearAllCachedResultValues();
+ cv = fe.evaluate(cellE1);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cv.getCellType());
+ assertEquals(43.0, cv.getNumberValue(), 0.0);
+
+
+ }
}