]> source.dussan.org Git - poi.git/commitdiff
Add reproducer tests for Bug 53515, disabled as we do not fix any of the
authorDominik Stadler <centic@apache.org>
Sat, 26 Oct 2013 10:05:24 +0000 (10:05 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 26 Oct 2013 10:05:24 +0000 (10:05 +0000)
reported issues. Also fix some Ecliipse warnings.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1535959 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

index 0d4a7d3c126c3bfa9f32ecfe45a71f21aa6cdc79..6a9abba7533e6f329b52551bd374d90c184267cf 100644 (file)
 
 package org.apache.poi.xssf.streaming;
 
-import org.apache.poi.ss.usermodel.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.poi.ss.usermodel.BaseTestWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
-import java.io.File;
-
 public final class TestSXSSFWorkbook extends BaseTestWorkbook {
     public static final SXSSFITestDataProvider _testDataProvider = SXSSFITestDataProvider.instance;
 
@@ -264,4 +272,81 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
         assertWorkbookDispose(wb);
 
     }
+
+    // currently writing the same sheet multiple times is not supported...
+       public void DISABLEDtestBug53515() throws Exception {
+               Workbook wb = new SXSSFWorkbook(10);
+               populateWorkbook(wb);
+               saveTwice(wb);
+               wb = new XSSFWorkbook();
+               populateWorkbook(wb);
+               saveTwice(wb);
+       }
+
+       // Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files
+       // See http://www.oracle.com/technetwork/java/javase/documentation/overview-156328.html
+       public void DISABLEDtestBug53515a() throws Exception {
+               File out = new File("Test.xlsx");
+               out.delete();
+               for (int i = 0; i < 2; i++) {
+                       System.out.println("Iteration " + i);
+                       final SXSSFWorkbook wb;
+                       if (out.exists()) {
+                               wb = new SXSSFWorkbook(
+                                               (XSSFWorkbook) WorkbookFactory.create(out));
+                       } else {
+                               wb = new SXSSFWorkbook(10);
+                       }
+
+                       try {
+                               FileOutputStream outSteam = new FileOutputStream(out);
+                               if (i == 0) {
+                                       populateWorkbook(wb);
+                               } else {
+                                       System.gc();
+                                       System.gc();
+                                       System.gc();
+                               }
+
+                               wb.write(outSteam);
+                               // wb.dispose();
+                               outSteam.close();
+                       } finally {
+                               wb.dispose();
+                       }
+               }
+               out.delete();
+       }
+
+       private static void populateWorkbook(Workbook wb) {
+               Sheet sh = wb.createSheet();
+               for (int rownum = 0; rownum < 100; rownum++) {
+                       Row row = sh.createRow(rownum);
+                       for (int cellnum = 0; cellnum < 10; cellnum++) {
+                               Cell cell = row.createCell(cellnum);
+                               String address = new CellReference(cell).formatAsString();
+                               cell.setCellValue(address);
+                       }
+               }
+       }
+
+       private static void saveTwice(Workbook wb) throws Exception {
+               for (int i = 0; i < 2; i++) {
+                       try {
+                               NullOutputStream out = new NullOutputStream();
+                               wb.write(out);
+                               out.close();
+                       } catch (Exception e) {
+                               throw new Exception("ERROR: failed on " + (i + 1)
+                                               + "th time calling " + wb.getClass().getName()
+                                               + ".write() with exception " + e.getMessage(), e);
+                       }
+               }
+       }
+
+       private static class NullOutputStream extends OutputStream {
+               @Override
+               public void write(int b) throws IOException {
+               }
+       }
 }
index ce96c3fe177f4b4e7f650c6b84a44ef388e19ff4..30ecd1990ff7a8ea6a44ae4d248487d67c1ebd6e 100644 (file)
@@ -156,7 +156,7 @@ public abstract class BaseTestWorkbook extends TestCase {
         String sheetName2 = "My very long sheet name which is longer than 31 chars " +
                 "and sheetName2.substring(0, 31) == sheetName1.substring(0, 31)";
         try {
-            Sheet sh2 = wb.createSheet(sheetName2);
+            /*Sheet sh2 =*/ wb.createSheet(sheetName2);
             fail("expected exception");
         } catch (IllegalArgumentException e) {
             // expected during successful test
@@ -415,7 +415,7 @@ public abstract class BaseTestWorkbook extends TestCase {
         c.setCellValue(12.34);
         c.getCellStyle().setDataFormat(fmt);
 
-        Cell c2 = r.createCell(2); // TODO - c2 unused but changing next line ('c'->'c2') causes test to fail
+        /*Cell c2 =*/ r.createCell(2); // TODO - c2 unused but changing next line ('c'->'c2') causes test to fail
         c.setCellValue(factory.createRichTextString("\u20ac"));
 
         Cell c3 = r.createCell(3);
@@ -447,7 +447,7 @@ public abstract class BaseTestWorkbook extends TestCase {
         assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat()));
 
         //Test the cell string value
-        c2 = r.getCell(2);
+        /*c2 =*/ r.getCell(2);
         assertEquals(c.getRichStringCellValue().getString(), "\u20ac");
 
         //Test the cell formula