fix eclipse warnings - close resources

add getter for HSLF slideshows implementation class

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1774974 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
kiwiwings 2016-12-19 01:34:24 +00:00
parent c200faedec
commit 503a63c0d4
14 changed files with 398 additions and 366 deletions

View File

@ -25,6 +25,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -33,12 +34,10 @@ import org.apache.poi.hslf.usermodel.HSLFSlideShow;
/** /**
* Demonstrates how you can use HSLF to convert each slide into a PNG image * Demonstrates how you can use HSLF to convert each slide into a PNG image
*
* @author Yegor Kozlov
*/ */
public final class PPT2PNG { public final class PPT2PNG {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws IOException {
if (args.length == 0) { if (args.length == 0) {
usage(); usage();
@ -74,7 +73,9 @@ public final class PPT2PNG {
int height = (int)(pgsize.height*scale); int height = (int)(pgsize.height*scale);
for (HSLFSlide slide : ppt.getSlides()) { for (HSLFSlide slide : ppt.getSlides()) {
if (slidenum != -1 && slidenum != slide.getSlideNumber()) continue; if (slidenum != -1 && slidenum != slide.getSlideNumber()) {
continue;
}
String title = slide.getTitle(); String title = slide.getTitle();
System.out.println("Rendering slide "+slide.getSlideNumber() + (title == null ? "" : ": " + title)); System.out.println("Rendering slide "+slide.getSlideNumber() + (title == null ? "" : ": " + title));
@ -98,6 +99,8 @@ public final class PPT2PNG {
ImageIO.write(img, "png", out); ImageIO.write(img, "png", out);
out.close(); out.close();
} }
ppt.close();
} }
private static void usage(){ private static void usage(){

View File

@ -19,6 +19,8 @@
package org.apache.poi.xslf.usermodel.tutorial; package org.apache.poi.xslf.usermodel.tutorial;
import java.io.FileInputStream;
import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFShape; import org.apache.poi.xslf.usermodel.XSLFShape;
import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.poi.xslf.usermodel.XSLFSlide;
@ -26,12 +28,8 @@ import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
import org.apache.poi.xslf.usermodel.XSLFTextRun; import org.apache.poi.xslf.usermodel.XSLFTextRun;
import org.apache.poi.xslf.usermodel.XSLFTextShape; import org.apache.poi.xslf.usermodel.XSLFTextShape;
import java.io.FileInputStream;
/** /**
* Reading a .pptx presentation and printing basic shape properties * Reading a .pptx presentation and printing basic shape properties
*
* @author Yegor Kozlov
*/ */
public class Step1 { public class Step1 {
@ -41,7 +39,9 @@ public class Step1 {
return; return;
} }
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(args[0])); FileInputStream fis = new FileInputStream(args[0]);
XMLSlideShow ppt = new XMLSlideShow(fis);
fis.close();
for(XSLFSlide slide : ppt.getSlides()){ for(XSLFSlide slide : ppt.getSlides()){
System.out.println("Title: " + slide.getTitle()); System.out.println("Title: " + slide.getTitle());
@ -64,5 +64,7 @@ public class Step1 {
} }
} }
} }
ppt.close();
} }
} }

View File

@ -30,14 +30,11 @@ import java.io.FileOutputStream;
/** /**
* Create slides from pre-defined slide layouts * Create slides from pre-defined slide layouts
*
* @author Yegor Kozlov
*/ */
public class Step2 { public class Step2 {
public static void main(String[] args) throws Exception{ public static void main(String[] args) throws Exception{
XMLSlideShow ppt = new XMLSlideShow(); XMLSlideShow ppt = new XMLSlideShow();
// first see what slide layouts are available by default // first see what slide layouts are available by default
System.out.println("Available slide layouts:"); System.out.println("Available slide layouts:");
for(XSLFSlideMaster master : ppt.getSlideMasters()){ for(XSLFSlideMaster master : ppt.getSlideMasters()){
@ -75,6 +72,6 @@ public class Step2 {
FileOutputStream out = new FileOutputStream("step2.pptx"); FileOutputStream out = new FileOutputStream("step2.pptx");
ppt.write(out); ppt.write(out);
out.close(); out.close();
ppt.close();
} }
} }

View File

@ -52,6 +52,7 @@ import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.Resources; import org.apache.poi.sl.usermodel.Resources;
import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
@ -61,9 +62,6 @@ import org.apache.poi.util.Units;
* *
* TODO: - figure out how to match notes to their correct sheet (will involve * TODO: - figure out how to match notes to their correct sheet (will involve
* understanding DocSlideList and DocNotesList) - handle Slide creation cleaner * understanding DocSlideList and DocNotesList) - handle Slide creation cleaner
*
* @author Nick Burch
* @author Yegor kozlov
*/ */
public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable { public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable {
enum LoadSavePhase { enum LoadSavePhase {
@ -211,14 +209,18 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
// Now convert the byte offsets back into record offsets // Now convert the byte offsets back into record offsets
for (Record record : _hslfSlideShow.getRecords()) { for (Record record : _hslfSlideShow.getRecords()) {
if (!(record instanceof PositionDependentRecord)) continue; if (!(record instanceof PositionDependentRecord)) {
continue;
}
PositionDependentRecord pdr = (PositionDependentRecord) record; PositionDependentRecord pdr = (PositionDependentRecord) record;
int recordAt = pdr.getLastOnDiskOffset(); int recordAt = pdr.getLastOnDiskOffset();
Integer thisID = mostRecentByBytesRev.get(recordAt); Integer thisID = mostRecentByBytesRev.get(recordAt);
if (thisID == null) continue; if (thisID == null) {
continue;
}
// Bingo. Now, where do we store it? // Bingo. Now, where do we store it?
int storeAt = _sheetIdToCoreRecordsLookup.get(thisID); int storeAt = _sheetIdToCoreRecordsLookup.get(thisID);
@ -470,7 +472,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
for (HSLFTextParagraph p : hts.getTextParagraphs()) { for (HSLFTextParagraph p : hts.getTextParagraphs()) {
isDirty |= p.isDirty(); isDirty |= p.isDirty();
} }
if (isDirty) hts.storeText(); if (isDirty) {
hts.storeText();
}
} }
} }
} }
@ -632,7 +636,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
sa.remove(index); sa.remove(index);
int i=0; int i=0;
for (HSLFSlide s : _slides) s.setSlideNumber(i++); for (HSLFSlide s : _slides) {
s.setSlideNumber(i++);
}
for (SlideAtomsSet s : sa) { for (SlideAtomsSet s : sa) {
records.add(s.getSlidePersistAtom()); records.add(s.getSlidePersistAtom());
@ -653,7 +659,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
records = new ArrayList<Record>(); records = new ArrayList<Record>();
ArrayList<SlideAtomsSet> na = new ArrayList<SlideAtomsSet>(); ArrayList<SlideAtomsSet> na = new ArrayList<SlideAtomsSet>();
for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) { for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) {
if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) continue; if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) {
continue;
}
na.add(ns); na.add(ns);
records.add(ns.getSlidePersistAtom()); records.add(ns.getSlidePersistAtom());
if (ns.getSlideRecords() != null) { if (ns.getSlideRecords() != null) {
@ -1115,16 +1123,26 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
return psrId; return psrId;
} }
@Override
public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException { public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override
public Resources getResources() { public Resources getResources() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
/**
* @return the handler class which holds the hslf records
*/
@Internal
public HSLFSlideShowImpl getSlideShowImpl() {
return _hslfSlideShow;
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
_hslfSlideShow.close(); _hslfSlideShow.close();

View File

@ -34,12 +34,23 @@ public class HSLFTestDataSamples {
public static InputStream openSampleFileStream(String sampleFileName) { public static InputStream openSampleFileStream(String sampleFileName) {
return _inst.openResourceAsStream(sampleFileName); return _inst.openResourceAsStream(sampleFileName);
} }
public static File getSampleFile(String sampleFileName) { public static File getSampleFile(String sampleFileName) {
return _inst.getFile(sampleFileName); return _inst.getFile(sampleFileName);
} }
public static byte[] getTestDataFileContent(String fileName) { public static byte[] getTestDataFileContent(String fileName) {
return _inst.readFile(fileName); return _inst.readFile(fileName);
} }
public static HSLFSlideShow getSlideShow(String fileName) throws IOException {
InputStream is = openSampleFileStream(fileName);
try {
return new HSLFSlideShow(is);
} finally {
is.close();
}
}
/** /**
* Writes a slideshow to a <tt>ByteArrayOutputStream</tt> and reads it back * Writes a slideshow to a <tt>ByteArrayOutputStream</tt> and reads it back

View File

@ -21,8 +21,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.io.ByteArrayInputStream; import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
@ -32,6 +31,7 @@ import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.record.Document; import org.apache.poi.hslf.record.Document;
import org.apache.poi.hslf.usermodel.HSLFAutoShape; import org.apache.poi.hslf.usermodel.HSLFAutoShape;
import org.apache.poi.hslf.usermodel.HSLFFill; import org.apache.poi.hslf.usermodel.HSLFFill;
@ -40,7 +40,6 @@ import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFSheet; import org.apache.poi.hslf.usermodel.HSLFSheet;
import org.apache.poi.hslf.usermodel.HSLFSlide; import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
import org.junit.Test; import org.junit.Test;
@ -58,7 +57,7 @@ public final class TestBackground {
* Default background for slide, shape and slide master. * Default background for slide, shape and slide master.
*/ */
@Test @Test
public void defaults() { public void defaults() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(); HSLFSlideShow ppt = new HSLFSlideShow();
assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType()); assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType());
@ -69,14 +68,15 @@ public final class TestBackground {
HSLFShape shape = new HSLFAutoShape(ShapeType.RECT); HSLFShape shape = new HSLFAutoShape(ShapeType.RECT);
assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType()); assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
ppt.close();
} }
/** /**
* Read fill information from an reference ppt file * Read fill information from an reference ppt file
*/ */
@Test @Test
public void readBackground() throws Exception { public void readBackground() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("backgrounds.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("backgrounds.ppt");
HSLFFill fill; HSLFFill fill;
HSLFShape shape; HSLFShape shape;
@ -101,24 +101,25 @@ public final class TestBackground {
assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType()); assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
shape = slide.get(3).getShapes().get(0); shape = slide.get(3).getShapes().get(0);
assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType()); assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
ppt.close();
} }
/** /**
* Create a ppt with various fill effects * Create a ppt with various fill effects
*/ */
@Test @Test
public void backgroundPicture() throws Exception { public void backgroundPicture() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(); HSLFSlideShow ppt1 = new HSLFSlideShow();
HSLFSlide slide; HSLFSlide slide;
HSLFFill fill; HSLFFill fill;
HSLFShape shape; HSLFShape shape;
HSLFPictureData data; HSLFPictureData data;
//slide 1 //slide 1
slide = ppt.createSlide(); slide = ppt1.createSlide();
slide.setFollowMasterBackground(false); slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill(); fill = slide.getBackground().getFill();
data = ppt.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG); data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
fill.setFillType(HSLFFill.FILL_PICTURE); fill.setFillType(HSLFFill.FILL_PICTURE);
fill.setPictureData(data); fill.setPictureData(data);
@ -129,10 +130,10 @@ public final class TestBackground {
slide.addShape(shape); slide.addShape(shape);
//slide 2 //slide 2
slide = ppt.createSlide(); slide = ppt1.createSlide();
slide.setFollowMasterBackground(false); slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill(); fill = slide.getBackground().getFill();
data = ppt.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG); data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
fill.setFillType(HSLFFill.FILL_PATTERN); fill.setFillType(HSLFFill.FILL_PATTERN);
fill.setPictureData(data); fill.setPictureData(data);
fill.setBackgroundColor(Color.green); fill.setBackgroundColor(Color.green);
@ -145,10 +146,10 @@ public final class TestBackground {
slide.addShape(shape); slide.addShape(shape);
//slide 3 //slide 3
slide = ppt.createSlide(); slide = ppt1.createSlide();
slide.setFollowMasterBackground(false); slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill(); fill = slide.getBackground().getFill();
data = ppt.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG); data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
fill.setFillType(HSLFFill.FILL_TEXTURE); fill.setFillType(HSLFFill.FILL_TEXTURE);
fill.setPictureData(data); fill.setPictureData(data);
@ -156,12 +157,12 @@ public final class TestBackground {
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200)); shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill(); fill = shape.getFill();
fill.setFillType(HSLFFill.FILL_PICTURE); fill.setFillType(HSLFFill.FILL_PICTURE);
data = ppt.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG); data = ppt1.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
fill.setPictureData(data); fill.setPictureData(data);
slide.addShape(shape); slide.addShape(shape);
// slide 4 // slide 4
slide = ppt.createSlide(); slide = ppt1.createSlide();
slide.setFollowMasterBackground(false); slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill(); fill = slide.getBackground().getFill();
fill.setFillType(HSLFFill.FILL_SHADE_CENTER); fill.setFillType(HSLFFill.FILL_SHADE_CENTER);
@ -177,12 +178,8 @@ public final class TestBackground {
slide.addShape(shape); slide.addShape(shape);
//serialize and read again //serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream(); HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
ppt.write(out); List<HSLFSlide> slides = ppt2.getSlides();
out.close();
ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
List<HSLFSlide> slides = ppt.getSlides();
fill = slides.get(0).getBackground().getFill(); fill = slides.get(0).getBackground().getFill();
assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType()); assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
@ -206,6 +203,8 @@ public final class TestBackground {
assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType()); assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
shape = slides.get(3).getShapes().get(0); shape = slides.get(3).getShapes().get(0);
assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType()); assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
ppt2.close();
ppt1.close();
} }
private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) { private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) {

View File

@ -17,267 +17,263 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.util.List; import java.util.List;
import junit.framework.TestCase; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.record.Document;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.UserEditAtom;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/** /**
* Tests that SlideShow adds additional sheets properly * Tests that SlideShow adds additional sheets properly
*
* @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestAddingSlides extends TestCase { public final class TestAddingSlides {
// An empty SlideShow // An empty SlideShow
private HSLFSlideShowImpl hss_empty; private HSLFSlideShow ss_empty;
private HSLFSlideShow ss_empty;
// A SlideShow with one slide // A SlideShow with one slide
private HSLFSlideShowImpl hss_one; private HSLFSlideShow ss_one;
private HSLFSlideShow ss_one;
// A SlideShow with two slides // A SlideShow with two slides
private HSLFSlideShowImpl hss_two; private HSLFSlideShow ss_two;
private HSLFSlideShow ss_two;
/** /**
* Create/open the slideshows * Create/open the slideshows
*/ */
@Override @Before
public void setUp() throws Exception { public void setUp() throws IOException {
hss_empty = HSLFSlideShowImpl.create(); ss_empty = new HSLFSlideShow();
ss_empty = new HSLFSlideShow(hss_empty); ss_one = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt");
ss_two = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
}
POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); @After
public void tearDown() throws IOException {
ss_two.close();
ss_one.close();
ss_empty.close();
}
hss_one = new HSLFSlideShowImpl(slTests.openResourceAsStream("Single_Coloured_Page.ppt")); /**
ss_one = new HSLFSlideShow(hss_one); * Test adding a slide to an empty slideshow
*/
@Test
public void testAddSlideToEmpty() throws IOException {
// Doesn't have any slides
assertEquals(0, ss_empty.getSlides().size());
hss_two = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); // Should only have a master SLWT
ss_two = new HSLFSlideShow(hss_two); assertEquals(1,
} ss_empty.getDocumentRecord().getSlideListWithTexts().length);
/** // grab UserEditAtom
* Test adding a slide to an empty slideshow
*/
public void testAddSlideToEmpty() throws Exception {
// Doesn't have any slides
assertEquals(0, ss_empty.getSlides().size());
// Should only have a master SLWT
assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
//grab UserEditAtom
UserEditAtom usredit = null; UserEditAtom usredit = null;
Record[] _records = hss_empty.getRecords(); Record[] _records = ss_empty.getSlideShowImpl().getRecords();
for (Record record : _records) { for (Record record : _records) {
if(record.getRecordType() == RecordTypes.UserEditAtom.typeID) { if (record.getRecordType() == RecordTypes.UserEditAtom.typeID) {
usredit = (UserEditAtom)record; usredit = (UserEditAtom) record;
} }
} }
assertNotNull(usredit); assertNotNull(usredit);
// Add one // Add one
HSLFSlide slide = ss_empty.createSlide(); HSLFSlide slide = ss_empty.createSlide();
assertEquals(1, ss_empty.getSlides().size()); assertEquals(1, ss_empty.getSlides().size());
assertEquals(256, slide._getSheetNumber()); assertEquals(256, slide._getSheetNumber());
assertEquals(3, slide._getSheetRefId()); assertEquals(3, slide._getSheetRefId());
assertEquals(1, slide.getSlideNumber()); assertEquals(1, slide.getSlideNumber());
assertEquals(usredit.getMaxPersistWritten(), slide._getSheetRefId()); assertEquals(usredit.getMaxPersistWritten(), slide._getSheetRefId());
// Write out, and read back in // Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream(); HSLFSlideShow ss_read = HSLFTestDataSamples
hss_empty.write(baos); .writeOutAndReadBack(ss_empty);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais); // Check it now has a slide
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read); assertEquals(1, ss_read.getSlides().size());
// Check it now has a slide // Check it now has two SLWTs
assertEquals(1, ss_read.getSlides().size()); assertEquals(2,
ss_empty.getDocumentRecord().getSlideListWithTexts().length);
// Check it now has two SLWTs // And check it's as expected
assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length); slide = ss_read.getSlides().get(0);
assertEquals(256, slide._getSheetNumber());
assertEquals(3, slide._getSheetRefId());
assertEquals(1, slide.getSlideNumber());
ss_read.close();
}
// And check it's as expected /**
slide = ss_read.getSlides().get(0); * Test adding a slide to an existing slideshow
assertEquals(256, slide._getSheetNumber()); */
assertEquals(3, slide._getSheetRefId()); @Test
assertEquals(1, slide.getSlideNumber()); public void testAddSlideToExisting() throws IOException {
} // Has one slide
assertEquals(1, ss_one.getSlides().size());
HSLFSlide s1 = ss_one.getSlides().get(0);
/** // Should have two SLTWs
* Test adding a slide to an existing slideshow assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length);
*/
public void testAddSlideToExisting() throws Exception {
// Has one slide
assertEquals(1, ss_one.getSlides().size());
HSLFSlide s1 = ss_one.getSlides().get(0);
// Should have two SLTWs // Check slide 1 is as expected
assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length); assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
// Check slide 1 is as expected // Add a second one
assertEquals(256, s1._getSheetNumber()); HSLFSlide s2 = ss_one.createSlide();
assertEquals(3, s1._getSheetRefId()); assertEquals(2, ss_one.getSlides().size());
assertEquals(1, s1.getSlideNumber()); assertEquals(257, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
// Add a second one // Write out, and read back in
HSLFSlide s2 = ss_one.createSlide(); HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_one);
assertEquals(2, ss_one.getSlides().size());
assertEquals(257, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
// Write out, and read back in // Check it now has two slides
ByteArrayOutputStream baos = new ByteArrayOutputStream(); assertEquals(2, ss_read.getSlides().size());
hss_one.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais); // Should still have two SLTWs
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read); assertEquals(2,
ss_read.getDocumentRecord().getSlideListWithTexts().length);
// Check it now has two slides // And check it's as expected
assertEquals(2, ss_read.getSlides().size()); s1 = ss_read.getSlides().get(0);
s2 = ss_read.getSlides().get(1);
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
assertEquals(257, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
ss_read.close();
}
// Should still have two SLTWs /**
assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length); * Test adding a slide to an existing slideshow, with two slides already
*/
// And check it's as expected @Test
s1 = ss_read.getSlides().get(0); public void testAddSlideToExisting2() throws IOException {
s2 = ss_read.getSlides().get(1); // grab UserEditAtom
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
assertEquals(257, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
}
/**
* Test adding a slide to an existing slideshow,
* with two slides already
*/
@SuppressWarnings("unused")
public void testAddSlideToExisting2() throws Exception {
//grab UserEditAtom
UserEditAtom usredit = null; UserEditAtom usredit = null;
Record[] _records = hss_two.getRecords(); Record[] _records = ss_two.getSlideShowImpl().getRecords();
for (Record record : _records) { for (Record record : _records) {
if(record.getRecordType() == RecordTypes.UserEditAtom.typeID) { if (record.getRecordType() == RecordTypes.UserEditAtom.typeID) {
usredit = (UserEditAtom)record; usredit = (UserEditAtom) record;
} }
} }
assertNotNull(usredit); assertNotNull(usredit);
// Has two slides // Has two slides
assertEquals(2, ss_two.getSlides().size()); assertEquals(2, ss_two.getSlides().size());
HSLFSlide s1 = ss_two.getSlides().get(0); HSLFSlide s1 = ss_two.getSlides().get(0);
HSLFSlide s2 = ss_two.getSlides().get(1); HSLFSlide s2 = ss_two.getSlides().get(1);
// Check slide 1 is as expected // Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber()); assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId()); // master has notes assertEquals(4, s1._getSheetRefId()); // master has notes
assertEquals(1, s1.getSlideNumber()); assertEquals(1, s1.getSlideNumber());
// Check slide 2 is as expected // Check slide 2 is as expected
assertEquals(257, s2._getSheetNumber()); assertEquals(257, s2._getSheetNumber());
assertEquals(6, s2._getSheetRefId()); // master and 1 have notes assertEquals(6, s2._getSheetRefId()); // master and 1 have notes
assertEquals(2, s2.getSlideNumber()); assertEquals(2, s2.getSlideNumber());
// Add a third one // Add a third one
HSLFSlide s3 = ss_two.createSlide(); HSLFSlide s3 = ss_two.createSlide();
assertEquals(3, ss_two.getSlides().size()); assertEquals(3, ss_two.getSlides().size());
assertEquals(258, s3._getSheetNumber()); assertEquals(258, s3._getSheetNumber());
assertEquals(8, s3._getSheetRefId()); // lots of notes before us assertEquals(8, s3._getSheetRefId()); // lots of notes before us
assertEquals(3, s3.getSlideNumber()); assertEquals(3, s3.getSlideNumber());
assertEquals(usredit.getMaxPersistWritten(), s3._getSheetRefId()); assertEquals(usredit.getMaxPersistWritten(), s3._getSheetRefId());
// Write out, and read back in // Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream(); HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two);
hss_two.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais); // Check it now has three slides
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read); assertEquals(3, ss_read.getSlides().size());
// Check it now has three slides // And check it's as expected
assertEquals(3, ss_read.getSlides().size()); s1 = ss_read.getSlides().get(0);
s2 = ss_read.getSlides().get(1);
// And check it's as expected s3 = ss_read.getSlides().get(2);
s1 = ss_read.getSlides().get(0); assertEquals(256, s1._getSheetNumber());
s2 = ss_read.getSlides().get(1); assertEquals(4, s1._getSheetRefId());
s3 = ss_read.getSlides().get(2); assertEquals(1, s1.getSlideNumber());
assertEquals(256, s1._getSheetNumber()); assertEquals(257, s2._getSheetNumber());
assertEquals(4, s1._getSheetRefId()); assertEquals(6, s2._getSheetRefId());
assertEquals(1, s1.getSlideNumber()); assertEquals(2, s2.getSlideNumber());
assertEquals(257, s2._getSheetNumber()); assertEquals(258, s3._getSheetNumber());
assertEquals(6, s2._getSheetRefId()); assertEquals(8, s3._getSheetRefId());
assertEquals(2, s2.getSlideNumber()); assertEquals(3, s3.getSlideNumber());
assertEquals(258, s3._getSheetNumber()); ss_read.close();
assertEquals(8, s3._getSheetRefId()); }
assertEquals(3, s3.getSlideNumber());
}
/** /**
* Test SlideShow#removeSlide * Test SlideShow#removeSlide
*/ */
public void testRemoving() throws Exception { @Test
HSLFSlideShow ppt = new HSLFSlideShow(); public void testRemoving() throws IOException {
HSLFSlide slide1 = ppt.createSlide(); HSLFSlide slide1 = ss_empty.createSlide();
HSLFSlide slide2 = ppt.createSlide(); HSLFSlide slide2 = ss_empty.createSlide();
List<HSLFSlide> s1 = ppt.getSlides(); List<HSLFSlide> s1 = ss_empty.getSlides();
assertEquals(2, s1.size()); assertEquals(2, s1.size());
try { try {
ppt.removeSlide(-1); ss_empty.removeSlide(-1);
fail("expected exception"); fail("expected exception");
} catch (Exception e){ } catch (Exception e) {
} }
try { try {
ppt.removeSlide(2); ss_empty.removeSlide(2);
fail("expected exception"); fail("expected exception");
} catch (Exception e){ } catch (Exception e) {
} }
assertEquals(1, slide1.getSlideNumber()); assertEquals(1, slide1.getSlideNumber());
HSLFSlide removedSlide = ppt.removeSlide(0); HSLFSlide removedSlide = ss_empty.removeSlide(0);
List<HSLFSlide> s2 = ppt.getSlides(); List<HSLFSlide> s2 = ss_empty.getSlides();
assertEquals(1, s2.size()); assertEquals(1, s2.size());
assertSame(slide1, removedSlide); assertSame(slide1, removedSlide);
assertSame(slide2, s2.get(0)); assertSame(slide2, s2.get(0));
assertEquals(0, slide2.getSlideNumber()); assertEquals(0, slide2.getSlideNumber());
ByteArrayOutputStream out = new ByteArrayOutputStream(); HSLFSlideShow ss_read = HSLFTestDataSamples
ppt.write(out); .writeOutAndReadBack(ss_empty);
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())); List<HSLFSlide> s3 = ss_read.getSlides();
List<HSLFSlide> s3 = ppt.getSlides();
assertEquals(1, s3.size()); assertEquals(1, s3.size());
ss_read.close();
} }
@Test
public void test47261() throws Exception { public void test47261() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("47261.ppt");
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("47261.ppt"));
List<HSLFSlide> slides = ppt.getSlides(); List<HSLFSlide> slides = ppt.getSlides();
Document doc = ppt.getDocumentRecord(); Document doc = ppt.getDocumentRecord();
assertNotNull(doc.getSlideSlideListWithText()); assertNotNull(doc.getSlideSlideListWithText());
assertEquals(14, ppt.getSlides().size()); assertEquals(14, ppt.getSlides().size());
int notesId = slides.get(0).getSlideRecord().getSlideAtom().getNotesID(); int notesId = slides.get(0).getSlideRecord().getSlideAtom()
.getNotesID();
assertTrue(notesId > 0); assertTrue(notesId > 0);
assertNotNull(doc.getNotesSlideListWithText()); assertNotNull(doc.getNotesSlideListWithText());
assertEquals(14, doc.getNotesSlideListWithText().getSlideAtomsSets().length); assertEquals(14, doc.getNotesSlideListWithText().getSlideAtomsSets().length);
//remove all slides, corresponding notes should be removed too // remove all slides, corresponding notes should be removed too
for (int i = slides.size(); i > 0; i--) { for (int i = slides.size(); i > 0; i--) {
ppt.removeSlide(0); ppt.removeSlide(0);
} }
@ -285,6 +281,6 @@ public final class TestAddingSlides extends TestCase {
assertEquals(0, ppt.getNotes().size()); assertEquals(0, ppt.getNotes().size());
assertNull(doc.getSlideSlideListWithText()); assertNull(doc.getSlideSlideListWithText());
assertNull(doc.getNotesSlideListWithText()); assertNull(doc.getNotesSlideListWithText());
ppt.close();
} }
} }

View File

@ -17,16 +17,25 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.*;
import static org.apache.poi.POITestCase.assertContains; import static org.apache.poi.POITestCase.assertContains;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.*; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.SlideListWithText;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -36,46 +45,43 @@ import org.junit.Test;
* (model.TestTextRun tests the other functionality) * (model.TestTextRun tests the other functionality)
*/ */
public final class TestRichTextRun { public final class TestRichTextRun {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
// SlideShow primed on the test data // SlideShow primed on the test data
private HSLFSlideShow ss; private HSLFSlideShow ss;
private HSLFSlideShow ssRichA; private HSLFSlideShow ssRichA;
private HSLFSlideShow ssRichB; private HSLFSlideShow ssRichB;
private HSLFSlideShow ssRichC; private HSLFSlideShow ssRichC;
private HSLFSlideShow ssChinese; private HSLFSlideShow ssChinese;
private HSLFSlideShowImpl hss;
private HSLFSlideShowImpl hssRichA;
private HSLFSlideShowImpl hssRichB;
private HSLFSlideShowImpl hssRichC;
private HSLFSlideShowImpl hssChinese;
private static String filenameC; private static String filenameC;
@Before @Before
public void setUp() throws Exception { public void setUp() throws IOException {
// Basic (non rich) test file // Basic (non rich) test file
hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("basic_test_ppt_file.ppt")); ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
ss = new HSLFSlideShow(hss);
// Rich test file A // Rich test file A
hssRichA = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page.ppt")); ssRichA = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt");
ssRichA = new HSLFSlideShow(hssRichA);
// Rich test file B // Rich test file B
hssRichB = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page_With_Fonts_and_Alignments.ppt")); ssRichB = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page_With_Fonts_and_Alignments.ppt");
ssRichB = new HSLFSlideShow(hssRichB);
// Rich test file C - has paragraph styles that run out before // Rich test file C - has paragraph styles that run out before
// the character ones do // the character ones do
filenameC = "ParagraphStylesShorterThanCharStyles.ppt"; filenameC = "ParagraphStylesShorterThanCharStyles.ppt";
hssRichC = new HSLFSlideShowImpl(_slTests.openResourceAsStream(filenameC)); ssRichC = HSLFTestDataSamples.getSlideShow(filenameC);
ssRichC = new HSLFSlideShow(hssRichC);
// Rich test file with Chinese + English text in it // Rich test file with Chinese + English text in it
hssChinese = new HSLFSlideShowImpl(_slTests.openResourceAsStream("54880_chinese.ppt")); ssChinese = HSLFTestDataSamples.getSlideShow("54880_chinese.ppt");
ssChinese = new HSLFSlideShow(hssChinese);
} }
@After
public void tearDown() throws IOException {
ss.close();
ssRichA.close();
ssRichB.close();
ssRichC.close();
ssChinese.close();
}
/** /**
* Test the stuff about getting/setting bold * Test the stuff about getting/setting bold
* on a non rich text run * on a non rich text run
@ -201,7 +207,7 @@ public final class TestRichTextRun {
} }
@Test @Test
public void testChangeWriteRead() throws Exception { public void testChangeWriteRead() throws IOException {
for(HSLFSlideShow h : new HSLFSlideShow[] { ss, ssRichA, ssRichB }) { for(HSLFSlideShow h : new HSLFSlideShow[] { ss, ssRichA, ssRichB }) {
// Change // Change
HSLFSlide slideOne = h.getSlides().get(0); HSLFSlide slideOne = h.getSlides().get(0);
@ -219,12 +225,7 @@ public final class TestRichTextRun {
assertEquals("Courier", rtr.getFontFamily()); assertEquals("Courier", rtr.getFontFamily());
// Write out and back in // Write out and back in
ByteArrayOutputStream baos = new ByteArrayOutputStream(); HSLFSlideShow readS = HSLFTestDataSamples.writeOutAndReadBack(h);
h.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
HSLFSlideShowImpl readHSLF = new HSLFSlideShowImpl(bais);
HSLFSlideShow readS = new HSLFSlideShow(readHSLF);
// Tweak existing one again, to ensure really worked // Tweak existing one again, to ensure really worked
rtr.setBold(false); rtr.setBold(false);
@ -246,6 +247,7 @@ public final class TestRichTextRun {
assertTrue(rtrRRa.isBold()); assertTrue(rtrRRa.isBold());
assertEquals(18., rtrRRa.getFontSize(), 0); assertEquals(18., rtrRRa.getFontSize(), 0);
assertEquals("Courier", rtrRRa.getFontFamily()); assertEquals("Courier", rtrRRa.getFontFamily());
readS.close();
} }
} }
@ -314,7 +316,7 @@ public final class TestRichTextRun {
*/ */
@Test @Test
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void testParagraphStylesShorterTheCharStylesWrite() throws Exception { public void testParagraphStylesShorterTheCharStylesWrite() throws IOException {
assertMatchesSLTWC(ssRichC); assertMatchesSLTWC(ssRichC);
assertMatchesFileC(ssRichC); assertMatchesFileC(ssRichC);
@ -361,9 +363,9 @@ public final class TestRichTextRun {
* contents. * contents.
* @param s * @param s
*/ */
private void assertMatchesSLTWC(HSLFSlideShow s) throws Exception { private void assertMatchesSLTWC(HSLFSlideShow s) throws IOException {
// Grab a new copy of slideshow C // Grab a new copy of slideshow C
HSLFSlideShow refC = new HSLFSlideShow(_slTests.openResourceAsStream(filenameC)); HSLFSlideShow refC = HSLFTestDataSamples.getSlideShow(filenameC);
// Write out the 2nd SLWT in the active document // Write out the 2nd SLWT in the active document
SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1]; SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1];
@ -392,26 +394,22 @@ public final class TestRichTextRun {
* Checks that the supplied slideshow still matches the bytes * Checks that the supplied slideshow still matches the bytes
* of slideshow c * of slideshow c
*/ */
private static void assertMatchesFileC(HSLFSlideShow s) throws Exception { private static void assertMatchesFileC(HSLFSlideShow s) throws IOException {
// Grab the bytes of the file // Grab the bytes of the file
NPOIFSFileSystem fs = new NPOIFSFileSystem(_slTests.getFile(filenameC)); NPOIFSFileSystem fs = new NPOIFSFileSystem(HSLFTestDataSamples.openSampleFileStream(filenameC));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = fs.createDocumentInputStream("PowerPoint Document"); InputStream is = fs.createDocumentInputStream("PowerPoint Document");
IOUtils.copy(is, baos); byte[] raw_file = IOUtils.toByteArray(is);
is.close(); is.close();
fs.close(); fs.close();
byte[] raw_file = baos.toByteArray();
// Now write out the slideshow // Now write out the slideshow
baos.reset(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
s.write(baos); s.write(baos);
fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray())); fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
baos.reset();
is = fs.createDocumentInputStream("PowerPoint Document"); is = fs.createDocumentInputStream("PowerPoint Document");
IOUtils.copy(is, baos); byte[] raw_ss = IOUtils.toByteArray(is);
is.close(); is.close();
fs.close(); fs.close();
byte[] raw_ss = baos.toByteArray();
// different paragraph mask, because of sanitizing // different paragraph mask, because of sanitizing
raw_ss[169030] = 0x0a; raw_ss[169030] = 0x0a;
@ -420,7 +418,7 @@ public final class TestRichTextRun {
assertArrayEquals(raw_file, raw_ss); assertArrayEquals(raw_file, raw_ss);
} }
private byte[] writeRecord(Record r) throws Exception { private byte[] writeRecord(Record r) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos); r.writeOut(baos);
return baos.toByteArray(); return baos.toByteArray();
@ -428,7 +426,7 @@ public final class TestRichTextRun {
@Test @Test
public void testIndentationLevel() throws Exception { public void testIndentationLevel() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("ParagraphStylesShorterThanCharStyles.ppt");
for (HSLFSlide sl : ppt.getSlides()) { for (HSLFSlide sl : ppt.getSlides()) {
for (List<HSLFTextParagraph> txt : sl.getTextParagraphs()) { for (List<HSLFTextParagraph> txt : sl.getTextParagraphs()) {
for (HSLFTextParagraph p : txt) { for (HSLFTextParagraph p : txt) {
@ -438,11 +436,12 @@ public final class TestRichTextRun {
} }
} }
ppt.close();
} }
@Test @Test
public void testReadParagraphStyles() throws Exception { public void testReadParagraphStyles() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("bullets.ppt");
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
HSLFTextParagraph rt; HSLFTextParagraph rt;
@ -492,13 +491,14 @@ public final class TestRichTextRun {
rt = txt.get(1).get(0); rt = txt.get(1).get(0);
assertTrue(rt.isBullet()); assertTrue(rt.isBullet());
assertEquals('\u263A', (char)rt.getBulletChar()); assertEquals('\u263A', (char)rt.getBulletChar());
ppt.close();
} }
@Test @Test
public void testSetParagraphStyles() throws Exception { public void testSetParagraphStyles() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(); HSLFSlideShow ppt1 = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt1.createSlide();
HSLFTextBox shape = new HSLFTextBox(); HSLFTextBox shape = new HSLFTextBox();
shape.setText( shape.setText(
@ -524,12 +524,8 @@ public final class TestRichTextRun {
slide.addShape(shape); slide.addShape(shape);
//serialize and read again //serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream(); HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
ppt.write(out); slide = ppt2.getSlides().get(0);
out.close();
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides().get(0);
shape = (HSLFTextBox)slide.getShapes().get(0); shape = (HSLFTextBox)slide.getShapes().get(0);
rt = shape.getTextParagraphs().get(0); rt = shape.getTextParagraphs().get(0);
tr = rt.getTextRuns().get(0); tr = rt.getTextRuns().get(0);
@ -538,17 +534,19 @@ public final class TestRichTextRun {
assertEquals(50.0, rt.getLeftMargin(), 0); assertEquals(50.0, rt.getLeftMargin(), 0);
assertEquals(0, rt.getIndent(), 0); assertEquals(0, rt.getIndent(), 0);
assertEquals('\u263A', (char)rt.getBulletChar()); assertEquals('\u263A', (char)rt.getBulletChar());
ppt2.close();
ppt1.close();
} }
@Test @Test
public void testAddText() throws Exception { public void testAddText() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt")); HSLFSlideShow ppt1 = HSLFTestDataSamples.getSlideShow("bullets.ppt");
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
HSLFTextParagraph rt; HSLFTextParagraph rt;
HSLFTextRun tr; HSLFTextRun tr;
List<List<HSLFTextParagraph>> txt; List<List<HSLFTextParagraph>> txt;
List<HSLFSlide> slides = ppt.getSlides(); List<HSLFSlide> slides = ppt1.getSlides();
assertEquals(2, slides.size()); assertEquals(2, slides.size());
txt = slides.get(0).getTextParagraphs(); txt = slides.get(0).getTextParagraphs();
@ -592,12 +590,8 @@ public final class TestRichTextRun {
assertEquals("Me too!", tr.getRawText()); assertEquals("Me too!", tr.getRawText());
// Save and re-open // Save and re-open
ByteArrayOutputStream out = new ByteArrayOutputStream(); HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
ppt.write(out); slides = ppt2.getSlides();
out.close();
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slides = ppt.getSlides();
assertEquals(2, slides.size()); assertEquals(2, slides.size());
@ -616,9 +610,8 @@ public final class TestRichTextRun {
tr = rt.getTextRuns().get(0); tr = rt.getTextRuns().get(0);
assertTrue(tr.isBold()); assertTrue(tr.isBold());
assertEquals("Me too!", tr.getRawText()); assertEquals("Me too!", tr.getRawText());
ppt2.close();
// FileOutputStream fout = new FileOutputStream("/tmp/foo.ppt"); ppt1.close();
// ppt.write(fout);
} }
@Test @Test

View File

@ -19,28 +19,31 @@ package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* Tests that SlideShow returns Sheets which have the right text in them * Tests that SlideShow returns Sheets which have the right text in them
*
* @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestSheetText { public final class TestSheetText {
// SlideShow primed on the test data // SlideShow primed on the test data
private HSLFSlideShow ss; private HSLFSlideShow ss;
@Before @Before
public void init() throws Exception { public void init() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new HSLFSlideShow(hss);
} }
@After
public void tearDown() throws IOException {
ss.close();
}
@Test @Test
public void testSheetOne() { public void testSheetOne() {
HSLFSheet slideOne = ss.getSlides().get(0); HSLFSheet slideOne = ss.getSlides().get(0);
@ -68,10 +71,8 @@ public final class TestSheetText {
* TextProps don't have enough data. * TextProps don't have enough data.
* (Make sure we don't screw up / throw an exception etc) * (Make sure we don't screw up / throw an exception etc)
*/ */
public void testWithShortTextPropData() throws Exception { public void testWithShortTextPropData() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); HSLFSlideShow sss = HSLFTestDataSamples.getSlideShow("iisd_report.ppt");
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("iisd_report.ppt"));
HSLFSlideShow sss = new HSLFSlideShow(hss);
// Should come out with 10 slides, no notes // Should come out with 10 slides, no notes
assertEquals(10, sss.getSlides().size()); assertEquals(10, sss.getSlides().size());
@ -90,5 +91,6 @@ public final class TestSheetText {
assertEquals(1, s.getTextParagraphs().size()); assertEquals(1, s.getTextParagraphs().size());
assertEquals(exp, HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0))); assertEquals(exp, HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
sss.close();
} }
} }

View File

@ -19,32 +19,33 @@ package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* Tests that SlideShow returns Sheets in the right order * Tests that SlideShow returns Sheets in the right order
*
* @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestSlideOrdering { public final class TestSlideOrdering {
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
// Simple slideshow, record order matches slide order // Simple slideshow, record order matches slide order
private HSLFSlideShow ssA; private HSLFSlideShow ssA;
// Complex slideshow, record order doesn't match slide order // Complex slideshow, record order doesn't match slide order
private HSLFSlideShow ssB; private HSLFSlideShow ssB;
@Before @Before
public void init() throws Exception { public void init() throws IOException {
HSLFSlideShowImpl hssA = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); ssA = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
ssA = new HSLFSlideShow(hssA); ssB = HSLFTestDataSamples.getSlideShow("incorrect_slide_order.ppt");
}
HSLFSlideShowImpl hssB = new HSLFSlideShowImpl(slTests.openResourceAsStream("incorrect_slide_order.ppt")); @After
ssB = new HSLFSlideShow(hssB); public void tearDown() throws IOException {
ssA.close();
ssB.close();
} }
/** /**
@ -83,10 +84,8 @@ public final class TestSlideOrdering {
* @param titles * @param titles
* array of reference slide titles * array of reference slide titles
*/ */
protected void assertSlideOrdering(String filename, String[] titles) throws Exception { protected void assertSlideOrdering(String filename, String[] titles) throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow(filename);
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream(filename));
List<HSLFSlide> slide = ppt.getSlides(); List<HSLFSlide> slide = ppt.getSlides();
assertEquals(titles.length, slide.size()); assertEquals(titles.length, slide.size());
@ -94,6 +93,7 @@ public final class TestSlideOrdering {
String title = slide.get(i).getTitle(); String title = slide.get(i).getTitle();
assertEquals("Wrong slide title in " + filename, titles[i], title); assertEquals("Wrong slide title in " + filename, titles[i], title);
} }
ppt.close();
} }
@Test @Test

View File

@ -18,30 +18,29 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.junit.Test;
/** /**
* Test reading sound data from a ppt * Test reading sound data from a ppt
*
* @author Yegor Kozlov
*/ */
public final class TestSoundData extends TestCase{ public final class TestSoundData {
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
/** /**
* Read a reference sound file from disk and compare it from the data extracted from the slide show * Read a reference sound file from disk and compare it from the data extracted from the slide show
*/ */
@Test
public void testSounds() throws Exception { public void testSounds() throws Exception {
//read the reference sound file //read the reference sound file
byte[] ref_data = slTests.readFile("ringin.wav"); byte[] ref_data = HSLFTestDataSamples.getTestDataFileContent("ringin.wav");
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("sound.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("sound.ppt");
HSLFSoundData[] sound = ppt.getSoundData(); HSLFSoundData[] sound = ppt.getSoundData();
assertEquals("Expected 1 sound", 1, sound.length); assertEquals("Expected 1 sound", 1, sound.length);
assertArrayEquals(ref_data, sound[0].getData()); assertArrayEquals(ref_data, sound[0].getData());
ppt.close();
} }
} }

View File

@ -31,7 +31,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.sl.draw.DrawTableShape; import org.apache.poi.sl.draw.DrawTableShape;
import org.apache.poi.sl.usermodel.StrokeStyle; import org.apache.poi.sl.usermodel.StrokeStyle;
import org.junit.Test; import org.junit.Test;
@ -41,8 +41,6 @@ import org.junit.Test;
* Table related tests * Table related tests
*/ */
public class TestTable { public class TestTable {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@Test @Test
public void moveTable() throws IOException { public void moveTable() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(); HSLFSlideShow ppt = new HSLFSlideShow();
@ -68,7 +66,7 @@ public class TestTable {
@Test @Test
public void testTable() throws IOException { public void testTable() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("54111.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("54111.ppt");
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
List<HSLFSlide> slides = ppt.getSlides(); List<HSLFSlide> slides = ppt.getSlides();

View File

@ -26,42 +26,42 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.TextBytesAtom; import org.apache.poi.hslf.record.TextBytesAtom;
import org.apache.poi.hslf.record.TextCharsAtom; import org.apache.poi.hslf.record.TextCharsAtom;
import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextHeaderAtom;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* Tests for TextRuns * Tests for TextRuns
*
* @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestTextRun { public final class TestTextRun {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
// SlideShow primed on the test data // SlideShow primed on the test data
private HSLFSlideShow ss; private HSLFSlideShow ss;
private HSLFSlideShow ssRich; private HSLFSlideShow ssRich;
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
// Basic (non rich) test file // Basic (non rich) test file
ss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt")); ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
// Rich test file // Rich test file
ssRich = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page.ppt")); ssRich = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt");
} }
@After
public void tearDown() throws IOException {
ssRich.close();
ss.close();
}
/** /**
* Test to ensure that getting the text works correctly * Test to ensure that getting the text works correctly
*/ */
@ -441,7 +441,7 @@ public final class TestTextRun {
public void testBug41015() throws IOException { public void testBug41015() throws IOException {
List<HSLFTextRun> rt; List<HSLFTextRun> rt;
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug-41015.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("bug-41015.ppt");
HSLFSlide sl = ppt.getSlides().get(0); HSLFSlide sl = ppt.getSlides().get(0);
List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs(); List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
assertEquals(2, textParass.size()); assertEquals(2, textParass.size());
@ -461,13 +461,14 @@ public final class TestTextRun {
assertEquals(indents[i], p.getIndentLevel()); assertEquals(indents[i], p.getIndentLevel());
i++; i++;
} }
ppt.close();
} }
/** /**
* Test creation of TextRun objects. * Test creation of TextRun objects.
*/ */
@Test @Test
public void testAddTextRun() { public void testAddTextRun() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(); HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide(); HSLFSlide slide = ppt.createSlide();
@ -511,12 +512,13 @@ public final class TestTextRun {
runs = slide2.getTextParagraphs(); runs = slide2.getTextParagraphs();
assertNotNull(runs); assertNotNull(runs);
assertEquals(4, runs.size()); assertEquals(4, runs.size());
ppt.close();
} }
@Test @Test
public void test48916() throws IOException { public void test48916() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("SampleShow.ppt")); HSLFSlideShow ppt1 = HSLFTestDataSamples.getSlideShow("SampleShow.ppt");
List<HSLFSlide> slides = ppt.getSlides(); List<HSLFSlide> slides = ppt1.getSlides();
for(HSLFSlide slide : slides){ for(HSLFSlide slide : slides){
for(HSLFShape sh : slide.getShapes()){ for(HSLFShape sh : slide.getShapes()){
if (!(sh instanceof HSLFTextShape)) continue; if (!(sh instanceof HSLFTextShape)) continue;
@ -539,11 +541,9 @@ public final class TestTextRun {
// tx.storeText(); // tx.storeText();
} }
} }
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())); HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
for(HSLFSlide slide : ppt.getSlides()){ for(HSLFSlide slide : ppt2.getSlides()){
for(HSLFShape sh : slide.getShapes()){ for(HSLFShape sh : slide.getShapes()){
if(sh instanceof HSLFTextShape){ if(sh instanceof HSLFTextShape){
HSLFTextShape tx = (HSLFTextShape)sh; HSLFTextShape tx = (HSLFTextShape)sh;
@ -554,12 +554,13 @@ public final class TestTextRun {
} }
} }
} }
ppt2.close();
ppt1.close();
} }
@Test @Test
public void test52244() throws IOException { public void test52244() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52244.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("52244.ppt");
HSLFSlide slide = ppt.getSlides().get(0); HSLFSlide slide = ppt.getSlides().get(0);
int sizes[] = { 36, 24, 12, 32, 12, 12 }; int sizes[] = { 36, 24, 12, 32, 12, 12 };
@ -569,6 +570,7 @@ public final class TestTextRun {
assertEquals("Arial", textParas.get(0).getTextRuns().get(0).getFontFamily()); assertEquals("Arial", textParas.get(0).getTextRuns().get(0).getFontFamily());
assertEquals(sizes[i++], textParas.get(0).getTextRuns().get(0).getFontSize().intValue()); assertEquals(sizes[i++], textParas.get(0).getTextRuns().get(0).getFontSize().intValue());
} }
ppt.close();
} }
@Test @Test
@ -579,5 +581,6 @@ public final class TestTextRun {
title.setText(""); title.setText("");
title.appendText("\n", true); title.appendText("\n", true);
title.appendText("para", true); title.appendText("para", true);
ppt.close();
} }
} }

View File

@ -17,24 +17,29 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.*; import java.io.ByteArrayInputStream;
import java.util.*; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.POIDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
import org.junit.Test; import org.junit.Test;
/** /**
* Verify behavior of <code>TextShape</code> and its sub-classes * Verify behavior of <code>TextShape</code> and its sub-classes
*
* @author Yegor Kozlov
*/ */
public final class TestTextShape { public final class TestTextShape {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@Test @Test
public void createAutoShape(){ public void createAutoShape(){
HSLFTextShape shape = new HSLFAutoShape(ShapeType.TRAPEZOID); HSLFTextShape shape = new HSLFAutoShape(ShapeType.TRAPEZOID);
@ -67,7 +72,7 @@ public final class TestTextShape {
*/ */
@Test @Test
public void read() throws IOException { public void read() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text_shapes.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("text_shapes.ppt");
List<String> lst1 = new ArrayList<String>(); List<String> lst1 = new ArrayList<String>();
HSLFSlide slide = ppt.getSlides().get(0); HSLFSlide slide = ppt.getSlides().get(0);
@ -85,10 +90,11 @@ public final class TestTextShape {
assertEquals("Text in a TextBox", rawText); assertEquals("Text in a TextBox", rawText);
break; break;
case RECT: case RECT:
if(runType == TextHeaderAtom.OTHER_TYPE) if(runType == TextHeaderAtom.OTHER_TYPE) {
assertEquals("Rectangle", rawText); assertEquals("Rectangle", rawText);
else if(runType == TextHeaderAtom.TITLE_TYPE) } else if(runType == TextHeaderAtom.TITLE_TYPE) {
assertEquals("Title Placeholder", rawText); assertEquals("Title Placeholder", rawText);
}
break; break;
case OCTAGON: case OCTAGON:
assertEquals("Octagon", rawText); assertEquals("Octagon", rawText);
@ -112,6 +118,7 @@ public final class TestTextShape {
} }
assertTrue(lst1.containsAll(lst2)); assertTrue(lst1.containsAll(lst2));
ppt.close();
} }
@Test @Test
@ -147,11 +154,12 @@ public final class TestTextShape {
shape1 = (HSLFTextShape)shape.get(1); shape1 = (HSLFTextShape)shape.get(1);
assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType()); assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType());
assertEquals("Testing TextShape", shape1.getText()); assertEquals("Testing TextShape", shape1.getText());
ppt.close();
} }
@Test @Test
public void margins() throws IOException { public void margins() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text-margins.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("text-margins.ppt");
HSLFSlide slide = ppt.getSlides().get(0); HSLFSlide slide = ppt.getSlides().get(0);
@ -188,11 +196,13 @@ public final class TestTextShape {
assertEquals(28.34, tx.getRightInset(), 0.01); assertEquals(28.34, tx.getRightInset(), 0.01);
assertEquals(3.6, tx.getTopInset(), 0); assertEquals(3.6, tx.getTopInset(), 0);
assertEquals(3.6, tx.getBottomInset(), 0); assertEquals(3.6, tx.getBottomInset(), 0);
ppt.close();
} }
@Test @Test
public void bug52599() throws IOException { public void bug52599() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52599.ppt")); HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("52599.ppt");
HSLFSlide slide = ppt.getSlides().get(0); HSLFSlide slide = ppt.getSlides().get(0);
List<HSLFShape> sh = slide.getShapes(); List<HSLFShape> sh = slide.getShapes();
@ -209,5 +219,6 @@ public final class TestTextShape {
HSLFTextShape sh2 = (HSLFTextShape)sh.get(2); HSLFTextShape sh2 = (HSLFTextShape)sh.get(2);
assertEquals("this box should be shown just once", sh2.getText()); assertEquals("this box should be shown just once", sh2.getText());
assertEquals(-1, sh2.getTextParagraphs().get(0).getIndex()); assertEquals(-1, sh2.getTextParagraphs().get(0).getIndex());
ppt.close();
} }
} }