From 42f735fed4c03c54b8c100a3bf435f930ae79a43 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 12 Sep 2016 23:10:27 +0000 Subject: [PATCH] Disabled unit test for #60010 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760458 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/streaming/TestSXSSFWorkbook.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index bdd858b061..7b5a67de58 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -35,6 +36,8 @@ import java.util.Arrays; import org.apache.poi.POIDataSamples; import org.apache.poi.POITestCase; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.ss.usermodel.BaseTestXWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -536,4 +539,40 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { swb.dispose(); swb.close(); } + + /** + * To avoid accident changes to the template, you should be able + * to create a SXSSFWorkbook from a read-only XSSF one, then + * change + save that (only). See bug #60010 + * TODO Fix this to work! + */ + @Test + @Ignore + public void createFromReadOnlyWorkbook() throws Exception { + File input = XSSFTestDataSamples.getSampleFile("sample.xlsx"); + OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ); + XSSFWorkbook xssf = new XSSFWorkbook(pkg); + SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2); + + String sheetName = "Test SXSSF"; + Sheet s = wb.createSheet(sheetName); + for (int i=0; i<10; i++) { + Row r = s.createRow(i); + r.createCell(0).setCellValue(true); + r.createCell(1).setCellValue(2.4); + r.createCell(2).setCellValue("Test Row " + i); + } + assertEquals(10, s.getLastRowNum()); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + wb.write(bos); + wb.dispose(); + wb.close(); + + xssf = new XSSFWorkbook(new ByteArrayInputStream(bos.toByteArray())); + s = xssf.getSheet(sheetName); + assertEquals(10, s.getLastRowNum()); + assertEquals(true, s.getRow(0).getCell(0).getBooleanCellValue()); + assertEquals("Test Row 9", s.getRow(9).getCell(2).getStringCellValue()); + } }