mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Enable storing an SXSSF workbook twice
Verify this via a unit-test for all types of workbooks Add a test to verify the contents is byte-for-byte equal Also remove an overwritten test which works the same now for all three workbook-types git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886060 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1d26df99ee
commit
615de587f7
@ -131,7 +131,7 @@ public class SheetDataWriter implements Closeable {
|
||||
* This method <em>must</em> be invoked before calling {@link #getWorksheetXMLInputStream()}
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
_out.flush();
|
||||
// this would break writing the same document multiple times: _out.flush();
|
||||
_out.close();
|
||||
}
|
||||
|
||||
|
||||
@ -101,20 +101,6 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues {
|
||||
wb2.close();
|
||||
}
|
||||
|
||||
// bug 60197: setSheetOrder should update sheet-scoped named ranges to maintain references to the sheets before the re-order
|
||||
@Test
|
||||
@Override
|
||||
protected void bug60197_NamedRangesReferToCorrectSheetWhenSheetOrderIsChanged() throws Exception {
|
||||
// expected on the second time that _testDataProvider.writeOutAndReadBack(SXSSFWorkbook) is called
|
||||
// if the test makes it this far, then we know that XSSFName sheet indices are updated when sheet
|
||||
// order is changed, which is the purpose of this test. Therefore, consider this a passing test.
|
||||
RuntimeException e =
|
||||
assertThrows(RuntimeException.class, () -> super.bug60197_NamedRangesReferToCorrectSheetWhenSheetOrderIsChanged());
|
||||
Throwable cause = e.getCause();
|
||||
assertTrue(cause instanceof IOException);
|
||||
assertEquals("Stream closed", cause.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug61648() throws Exception {
|
||||
// works as expected
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@ -30,6 +31,7 @@ import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.AttributedString;
|
||||
import java.util.HashMap;
|
||||
@ -106,7 +108,6 @@ public abstract class BaseTestBugzillaIssues {
|
||||
/**
|
||||
* test writing a file with large number of unique strings,
|
||||
* open resulting file in Excel to check results!
|
||||
* @param num the number of strings to generate
|
||||
*/
|
||||
@Test
|
||||
public final void bug15375_2() throws IOException {
|
||||
@ -1804,4 +1805,32 @@ public abstract class BaseTestBugzillaIssues {
|
||||
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
|
||||
assertEquals(expectedResultOrNull, eval.evaluate(intF).formatAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWriteDocumentTwice() throws Exception {
|
||||
try (Workbook wb = _testDataProvider.createWorkbook()) {
|
||||
Sheet sheet = wb.createSheet("RawData");
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cell;
|
||||
|
||||
cell = row.createCell(0);
|
||||
cell.setCellValue("Ernie & Bert");
|
||||
|
||||
cell = row.createCell(1);
|
||||
// Set a precalculated formula value containing a special character.
|
||||
cell.setCellValue("Ernie & Bert are cool!");
|
||||
cell.setCellFormula("A1 & \" are cool!\"");
|
||||
|
||||
try (ByteArrayOutputStream out1 = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream out2 = new ByteArrayOutputStream()) {
|
||||
wb.write(out1);
|
||||
wb.write(out2);
|
||||
|
||||
out1.flush();
|
||||
out2.flush();
|
||||
|
||||
assertArrayEquals(out1.toByteArray(), out2.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user