From: Nick Burch Date: Fri, 27 May 2011 13:36:00 +0000 (+0000) Subject: Add unit test from Stefan for bug #51172 - DOCX gif support X-Git-Tag: REL_3_8_BETA3~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d02dee4c6846f67588c86f4d8b78a9e1a276a916;p=poi.git Add unit test from Stefan for bug #51172 - DOCX gif support git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1128301 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java index ebdeea294b..b3f1ce34ad 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java @@ -17,14 +17,19 @@ package org.apache.poi.xwpf; +import java.util.ArrayList; +import java.util.List; + import junit.framework.TestCase; +import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLProperties; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFPictureData; import org.apache.poi.xwpf.usermodel.XWPFRelation; import org.apache.xmlbeans.XmlCursor; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; @@ -194,4 +199,25 @@ public final class TestXWPFDocument extends TestCase { assertEquals(p3, doc.getBodyElements().get(0)); assertEquals(p3, doc.getParagraphs().get(0)); } + + public void testGIFSupport() throws Exception + { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("WithGIF.docx"); + ArrayList gifParts = doc.getPackage().getPartsByContentType(XWPFRelation.IMAGE_GIF.getContentType()); + assertEquals("Expected exactly one GIF part in package.",1,gifParts.size()); + PackagePart gifPart = gifParts.get(0); + + List relations = doc.getRelations(); + POIXMLDocumentPart gifDocPart = null; + for (POIXMLDocumentPart docPart : relations) + { + if (gifPart == docPart.getPackagePart()) + { + assertNull("More than one POIXMLDocumentPart for GIF PackagePart.",gifDocPart); + gifDocPart = docPart; + } + } + assertNotNull("GIF part not related to document.xml PackagePart",gifDocPart); + assertTrue("XWPFRelation for GIF image was not recognized properly, as the POIXMLDocumentPart created was of a wrong type.",XWPFRelation.IMAGE_GIF.getRelationClass().isInstance(gifDocPart)); + } } diff --git a/test-data/document/WithGIF.docx b/test-data/document/WithGIF.docx new file mode 100644 index 0000000000..8af42d5880 Binary files /dev/null and b/test-data/document/WithGIF.docx differ