diff options
author | Javen O'Neal <onealj@apache.org> | 2017-12-13 06:21:19 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2017-12-13 06:21:19 +0000 |
commit | 54b0cf8f93c8749415e8d35d9bb412c3cb69caf2 (patch) | |
tree | a0e7f0e22e45ce4d6cbdab984e263a6c60288562 | |
parent | 2ed2aa504d285082eaa72a2ecefc065ee7b5967f (diff) | |
download | poi-54b0cf8f93c8749415e8d35d9bb412c3cb69caf2.tar.gz poi-54b0cf8f93c8749415e8d35d9bb412c3cb69caf2.zip |
bug 57423: add unit test demonstrating corrupted workbook where CTRow xmlbeans are not in ascending order in the CTWorksheet; unit test adapted from Luca
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1817975 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java index ea48e4b169..f9bfcee8f0 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java @@ -342,4 +342,42 @@ public final class TestUnfixedBugs { assertEquals("Did not have expected contents at rownum " + rowNum, contents + ".0", cell.toString()); } + + @Test + public void bug57423_shiftRowsByLargeOffset() throws IOException { + try ( + XSSFWorkbook wb = new XSSFWorkbook(); + //OutputStream out = new FileOutputStream("/tmp/57423." + wb.getClass().getName() + ".xlsx")); + ) { + Sheet sh = wb.createSheet(); + sh.createRow(0).createCell(0).setCellValue("a"); + sh.createRow(1).createCell(0).setCellValue("b"); + sh.createRow(2).createCell(0).setCellValue("c"); + sh.shiftRows(0, 1, 3); + + XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb); + + assertThatRowsInAscendingOrder(wb); + assertThatRowsInAscendingOrder(wbBack); + + //wbBack.write(out); + // Excel reports that the workbook is corrupt because the rows are not in ascending order + // LibreOffice doesn't complain when rows are not in ascending order + + wbBack.close(); + } + } + + private void assertThatRowsInAscendingOrder(final XSSFWorkbook wb) { + // Check that CTRows are stored in ascending order of row index + long maxSeenRowNum = 0; //1-based + for (final CTRow ctRow : wb.getSheetAt(0).getCTWorksheet().getSheetData().getRowArray()) { + final long rowNum = ctRow.getR(); //1-based + //final int rowNum = Integer.parseInt(ctRow.getR()); //1-based + assertTrue("Row " + rowNum + " (1-based) is not in ascending order; previously saw " + maxSeenRowNum, + rowNum > maxSeenRowNum); + maxSeenRowNum = rowNum; + } + } + } |