You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2017/12/13 06:21:19 UTC
svn commit: r1817975 -
/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
Author: onealj
Date: Wed Dec 13 06:21:19 2017
New Revision: 1817975
URL: http://svn.apache.org/viewvc?rev=1817975&view=rev
Log:
bug 57423: add unit test demonstrating corrupted workbook where CTRow xmlbeans are not in ascending order in the CTWorksheet; unit test adapted from Luca
Modified:
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java?rev=1817975&r1=1817974&r2=1817975&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java Wed Dec 13 06:21:19 2017
@@ -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;
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org