]> source.dussan.org Git - poi.git/commitdiff
Add reproducer for bug 56655
authorDominik Stadler <centic@apache.org>
Wed, 7 Jan 2015 14:34:13 +0000 (14:34 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 7 Jan 2015 14:34:13 +0000 (14:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1650069 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java

index cb29db710e316e7ce62dfffe836309fafd91b788..c90ba80614b5b2b226dcbeeeed57211adc83afe5 100644 (file)
@@ -17,6 +17,8 @@
 \r
 package org.apache.poi.xssf.usermodel;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+\r
 import java.io.IOException;\r
 import java.nio.charset.Charset;\r
 import java.util.Calendar;\r
@@ -29,6 +31,7 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.ss.usermodel.Cell;\r
 import org.apache.poi.ss.usermodel.DataFormatter;\r
 import org.apache.poi.ss.usermodel.DateUtil;\r
+import org.apache.poi.ss.usermodel.FormulaError;\r
 import org.apache.poi.ss.usermodel.RichTextString;\r
 import org.apache.poi.ss.usermodel.Row;\r
 import org.apache.poi.ss.usermodel.Sheet;\r
@@ -240,4 +243,66 @@ public final class TestUnfixedBugs extends TestCase {
         assertEquals(2, strBack.getIndexOfFormattingRun(1));\r
         assertEquals(4, strBack.getIndexOfFormattingRun(2));\r
     }\r
+\r
+    @Test\r
+    public void testBug56655() {\r
+        XSSFWorkbook wb =  new XSSFWorkbook();\r
+        Sheet sheet = wb.createSheet();\r
+        \r
+        setCellFormula(sheet, 0, 0, "#VALUE!");\r
+        setCellFormula(sheet, 0, 1, "SUMIFS(A:A,A:A,#VALUE!)");\r
+\r
+        XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);\r
+\r
+        assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0,0).getCachedFormulaResultType());\r
+        assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,0).getErrorCellValue());\r
+        assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0,1).getCachedFormulaResultType());\r
+        assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,1).getErrorCellValue());\r
+    }\r
+\r
+    @Test\r
+    public void testBug56655a() {\r
+        XSSFWorkbook wb =  new XSSFWorkbook();\r
+        Sheet sheet = wb.createSheet();\r
+        \r
+        setCellFormula(sheet, 0, 0, "B1*C1");\r
+        sheet.getRow(0).createCell(1).setCellValue("A");\r
+        setCellFormula(sheet, 1, 0, "B1*C1");\r
+        sheet.getRow(1).createCell(1).setCellValue("A");\r
+        setCellFormula(sheet, 0, 3, "SUMIFS(A:A,A:A,A2)");\r
+\r
+        XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);\r
+\r
+        assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0, 0).getCachedFormulaResultType());\r
+        assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 0).getErrorCellValue());\r
+        assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 1, 0).getCachedFormulaResultType());\r
+        assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 1, 0).getErrorCellValue());\r
+        assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0, 3).getCachedFormulaResultType());\r
+        assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 3).getErrorCellValue());\r
+    }\r
+\r
+    /**\r
+    * @param row 0-based\r
+    * @param column 0-based\r
+    */\r
+   void setCellFormula(Sheet sheet, int row, int column, String formula) {\r
+       Row r = sheet.getRow(row);\r
+       if (r == null) {\r
+           r = sheet.createRow(row);\r
+       }\r
+       Cell cell = r.getCell(column);\r
+       if (cell == null) {\r
+           cell = r.createCell(column);\r
+       }\r
+       cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);\r
+       cell.setCellFormula(formula);\r
+   }\r
+\r
+   /**\r
+    * @param rowNo 0-based\r
+    * @param column 0-based\r
+    */\r
+   Cell getCell(Sheet sheet, int rowNo, int column) {\r
+       return sheet.getRow(rowNo).getCell(column);\r
+   }\r
 }\r