Add reproducer tests for Bug 53515, disabled as we do not fix any of the

reported issues. Also fix some Ecliipse warnings.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1535959 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2013-10-26 10:05:24 +00:00
parent 5644fcbaa0
commit 0342f9602d
2 changed files with 91 additions and 6 deletions

View File

@ -19,13 +19,21 @@
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 {
}
}
}

View 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