]> source.dussan.org Git - poi.git/commitdiff
Tests for patches from Yegor (Bug #39097)
authorNick Burch <nick@apache.org>
Sun, 26 Mar 2006 16:21:08 +0000 (16:21 +0000)
committerNick Burch <nick@apache.org>
Sun, 26 Mar 2006 16:21:08 +0000 (16:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@388921 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/testcases/org/apache/poi/hslf/data/clock.jpg [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/data/painting.png [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java

diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/clock.jpg b/src/scratchpad/testcases/org/apache/poi/hslf/data/clock.jpg
new file mode 100644 (file)
index 0000000..5f05e42
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/clock.jpg differ
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/painting.png b/src/scratchpad/testcases/org/apache/poi/hslf/data/painting.png
new file mode 100644 (file)
index 0000000..28f1233
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/painting.png differ
index d40ed0eb932c0d34a4b64b87b213bf497252c72a..b4503eb017fdf16d104f8e7adf751e7ddc8a62f5 100644 (file)
 package org.apache.poi.hslf.usermodel;\r
 \r
 import org.apache.poi.hslf.*;\r
+import org.apache.poi.hslf.usermodel.PictureData;\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.model.Slide;\r
+import org.apache.poi.hslf.model.Shape;\r
+import org.apache.poi.hslf.model.Picture;\r
+import org.apache.poi.util.LittleEndian;\r
 import junit.framework.TestCase;\r
 \r
 import javax.imageio.ImageIO;\r
 import java.awt.image.BufferedImage;\r
 import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.File;\r
 \r
 /**\r
  * Test extracting images from a ppt file\r
@@ -29,19 +37,61 @@ import java.io.ByteArrayInputStream;
  * @author Yegor Kozlov\r
  */\r
 public class TestPictures extends TestCase{\r
+    public static String dirname = System.getProperty("HSLF.testdata.path");\r
+    public static String filename = dirname + "/ppt_with_png.ppt";\r
 \r
-    public void testPictures() throws Exception {\r
-        String dirname = System.getProperty("HSLF.testdata.path");\r
-        String filename = dirname + "/ppt_with_png.ppt";\r
+    public void testReadPictures() throws Exception {\r
 \r
         HSLFSlideShow ppt = new HSLFSlideShow(filename);\r
-        Picture[] pict = ppt.getPictures();\r
+        PictureData[] pict = ppt.getPictures();\r
         assertNotNull(pict);\r
         for (int i = 0; i < pict.length; i++) {\r
             byte[] data = pict[i].getData();\r
+\r
             BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));\r
             assertNotNull(img);\r
         }\r
         ppt.close();\r
     }\r
+\r
+    public void testSerializePictures() throws Exception {\r
+        HSLFSlideShow ppt = new HSLFSlideShow(filename);\r
+        PictureData[] pict = ppt.getPictures();\r
+        assertNotNull(pict);\r
+\r
+        ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+        ppt.write(out);\r
+        out.close();\r
+\r
+        ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));\r
+        pict = ppt.getPictures();\r
+        assertNotNull(pict);\r
+    }\r
+\r
+    public void testAddPictures() throws Exception {\r
+        int idx;\r
+        Slide slide;\r
+        Picture pict;\r
+\r
+        SlideShow ppt = new SlideShow();\r
+\r
+        idx = ppt.addPicture(new File(dirname + "/clock.jpg"), Picture.JPEG);\r
+        slide = ppt.createSlide();\r
+        pict = new Picture(idx);\r
+        pict.setDefaultSize(ppt);\r
+        slide.addShape(pict);\r
+\r
+        idx = ppt.addPicture(new File(dirname + "/painting.png"), Picture.PNG);\r
+        pict = new Picture(idx);\r
+        pict.setDefaultSize(ppt);\r
+        slide.addShape(pict);\r
+\r
+        ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+        ppt.write(out);\r
+        out.close();\r
+\r
+        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
+        assertTrue(ppt.getPictures().length == 2 );\r
+    }\r
+\r
 }\r