diff options
author | PJ Fanning <fanningpj@apache.org> | 2023-10-27 16:53:06 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2023-10-27 16:53:06 +0000 |
commit | 8142b56fb88d8139df5fb42c7343d2a624e79c00 (patch) | |
tree | 2c6d95e514a3c61ce9d73f1b987d449747891e7a /poi-ooxml | |
parent | 0d1644282fbc43167b626b84e7978de53a336b2c (diff) | |
download | poi-8142b56fb88d8139df5fb42c7343d2a624e79c00.tar.gz poi-8142b56fb88d8139df5fb42c7343d2a624e79c00.zip |
some tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1913395 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java index fe67289913..9b1502df55 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -36,6 +36,7 @@ import org.apache.poi.POIDataSamples; import org.apache.poi.common.usermodel.PictureType; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLProperties; +import org.apache.poi.ooxml.TrackingInputStream; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; @@ -481,6 +482,28 @@ public final class TestXWPFDocument { } @Test + void testInputStreamClosed() throws IOException { + try (TrackingInputStream stream = new TrackingInputStream( + POIDataSamples.getDocumentInstance().openResourceAsStream("EnforcedWith.docx"))) { + try (XWPFDocument docx = new XWPFDocument(stream)) { + assertNotNull(docx.getDocument()); + } + assertTrue(stream.isClosed(), "stream was closed?"); + } + } + + @Test + void testInputStreamNotClosedWhenOptionUsed() throws IOException { + try (TrackingInputStream stream = new TrackingInputStream( + POIDataSamples.getDocumentInstance().openResourceAsStream("EnforcedWith.docx"))) { + try (XWPFDocument docx = new XWPFDocument(stream, false)) { + assertNotNull(docx.getDocument()); + } + assertFalse(stream.isClosed(), "stream was not closed?"); + } + } + + @Test @Disabled("XWPF should be able to write to a new Stream when opened Read-Only") void testWriteFromReadOnlyOPC() throws Exception { try (OPCPackage opc = OPCPackage.open( |