From 8142b56fb88d8139df5fb42c7343d2a624e79c00 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 27 Oct 2023 16:53:06 +0000 Subject: [PATCH] some tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1913395 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xwpf/usermodel/TestXWPFDocument.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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; @@ -480,6 +481,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 { -- 2.39.5