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.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
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
*
* @author Yegor Kozlov
*/
public final class PPT2PNG {
public static void main(String args[]) throws Exception {
public static void main(String args[]) throws IOException {
if (args.length == 0) {
usage();
@ -74,7 +73,9 @@ public final class PPT2PNG {
int height = (int)(pgsize.height*scale);
for (HSLFSlide slide : ppt.getSlides()) {
if (slidenum != -1 && slidenum != slide.getSlideNumber()) continue;
if (slidenum != -1 && slidenum != slide.getSlideNumber()) {
continue;
}
String title = slide.getTitle();
System.out.println("Rendering slide "+slide.getSlideNumber() + (title == null ? "" : ": " + title));
@ -98,6 +99,8 @@ public final class PPT2PNG {
ImageIO.write(img, "png", out);
out.close();
}
ppt.close();
}
private static void usage(){

View File

@ -19,6 +19,8 @@
package org.apache.poi.xslf.usermodel.tutorial;
import java.io.FileInputStream;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFShape;
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.XSLFTextShape;
import java.io.FileInputStream;
/**
* Reading a .pptx presentation and printing basic shape properties
*
* @author Yegor Kozlov
*/
public class Step1 {
@ -41,7 +39,9 @@ public class Step1 {
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()){
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
*
* @author Yegor Kozlov
*/
public class Step2 {
public static void main(String[] args) throws Exception{
XMLSlideShow ppt = new XMLSlideShow();
// first see what slide layouts are available by default
System.out.println("Available slide layouts:");
for(XSLFSlideMaster master : ppt.getSlideMasters()){
@ -75,6 +72,6 @@ public class Step2 {
FileOutputStream out = new FileOutputStream("step2.pptx");
ppt.write(out);
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.SlideShow;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
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
* understanding DocSlideList and DocNotesList) - handle Slide creation cleaner
*
* @author Nick Burch
* @author Yegor kozlov
*/
public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable {
enum LoadSavePhase {
@ -211,14 +209,18 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
// Now convert the byte offsets back into record offsets
for (Record record : _hslfSlideShow.getRecords()) {
if (!(record instanceof PositionDependentRecord)) continue;
if (!(record instanceof PositionDependentRecord)) {
continue;
}
PositionDependentRecord pdr = (PositionDependentRecord) record;
int recordAt = pdr.getLastOnDiskOffset();
Integer thisID = mostRecentByBytesRev.get(recordAt);
if (thisID == null) continue;
if (thisID == null) {
continue;
}
// Bingo. Now, where do we store it?
int storeAt = _sheetIdToCoreRecordsLookup.get(thisID);
@ -470,7 +472,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
for (HSLFTextParagraph p : hts.getTextParagraphs()) {
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);
int i=0;
for (HSLFSlide s : _slides) s.setSlideNumber(i++);
for (HSLFSlide s : _slides) {
s.setSlideNumber(i++);
}
for (SlideAtomsSet s : sa) {
records.add(s.getSlidePersistAtom());
@ -653,7 +659,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
records = new ArrayList<Record>();
ArrayList<SlideAtomsSet> na = new ArrayList<SlideAtomsSet>();
for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) {
if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) continue;
if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) {
continue;
}
na.add(ns);
records.add(ns.getSlidePersistAtom());
if (ns.getSlideRecords() != null) {
@ -1115,16 +1123,26 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
return psrId;
}
@Override
public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException {
// TODO Auto-generated method stub
return null;
}
@Override
public Resources getResources() {
// TODO Auto-generated method stub
return null;
}
/**
* @return the handler class which holds the hslf records
*/
@Internal
public HSLFSlideShowImpl getSlideShowImpl() {
return _hslfSlideShow;
}
@Override
public void close() throws IOException {
_hslfSlideShow.close();

View File

@ -34,13 +34,24 @@ public class HSLFTestDataSamples {
public static InputStream openSampleFileStream(String sampleFileName) {
return _inst.openResourceAsStream(sampleFileName);
}
public static File getSampleFile(String sampleFileName) {
return _inst.getFile(sampleFileName);
}
public static byte[] getTestDataFileContent(String 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
* from a <tt>ByteArrayInputStream</tt>.<p/>

View File

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

View File

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

View File

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

View File

@ -19,26 +19,29 @@ package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
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.Test;
/**
* Tests that SlideShow returns Sheets which have the right text in them
*
* @author Nick Burch (nick at torchbox dot com)
*/
public final class TestSheetText {
// SlideShow primed on the test data
private HSLFSlideShow ss;
@Before
public void init() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new HSLFSlideShow(hss);
public void init() throws IOException {
ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
}
@After
public void tearDown() throws IOException {
ss.close();
}
@Test
@ -68,10 +71,8 @@ public final class TestSheetText {
* TextProps don't have enough data.
* (Make sure we don't screw up / throw an exception etc)
*/
public void testWithShortTextPropData() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("iisd_report.ppt"));
HSLFSlideShow sss = new HSLFSlideShow(hss);
public void testWithShortTextPropData() throws IOException {
HSLFSlideShow sss = HSLFTestDataSamples.getSlideShow("iisd_report.ppt");
// Should come out with 10 slides, no notes
assertEquals(10, sss.getSlides().size());
@ -90,5 +91,6 @@ public final class TestSheetText {
assertEquals(1, s.getTextParagraphs().size());
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 java.io.IOException;
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.Test;
/**
* Tests that SlideShow returns Sheets in the right order
*
* @author Nick Burch (nick at torchbox dot com)
*/
public final class TestSlideOrdering {
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
// Simple slideshow, record order matches slide order
private HSLFSlideShow ssA;
// Complex slideshow, record order doesn't match slide order
private HSLFSlideShow ssB;
@Before
public void init() throws Exception {
HSLFSlideShowImpl hssA = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ssA = new HSLFSlideShow(hssA);
public void init() throws IOException {
ssA = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
ssB = HSLFTestDataSamples.getSlideShow("incorrect_slide_order.ppt");
}
HSLFSlideShowImpl hssB = new HSLFSlideShowImpl(slTests.openResourceAsStream("incorrect_slide_order.ppt"));
ssB = new HSLFSlideShow(hssB);
@After
public void tearDown() throws IOException {
ssA.close();
ssB.close();
}
/**
@ -83,10 +84,8 @@ public final class TestSlideOrdering {
* @param titles
* array of reference slide titles
*/
protected void assertSlideOrdering(String filename, String[] titles) throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream(filename));
protected void assertSlideOrdering(String filename, String[] titles) throws IOException {
HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow(filename);
List<HSLFSlide> slide = ppt.getSlides();
assertEquals(titles.length, slide.size());
@ -94,6 +93,7 @@ public final class TestSlideOrdering {
String title = slide.get(i).getTitle();
assertEquals("Wrong slide title in " + filename, titles[i], title);
}
ppt.close();
}
@Test

View File

@ -18,30 +18,29 @@
package org.apache.poi.hslf.usermodel;
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
*
* @author Yegor Kozlov
*/
public final class TestSoundData extends TestCase{
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
public final class TestSoundData {
/**
* Read a reference sound file from disk and compare it from the data extracted from the slide show
*/
@Test
public void testSounds() throws Exception {
//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();
assertEquals("Expected 1 sound", 1, sound.length);
assertArrayEquals(ref_data, sound[0].getData());
ppt.close();
}
}

View File

@ -31,7 +31,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
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.usermodel.StrokeStyle;
import org.junit.Test;
@ -41,8 +41,6 @@ import org.junit.Test;
* Table related tests
*/
public class TestTable {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@Test
public void moveTable() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
@ -68,7 +66,7 @@ public class TestTable {
@Test
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);
List<HSLFSlide> slides = ppt.getSlides();

View File

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

View File

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