Add reproducer for bug 56655

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1650069 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-01-07 14:34:13 +00:00
parent 3f6f9da0ce
commit 0179875251
1 changed files with 65 additions and 0 deletions

View File

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