aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-13 23:02:55 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-13 23:02:55 +0000
commitddde81cf806a5534a01483b563651bd84cf7452d (patch)
tree228d3debc22faf3ec1d18cb026300e9ded565ada /src/test/java
parent26ac5524f3667d44bb53fd19d8a770d900847210 (diff)
Read embedded blips in wp:inline
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
index cc0815e..0683bff 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -17,6 +17,7 @@ import org.zwobble.mammoth.xml.XmlNodes;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import static com.natpryce.makeiteasy.MakeItEasy.*;
@@ -404,6 +405,47 @@ public class BodyXmlTests {
}
@Test
+ public void canReadInlinePictures() throws IOException {
+ XmlElement element = inlineImageXml(embeddedBlipXml("rId5"), "It's a hat");
+ Relationships relationships = new Relationships(map(
+ "rId5", new Relationship("media/hat.png")));
+ String imageBytes = "Not an image at all!";
+ DocxFile file = new InMemoryDocxFile(map("word/media/hat.png", imageBytes));
+
+ Image image = (Image) readSuccess(
+ a(bodyReader, with(RELATIONSHIPS, relationships), with(DOCX_FILE, file)),
+ element);
+ assertThat(image, allOf(
+ hasProperty("altText", deepEquals(Optional.of("It's a hat"))),
+ hasProperty("contentType", deepEquals(Optional.of("image/png")))));
+ assertThat(
+ CharStreams.toString(new InputStreamReader(image.open())),
+ equalTo("Not an image at all!"));
+ }
+
+ private XmlElement inlineImageXml(XmlElement blip, String description) {
+ return element("w:drawing", list(
+ element("wp:inline", imageXml(blip, description))));
+ }
+
+ private List<XmlNode> imageXml(XmlElement blip, String description) {
+ return list(
+ element("wp:docPr", map("descr", description)),
+ element("a:graphic", list(
+ element("a:graphicData", list(
+ element("pic:pic", list(
+ element("pic:blipFill", list(blip)))))))));
+ }
+
+ private XmlElement embeddedBlipXml(String relationshipId) {
+ return blipXml(map("r:embed", relationshipId));
+ }
+
+ private XmlElement blipXml(Map<String, String> attributes) {
+ return element("a:blip", attributes);
+ }
+
+ @Test
public void appropriateElementsHaveTheirChildrenReadNormally() {
assertChildrenAreReadNormally("w:ins");
assertChildrenAreReadNormally("w:smartTag");