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
This commit is contained in:
parent
e21fd13a56
commit
0f9646d55d
@ -17,14 +17,19 @@
|
|||||||
|
|
||||||
package org.apache.poi.xwpf;
|
package org.apache.poi.xwpf;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLProperties;
|
import org.apache.poi.POIXMLProperties;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFPictureData;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFRelation;
|
import org.apache.poi.xwpf.usermodel.XWPFRelation;
|
||||||
import org.apache.xmlbeans.XmlCursor;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
|
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.getBodyElements().get(0));
|
||||||
assertEquals(p3, doc.getParagraphs().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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/document/WithGIF.docx
Normal file
BIN
test-data/document/WithGIF.docx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user