Tests for patches from Yegor (Bug #39097)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@388921 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7067a15892
commit
29a5b2b56b
BIN
src/scratchpad/testcases/org/apache/poi/hslf/data/clock.jpg
Normal file
BIN
src/scratchpad/testcases/org/apache/poi/hslf/data/clock.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
src/scratchpad/testcases/org/apache/poi/hslf/data/painting.png
Normal file
BIN
src/scratchpad/testcases/org/apache/poi/hslf/data/painting.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
@ -17,11 +17,19 @@
|
|||||||
package org.apache.poi.hslf.usermodel;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.hslf.*;
|
import org.apache.poi.hslf.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.PictureData;
|
||||||
|
import org.apache.poi.hslf.usermodel.SlideShow;
|
||||||
|
import org.apache.poi.hslf.model.Slide;
|
||||||
|
import org.apache.poi.hslf.model.Shape;
|
||||||
|
import org.apache.poi.hslf.model.Picture;
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test extracting images from a ppt file
|
* Test extracting images from a ppt file
|
||||||
@ -29,19 +37,61 @@ import java.io.ByteArrayInputStream;
|
|||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestPictures extends TestCase{
|
public class TestPictures extends TestCase{
|
||||||
|
public static String dirname = System.getProperty("HSLF.testdata.path");
|
||||||
|
public static String filename = dirname + "/ppt_with_png.ppt";
|
||||||
|
|
||||||
public void testPictures() throws Exception {
|
public void testReadPictures() throws Exception {
|
||||||
String dirname = System.getProperty("HSLF.testdata.path");
|
|
||||||
String filename = dirname + "/ppt_with_png.ppt";
|
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(filename);
|
HSLFSlideShow ppt = new HSLFSlideShow(filename);
|
||||||
Picture[] pict = ppt.getPictures();
|
PictureData[] pict = ppt.getPictures();
|
||||||
assertNotNull(pict);
|
assertNotNull(pict);
|
||||||
for (int i = 0; i < pict.length; i++) {
|
for (int i = 0; i < pict.length; i++) {
|
||||||
byte[] data = pict[i].getData();
|
byte[] data = pict[i].getData();
|
||||||
|
|
||||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
|
BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
|
||||||
assertNotNull(img);
|
assertNotNull(img);
|
||||||
}
|
}
|
||||||
ppt.close();
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSerializePictures() throws Exception {
|
||||||
|
HSLFSlideShow ppt = new HSLFSlideShow(filename);
|
||||||
|
PictureData[] pict = ppt.getPictures();
|
||||||
|
assertNotNull(pict);
|
||||||
|
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
ppt.write(out);
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
|
||||||
|
pict = ppt.getPictures();
|
||||||
|
assertNotNull(pict);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddPictures() throws Exception {
|
||||||
|
int idx;
|
||||||
|
Slide slide;
|
||||||
|
Picture pict;
|
||||||
|
|
||||||
|
SlideShow ppt = new SlideShow();
|
||||||
|
|
||||||
|
idx = ppt.addPicture(new File(dirname + "/clock.jpg"), Picture.JPEG);
|
||||||
|
slide = ppt.createSlide();
|
||||||
|
pict = new Picture(idx);
|
||||||
|
pict.setDefaultSize(ppt);
|
||||||
|
slide.addShape(pict);
|
||||||
|
|
||||||
|
idx = ppt.addPicture(new File(dirname + "/painting.png"), Picture.PNG);
|
||||||
|
pict = new Picture(idx);
|
||||||
|
pict.setDefaultSize(ppt);
|
||||||
|
slide.addShape(pict);
|
||||||
|
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
ppt.write(out);
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
|
||||||
|
assertTrue(ppt.getPictures().length == 2 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user