]> source.dussan.org Git - poi.git/commitdiff
Add unit test from Stefan for bug #51172 - DOCX gif support
authorNick Burch <nick@apache.org>
Fri, 27 May 2011 13:36:00 +0000 (13:36 +0000)
committerNick Burch <nick@apache.org>
Fri, 27 May 2011 13:36:00 +0000 (13:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1128301 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
test-data/document/WithGIF.docx [new file with mode: 0644]

index ebdeea294be67a4174aed2953529ef51167ac846..b3f1ce34ad1eb0505c571ed7646f0bb7a7ed3a98 100644 (file)
 
 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<PackagePart> 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<POIXMLDocumentPart> 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 (file)
index 0000000..8af42d5
Binary files /dev/null and b/test-data/document/WithGIF.docx differ