Browse Source

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
tags/REL_5_1_0
Dominik Stadler 3 years ago
parent
commit
615de587f7

+ 1
- 1
src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java View File

@@ -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();
}


+ 0
- 14
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java View File

@@ -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

+ 30
- 1
src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java View File

@@ -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…
Cancel
Save