aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/usermodel
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-05-19 13:13:09 +0000
committerDominik Stadler <centic@apache.org>2015-05-19 13:13:09 +0000
commit5209d15d1c2d12346ba57fdc41267ffd4e45a1f0 (patch)
tree77e0fc99de3c8f77365ab2de42720c23c92577d0 /src/testcases/org/apache/poi/ss/usermodel
parent636fefef8a9355e4e96fa2cdbb99f9b4abb03673 (diff)
downloadpoi-5209d15d1c2d12346ba57fdc41267ffd4e45a1f0.tar.gz
poi-5209d15d1c2d12346ba57fdc41267ffd4e45a1f0.zip
Prevent problems reported in Bug 56574 by ensuring that Cells are properly removed when a row is overwritten by calling createRow() with it's rownum.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1680280 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/usermodel')
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java55
1 files changed, 52 insertions, 3 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
index fe11df6589..8b6732ca45 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
@@ -18,9 +18,12 @@
package org.apache.poi.ss.usermodel;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -637,7 +640,7 @@ public abstract class BaseTestBugzillaIssues {
// Next up, SEARCH on its own
cf.setCellFormula("SEARCH(\"am\", A1)");
cf = evaluateCell(wb, cf);
- assertEquals(ErrorConstants.ERROR_VALUE, cf.getErrorCellValue());
+ assertEquals(FormulaError.VALUE.getCode(), cf.getErrorCellValue());
cf.setCellFormula("SEARCH(\"am\", B1)");
cf = evaluateCell(wb, cf);
@@ -645,11 +648,11 @@ public abstract class BaseTestBugzillaIssues {
cf.setCellFormula("SEARCH(\"am\", C1)");
cf = evaluateCell(wb, cf);
- assertEquals(ErrorConstants.ERROR_VALUE, cf.getErrorCellValue());
+ assertEquals(FormulaError.VALUE.getCode(), cf.getErrorCellValue());
cf.setCellFormula("SEARCH(\"am\", D1)");
cf = evaluateCell(wb, cf);
- assertEquals(ErrorConstants.ERROR_VALUE, cf.getErrorCellValue());
+ assertEquals(FormulaError.VALUE.getCode(), cf.getErrorCellValue());
// Finally, bring it all together
@@ -757,4 +760,50 @@ public abstract class BaseTestBugzillaIssues {
assertEquals(otherCellText, c1.getStringCellValue());
assertEquals(otherCellText, c2.getStringCellValue());
}
+
+ @Test
+ public void test56574OverwriteExistingRow() throws IOException {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sheet = wb.createSheet();
+
+ { // create the Formula-Cell
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+ cell.setCellFormula("A2");
+ }
+
+ { // check that it is there now
+ Row row = sheet.getRow(0);
+
+ /* CTCell[] cArray = ((XSSFRow)row).getCTRow().getCArray();
+ assertEquals(1, cArray.length);*/
+
+ Cell cell = row.getCell(0);
+ assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ }
+
+ { // overwrite the row
+ Row row = sheet.createRow(0);
+ assertNotNull(row);
+ }
+
+ { // creating a row in place of another should remove the existing data,
+ // check that the cell is gone now
+ Row row = sheet.getRow(0);
+
+ /*CTCell[] cArray = ((XSSFRow)row).getCTRow().getCArray();
+ assertEquals(0, cArray.length);*/
+
+ Cell cell = row.getCell(0);
+ assertNull(cell);
+ }
+
+ // the calculation chain in XSSF is empty in a newly created workbook, so we cannot check if it is correctly updated
+ /*assertNull(((XSSFWorkbook)wb).getCalculationChain());
+ assertNotNull(((XSSFWorkbook)wb).getCalculationChain().getCTCalcChain());
+ assertNotNull(((XSSFWorkbook)wb).getCalculationChain().getCTCalcChain().getCArray());
+ assertEquals(0, ((XSSFWorkbook)wb).getCalculationChain().getCTCalcChain().getCArray().length);*/
+
+ wb.close();
+ }
}