You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/03/11 19:24:32 UTC

svn commit: r1665957 - /poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Author: centic
Date: Wed Mar 11 18:24:32 2015
New Revision: 1665957

URL: http://svn.apache.org/r1665957
Log:
Add testcase which verifies that bug 56820 was solved by some other fix already

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1665957&r1=1665956&r2=1665957&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Wed Mar 11 18:24:32 2015
@@ -2186,4 +2186,80 @@ public final class TestXSSFBugs extends
             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();
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org