aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-03-11 18:24:32 +0000
committerDominik Stadler <centic@apache.org>2015-03-11 18:24:32 +0000
commit0ec21978fccc60a447379459188157757de2dce2 (patch)
tree0a033bc9ae075f4a99c2283f1d5f9375ea89154d /src/ooxml
parent336e16ba35ee2e336bc2f33655bdff33cebd9453 (diff)
downloadpoi-0ec21978fccc60a447379459188157757de2dce2.tar.gz
poi-0ec21978fccc60a447379459188157757de2dce2.zip
Add testcase which verifies that bug 56820 was solved by some other fix already
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1665957 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
index 6eaa3f14d1..ae43d81498 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
@@ -2186,4 +2186,80 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
wb.removeSheetAt(sn);
}
}
+
+ /**
+ * Sums 2 plus the cell at the left, indirectly to avoid reference
+ * problems when deleting columns, conditionally to stop recursion
+ */
+ private static final String FORMULA1 =
+ "IF( INDIRECT( ADDRESS( ROW(), COLUMN()-1 ) ) = 0, 0,"
+ + "INDIRECT( ADDRESS( ROW(), COLUMN()-1 ) ) ) + 2";
+
+ /**
+ * Sums 2 plus the upper cell, indirectly to avoid reference
+ * problems when deleting rows, conditionally to stop recursion
+ */
+ private static final String FORMULA2 =
+ "IF( INDIRECT( ADDRESS( ROW()-1, COLUMN() ) ) = 0, 0,"
+ + "INDIRECT( ADDRESS( ROW()-1, COLUMN() ) ) ) + 2";
+
+ /**
+ * Expected:
+
+ * [ 0][ 2][ 4]
+ * @throws IOException
+ */
+ @Test
+ public void testBug56820_Formula1() throws IOException {
+ Workbook wb = new XSSFWorkbook();
+ try {
+ FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+ Sheet sh = wb.createSheet();
+
+ sh.createRow(0).createCell(0).setCellValue(0.0d);
+ Cell formulaCell1 = sh.getRow(0).createCell(1);
+ Cell formulaCell2 = sh.getRow(0).createCell(2);
+ formulaCell1.setCellFormula(FORMULA1);
+ formulaCell2.setCellFormula(FORMULA1);
+
+ double A1 = evaluator.evaluate(formulaCell1).getNumberValue();
+ double A2 = evaluator.evaluate(formulaCell2).getNumberValue();
+
+ assertEquals(2, A1, 0);
+ assertEquals(4, A2, 0); //<-- FAILS EXPECTATIONS
+ } finally {
+ wb.close();
+ }
+ }
+
+ /**
+ * Expected:
+
+ * [ 0] <- number
+ * [ 2] <- formula
+ * [ 4] <- formula
+ * @throws IOException
+ */
+ @Test
+ public void testBug56820_Formula2() throws IOException {
+ Workbook wb = new XSSFWorkbook();
+ try {
+ FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+ Sheet sh = wb.createSheet();
+
+ sh.createRow(0).createCell(0).setCellValue(0.0d);
+ Cell formulaCell1 = sh.createRow(1).createCell(0);
+ Cell formulaCell2 = sh.createRow(2).createCell(0);
+ formulaCell1.setCellFormula(FORMULA2);
+ formulaCell2.setCellFormula(FORMULA2);
+
+ double A1 = evaluator.evaluate(formulaCell1).getNumberValue();
+ double A2 = evaluator.evaluate(formulaCell2).getNumberValue(); //<-- FAILS EVALUATION
+
+ assertEquals(2, A1, 0);
+ assertEquals(4, A2, 0);
+ } finally {
+ wb.close();
+ }
+ }
}