aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/testcases
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2020-03-29 08:16:17 +0000
committerDominik Stadler <centic@apache.org>2020-03-29 08:16:17 +0000
commitcc1b6557ee514aa2f9997b104c42a09aae3400e3 (patch)
tree644cde8d797a4e1a2bfde372bcba97d78a28d1ae /src/ooxml/testcases
parentf58aa530da8ec1871e445c706d7e915be68998a6 (diff)
downloadpoi-cc1b6557ee514aa2f9997b104c42a09aae3400e3.tar.gz
poi-cc1b6557ee514aa2f9997b104c42a09aae3400e3.zip
Bug 63845: Adjust handling of formula-cells to fix regression introduced in 4.1.0
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1875837 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases')
-rw-r--r--src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java10
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java48
2 files changed, 52 insertions, 6 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java b/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
index 28d2d48936..46d7d6319e 100644
--- a/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
+++ b/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
@@ -20,8 +20,6 @@ package org.apache.poi.ss.usermodel;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
-import java.util.Calendar;
-import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.ITestDataProvider;
@@ -30,9 +28,9 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
import org.junit.Test;
/**
- * Class for combined testing of XML-specific functionality of
+ * Class for combined testing of XML-specific functionality of
* {@link XSSFCell} and {@link SXSSFCell}.
- *
+ *
* Any test that is applicable for {@link HSSFCell} as well should go into
* the common base class {@link BaseTestCell}.
*/
@@ -47,14 +45,14 @@ public abstract class BaseTestXCell extends BaseTestCell {
Sheet sh = wb1.createSheet();
Row row = sh.createRow(0);
Cell cell = row.createCell(0);
- String sval = "\u0000\u0002\u0012<>\t\n\u00a0 &\"POI\'\u2122";
+ String sval = "\u0000\u0002\u0012<>\t\n\u00a0 &\"POI'\u2122";
cell.setCellValue(sval);
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
wb1.close();
// invalid characters are replaced with question marks
- assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+ assertEquals("???<>\t\n\u00a0 &\"POI'\u2122", wb2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
wb2.close();
}
}
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 86aa1ccb59..067df075d0 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
@@ -3494,4 +3494,52 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
LOG.log(POILogger.INFO, Duration.between(start, Instant.now()));
}
}
+
+ @Test
+ public void testBug63845() throws IOException {
+ try (Workbook wb = new XSSFWorkbook()) {
+ Sheet sheet = wb.createSheet();
+ Row row = sheet.createRow(0);
+
+ Cell cell = row.createCell(0, CellType.FORMULA);
+ cell.setCellFormula("SUM(B1:E1)");
+
+ assertNull("Element 'v' should not be set for formulas unless the value was calculated",
+ ((XSSFCell) cell).getCTCell().getV());
+
+ try (Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb)) {
+ Cell cellBack = wbBack.getSheetAt(0).getRow(0).getCell(0);
+ assertNull("Element 'v' should not be set for formulas unless the value was calculated",
+ ((XSSFCell) cellBack).getCTCell().getV());
+
+ wbBack.getCreationHelper().createFormulaEvaluator().evaluateInCell(cellBack);
+
+ assertEquals("Element 'v' should be set now as the formula was calculated manually",
+ "0.0", ((XSSFCell) cellBack).getCTCell().getV());
+ }
+ }
+ }
+
+ @Test
+ public void testBug63845_2() throws IOException {
+ try (Workbook wb = new XSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("test");
+ Row row = sheet.createRow(0);
+ row.createCell(0).setCellValue(2);
+ row.createCell(1).setCellValue(5);
+ row.createCell(2).setCellFormula("A1+B1");
+
+ try (Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb)) {
+ Cell cellBack = wbBack.getSheetAt(0).getRow(0).getCell(2);
+
+ assertNull("Element 'v' should not be set for formulas unless the value was calculated",
+ ((XSSFCell) cellBack).getCTCell().getV());
+
+ wbBack.getCreationHelper().createFormulaEvaluator().evaluateInCell(cellBack);
+
+ assertEquals("Element 'v' should be set now as the formula was calculated manually",
+ "7.0", ((XSSFCell) cellBack).getCTCell().getV());
+ }
+ }
+ }
}