close resources, as SlideShow is now Closeable
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711865 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
44edbec0d5
commit
ae69a781f5
@ -26,6 +26,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
|
import org.apache.poi.OldFileFormatException;
|
||||||
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
||||||
import org.apache.poi.poifs.crypt.Decryptor;
|
import org.apache.poi.poifs.crypt.Decryptor;
|
||||||
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
||||||
@ -274,6 +275,8 @@ public class SlideShowFactory {
|
|||||||
throw (IOException)t;
|
throw (IOException)t;
|
||||||
} else if (t instanceof EncryptedDocumentException) {
|
} else if (t instanceof EncryptedDocumentException) {
|
||||||
throw (EncryptedDocumentException)t;
|
throw (EncryptedDocumentException)t;
|
||||||
|
} else if (t instanceof OldFileFormatException) {
|
||||||
|
throw (OldFileFormatException)t;
|
||||||
} else {
|
} else {
|
||||||
throw new IOException(t);
|
throw new IOException(t);
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -64,8 +60,6 @@ import org.apache.poi.util.StringUtil;
|
|||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Testcases for bugs entered in bugzilla
|
* Testcases for bugs entered in bugzilla
|
||||||
* the Test name contains the bugzilla bug id
|
* the Test name contains the bugzilla bug id
|
||||||
@ -79,11 +73,8 @@ public final class TestBugs {
|
|||||||
* Bug 41384: Array index wrong in record creation
|
* Bug 41384: Array index wrong in record creation
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug41384() throws Exception {
|
public void bug41384() throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("41384.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41384.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
assertTrue("No Exceptions while reading file", true);
|
|
||||||
|
|
||||||
assertEquals(1, ppt.getSlides().size());
|
assertEquals(1, ppt.getSlides().size());
|
||||||
|
|
||||||
@ -91,6 +82,8 @@ public final class TestBugs {
|
|||||||
assertEquals(2, pict.size());
|
assertEquals(2, pict.size());
|
||||||
assertEquals(PictureType.JPEG, pict.get(0).getType());
|
assertEquals(PictureType.JPEG, pict.get(0).getType());
|
||||||
assertEquals(PictureType.JPEG, pict.get(1).getType());
|
assertEquals(PictureType.JPEG, pict.get(1).getType());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,11 +91,8 @@ public final class TestBugs {
|
|||||||
* when the RichTextRun comes from a Notes model object
|
* when the RichTextRun comes from a Notes model object
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug42474_1() throws Exception {
|
public void bug42474_1() throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42474-1.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42474-1.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
assertTrue("No Exceptions while reading file", true);
|
|
||||||
assertEquals(2, ppt.getSlides().size());
|
assertEquals(2, ppt.getSlides().size());
|
||||||
|
|
||||||
List<HSLFTextParagraph> txrun;
|
List<HSLFTextParagraph> txrun;
|
||||||
@ -121,16 +111,15 @@ public final class TestBugs {
|
|||||||
assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun));
|
assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun));
|
||||||
assertEquals(true, txrun.get(0).getTextRuns().get(0).isBold());
|
assertEquals(true, txrun.get(0).getTextRuns().get(0).isBold());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second fix from Bug 42474: Incorrect matching of notes to slides
|
* Second fix from Bug 42474: Incorrect matching of notes to slides
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug42474_2() throws Exception {
|
public void bug42474_2() throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42474-2.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42474-2.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
|
|
||||||
//map slide number and starting phrase of its notes
|
//map slide number and starting phrase of its notes
|
||||||
Map<Integer, String> notesMap = new HashMap<Integer, String>();
|
Map<Integer, String> notesMap = new HashMap<Integer, String>();
|
||||||
@ -151,16 +140,16 @@ public final class TestBugs {
|
|||||||
startingPhrase , text.startsWith(startingPhrase));
|
startingPhrase , text.startsWith(startingPhrase));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns
|
* Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug42485 () throws Exception {
|
public void bug42485 () throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42485.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
|
for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
|
||||||
if(shape instanceof HSLFGroupShape){
|
if(shape instanceof HSLFGroupShape){
|
||||||
HSLFGroupShape group = (HSLFGroupShape)shape;
|
HSLFGroupShape group = (HSLFGroupShape)shape;
|
||||||
@ -172,16 +161,15 @@ public final class TestBugs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 42484: NullPointerException from ShapeGroup.getAnchor()
|
* Bug 42484: NullPointerException from ShapeGroup.getAnchor()
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug42484 () throws Exception {
|
public void bug42484 () throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42485.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
|
for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
|
||||||
if(shape instanceof HSLFGroupShape){
|
if(shape instanceof HSLFGroupShape){
|
||||||
HSLFGroupShape group = (HSLFGroupShape)shape;
|
HSLFGroupShape group = (HSLFGroupShape)shape;
|
||||||
@ -191,17 +179,15 @@ public final class TestBugs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue("No Exceptions while reading file", true);
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file
|
* Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug41381() throws Exception {
|
public void bug41381() throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("alterman_security.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("alterman_security.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
assertTrue("No Exceptions while reading file", true);
|
assertTrue("No Exceptions while reading file", true);
|
||||||
|
|
||||||
assertEquals(1, ppt.getSlideMasters().size());
|
assertEquals(1, ppt.getSlideMasters().size());
|
||||||
@ -213,6 +199,7 @@ public final class TestBugs {
|
|||||||
assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster);
|
assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster);
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
}
|
}
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -220,25 +207,20 @@ public final class TestBugs {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Test
|
@Test
|
||||||
public void bug42486 () throws Exception {
|
public void bug42486 () throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42486.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
for (HSLFSlide slide : ppt.getSlides()) {
|
for (HSLFSlide slide : ppt.getSlides()) {
|
||||||
List<HSLFShape> shape = slide.getShapes();
|
List<HSLFShape> shape = slide.getShapes();
|
||||||
}
|
}
|
||||||
assertTrue("No Exceptions while reading file", true);
|
ppt.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 42524: NPE in Shape.getShapeType()
|
* Bug 42524: NPE in Shape.getShapeType()
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug42524 () throws Exception {
|
public void bug42524 () throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42486.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
//walk down the tree and see if there were no errors while reading
|
//walk down the tree and see if there were no errors while reading
|
||||||
for (HSLFSlide slide : ppt.getSlides()) {
|
for (HSLFSlide slide : ppt.getSlides()) {
|
||||||
for (HSLFShape shape : slide.getShapes()) {
|
for (HSLFShape shape : slide.getShapes()) {
|
||||||
@ -252,8 +234,7 @@ public final class TestBugs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
assertTrue("No Exceptions while reading file", true);
|
ppt.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -261,10 +242,8 @@ public final class TestBugs {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Test
|
@Test
|
||||||
public void bug42520 () throws Exception {
|
public void bug42520 () throws IOException {
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42520.ppt"));
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
|
||||||
|
|
||||||
//test case from the bug report
|
//test case from the bug report
|
||||||
HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides().get(11).getShapes().get(10);
|
HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides().get(11).getShapes().get(10);
|
||||||
@ -283,10 +262,9 @@ public final class TestBugs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
assertTrue("No Exceptions while reading file", true);
|
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -294,10 +272,8 @@ public final class TestBugs {
|
|||||||
* ( also fixed followup: getTextRuns() returns no text )
|
* ( also fixed followup: getTextRuns() returns no text )
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug38256 () throws Exception {
|
public void bug38256 () throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("38256.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("38256.ppt"));
|
||||||
|
|
||||||
assertTrue("No Exceptions while reading file", true);
|
|
||||||
|
|
||||||
List<HSLFSlide> slide = ppt.getSlides();
|
List<HSLFSlide> slide = ppt.getSlides();
|
||||||
assertEquals(1, slide.size());
|
assertEquals(1, slide.size());
|
||||||
@ -315,6 +291,7 @@ public final class TestBugs {
|
|||||||
assertTrue(text, txt.contains(text));
|
assertTrue(text, txt.contains(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -322,10 +299,8 @@ public final class TestBugs {
|
|||||||
* ( also fixed followup: getTextRuns() returns no text )
|
* ( also fixed followup: getTextRuns() returns no text )
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug43781() throws Exception {
|
public void bug43781() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("43781.ppt"));
|
||||||
|
|
||||||
assertTrue("No Exceptions while reading file", true);
|
|
||||||
|
|
||||||
// Check the first slide
|
// Check the first slide
|
||||||
HSLFSlide slide = ppt.getSlides().get(0);
|
HSLFSlide slide = ppt.getSlides().get(0);
|
||||||
@ -353,14 +328,15 @@ public final class TestBugs {
|
|||||||
// There are two shapes in the ppt
|
// There are two shapes in the ppt
|
||||||
assertEquals(2, lst.size());
|
assertEquals(2, lst.size());
|
||||||
assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst));
|
assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst));
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 44296: HSLF Not Extracting Slide Background Image
|
* Bug 44296: HSLF Not Extracting Slide Background Image
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug44296 () throws Exception {
|
public void bug44296 () throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("44296.ppt"));
|
||||||
|
|
||||||
HSLFSlide slide = ppt.getSlides().get(0);
|
HSLFSlide slide = ppt.getSlides().get(0);
|
||||||
|
|
||||||
@ -371,29 +347,25 @@ public final class TestBugs {
|
|||||||
HSLFPictureData pict = f.getPictureData();
|
HSLFPictureData pict = f.getPictureData();
|
||||||
assertNotNull(pict);
|
assertNotNull(pict);
|
||||||
assertEquals(PictureType.JPEG, pict.getType());
|
assertEquals(PictureType.JPEG, pict.getType());
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
|
* Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for
|
||||||
|
* type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug44770() throws Exception {
|
public void bug44770() throws IOException {
|
||||||
try {
|
SlideShowFactory.create(_slTests.getFile("44770.ppt")).close();
|
||||||
new HSLFSlideShow(_slTests.openResourceAsStream("44770.ppt"));
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
if (e.getMessage().equals("Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing")) {
|
|
||||||
throw new AssertionFailedError("Identified bug 44770");
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 41071: Will not extract text from Powerpoint TextBoxes
|
* Bug 41071: Will not extract text from Powerpoint TextBoxes
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug41071() throws Exception {
|
public void bug41071() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41071.ppt"));
|
||||||
|
|
||||||
HSLFSlide slide = ppt.getSlides().get(0);
|
HSLFSlide slide = ppt.getSlides().get(0);
|
||||||
List<HSLFShape> sh = slide.getShapes();
|
List<HSLFShape> sh = slide.getShapes();
|
||||||
@ -405,73 +377,66 @@ public final class TestBugs {
|
|||||||
List<List<HSLFTextParagraph>> run = slide.getTextParagraphs();
|
List<List<HSLFTextParagraph>> run = slide.getTextParagraphs();
|
||||||
assertEquals(3, run.size());
|
assertEquals(3, run.size());
|
||||||
assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2)));
|
assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2)));
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PowerPoint 95 files should throw a more helpful exception
|
* PowerPoint 95 files should throw a more helpful exception
|
||||||
* @throws Exception
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Test(expected=OldPowerPointFormatException.class)
|
@Test(expected=OldPowerPointFormatException.class)
|
||||||
public void bug41711() throws Exception {
|
public void bug41711() throws IOException {
|
||||||
// New file is fine
|
// New file is fine
|
||||||
new HSLFSlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
|
SlideShowFactory.create(_slTests.getFile("SampleShow.ppt")).close();
|
||||||
|
|
||||||
// PowerPoint 95 gives an old format exception
|
// PowerPoint 95 gives an old format exception
|
||||||
new HSLFSlideShow(_slTests.openResourceAsStream("PPT95.ppt"));
|
SlideShowFactory.create(_slTests.getFile("PPT95.ppt")).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changing text from Ascii to Unicode
|
* Changing text from Ascii to Unicode
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug49648() throws Exception {
|
public void bug49648() throws IOException {
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("49648.ppt"));
|
||||||
for(HSLFSlide slide : ppt.getSlides()) {
|
for (HSLFSlide slide : ppt.getSlides()) {
|
||||||
for(List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
|
for (List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
|
||||||
String text = HSLFTextParagraph.getRawText(run);
|
String text = HSLFTextParagraph.getRawText(run);
|
||||||
text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
|
text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
|
||||||
HSLFTextParagraph.setText(run, text);
|
HSLFTextParagraph.setText(run, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 41246: AIOOB with illegal note references
|
* Bug 41246: AIOOB with illegal note references
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug41246a() throws Exception {
|
public void bug41246a() throws IOException {
|
||||||
InputStream fis = _slTests.openResourceAsStream("41246-1.ppt");
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41246-1.ppt"));
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis);
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
|
||||||
assertTrue("No Exceptions while reading file", true);
|
|
||||||
|
|
||||||
ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt);
|
ppt.close();
|
||||||
assertTrue("No Exceptions while rewriting file", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug41246b() throws Exception {
|
public void bug41246b() throws IOException {
|
||||||
InputStream fis = _slTests.openResourceAsStream("41246-2.ppt");
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41246-2.ppt"));
|
||||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis);
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
|
||||||
assertTrue("No Exceptions while reading file", true);
|
|
||||||
|
|
||||||
ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt);
|
ppt.close();
|
||||||
assertTrue("No Exceptions while rewriting file", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bug 45776: Fix corrupt file problem using TextRun.setText
|
* Bug 45776: Fix corrupt file problem using TextRun.setText
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void bug45776() throws Exception {
|
public void bug45776() throws IOException {
|
||||||
InputStream is = _slTests.openResourceAsStream("45776.ppt");
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("45776.ppt"));
|
||||||
HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl(is));
|
|
||||||
is.close();
|
|
||||||
|
|
||||||
// get slides
|
// get slides
|
||||||
for (HSLFSlide slide : ppt.getSlides()) {
|
for (HSLFSlide slide : ppt.getSlides()) {
|
||||||
@ -490,35 +455,33 @@ public final class TestBugs {
|
|||||||
assertEquals(str.length()+1,tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
|
assertEquals(str.length()+1,tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug55732() throws Exception {
|
public void bug55732() throws IOException {
|
||||||
File file = _slTests.getFile("bug55732.ppt");
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug55732.ppt"));
|
||||||
|
|
||||||
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
|
List<HSLFSlide> _slides = ppt.getSlides();
|
||||||
HSLFSlideShow _show = new HSLFSlideShow(ss);
|
|
||||||
List<HSLFSlide> _slides = _show.getSlides();
|
|
||||||
|
|
||||||
/* Iterate over slides and extract text */
|
/* Iterate over slides and extract text */
|
||||||
for( HSLFSlide slide : _slides ) {
|
for( HSLFSlide slide : _slides ) {
|
||||||
HeadersFooters hf = slide.getHeadersFooters();
|
HeadersFooters hf = slide.getHeadersFooters();
|
||||||
/*boolean visible =*/ hf.isHeaderVisible(); // exception happens here
|
/*boolean visible =*/ hf.isHeaderVisible(); // exception happens here
|
||||||
}
|
}
|
||||||
assertTrue("No Exceptions while reading headers", true);
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug56260() throws Exception {
|
public void bug56260() throws IOException {
|
||||||
File file = _slTests.getFile("56260.ppt");
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("56260.ppt"));
|
||||||
|
List<HSLFSlide> _slides = ppt.getSlides();
|
||||||
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
|
|
||||||
HSLFSlideShow _show = new HSLFSlideShow(ss);
|
|
||||||
List<HSLFSlide> _slides = _show.getSlides();
|
|
||||||
assertEquals(13, _slides.size());
|
assertEquals(13, _slides.size());
|
||||||
|
|
||||||
// Check the number of TextHeaderAtoms on Slide 1
|
// Check the number of TextHeaderAtoms on Slide 1
|
||||||
Document dr = _show.getDocumentRecord();
|
Document dr = ppt.getDocumentRecord();
|
||||||
SlideListWithText slidesSLWT = dr.getSlideSlideListWithText();
|
SlideListWithText slidesSLWT = dr.getSlideSlideListWithText();
|
||||||
SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0];
|
SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0];
|
||||||
|
|
||||||
@ -540,88 +503,67 @@ public final class TestBugs {
|
|||||||
if (! tr.get(0).isDrawingBased()) str++;
|
if (! tr.get(0).isDrawingBased()) str++;
|
||||||
}
|
}
|
||||||
assertEquals(2, str);
|
assertEquals(2, str);
|
||||||
|
|
||||||
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug37625() throws IOException {
|
public void bug37625() throws IOException {
|
||||||
InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt"));
|
HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("37625.ppt"));
|
||||||
try {
|
assertEquals(29, ppt1.getSlides().size());
|
||||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
|
||||||
assertEquals(29, slideShow.getSlides().size());
|
|
||||||
|
|
||||||
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
|
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
||||||
assertNotNull(slideBack);
|
assertNotNull(ppt2);
|
||||||
assertEquals(29, slideBack.getSlides().size());
|
assertEquals(29, ppt2.getSlides().size());
|
||||||
} finally {
|
ppt2.close();
|
||||||
inputStream.close();
|
ppt1.close();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug57272() throws Exception {
|
public void bug57272() throws IOException {
|
||||||
InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt"));
|
HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("57272_corrupted_usereditatom.ppt"));
|
||||||
try {
|
assertEquals(6, ppt1.getSlides().size());
|
||||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
|
||||||
assertEquals(6, slideShow.getSlides().size());
|
|
||||||
|
|
||||||
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
|
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
||||||
assertNotNull(slideBack);
|
assertNotNull(ppt2);
|
||||||
assertEquals(6, slideBack.getSlides().size());
|
assertEquals(6, ppt2.getSlides().size());
|
||||||
} finally {
|
ppt2.close();
|
||||||
inputStream.close();
|
ppt1.close();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug49541() throws Exception {
|
public void bug49541() throws IOException {
|
||||||
InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("49541_symbol_map.ppt"));
|
||||||
try {
|
HSLFSlide slide = ppt.getSlides().get(0);
|
||||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
|
||||||
HSLFSlide slide = slideShow.getSlides().get(0);
|
|
||||||
HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0);
|
HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0);
|
||||||
HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0);
|
HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0);
|
||||||
String text = StringUtil.mapMsCodepointString(tb.getText());
|
String text = StringUtil.mapMsCodepointString(tb.getText());
|
||||||
assertEquals("\u226575 years", text);
|
assertEquals("\u226575 years", text);
|
||||||
} finally {
|
ppt.close();
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug47261() throws Exception {
|
public void bug47261() throws IOException {
|
||||||
InputStream inputStream = new FileInputStream(_slTests.getFile("bug47261.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug47261.ppt"));
|
||||||
try {
|
ppt.removeSlide(0);
|
||||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
ppt.createSlide();
|
||||||
slideShow.removeSlide(0);
|
HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
|
||||||
slideShow.createSlide();
|
ppt.close();
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
||||||
slideShow.write(bos);
|
|
||||||
} finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug56240() throws Exception {
|
public void bug56240() throws IOException {
|
||||||
InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug56240.ppt"));
|
||||||
try {
|
int slideCnt = ppt.getSlides().size();
|
||||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
|
||||||
int slideCnt = slideShow.getSlides().size();
|
|
||||||
assertEquals(105, slideCnt);
|
assertEquals(105, slideCnt);
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
|
||||||
slideShow.write(bos);
|
ppt.close();
|
||||||
bos.close();
|
|
||||||
} finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bug46441() throws Exception {
|
public void bug46441() throws IOException {
|
||||||
InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt"));
|
HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug46441.ppt"));
|
||||||
try {
|
HSLFAutoShape as = (HSLFAutoShape)ppt.getSlides().get(0).getShapes().get(0);
|
||||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
|
||||||
HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0);
|
|
||||||
AbstractEscherOptRecord opt = as.getEscherOptRecord();
|
AbstractEscherOptRecord opt = as.getEscherOptRecord();
|
||||||
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
|
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
|
||||||
double exp[][] = {
|
double exp[][] = {
|
||||||
@ -643,9 +585,7 @@ public final class TestBugs {
|
|||||||
assertEquals(exp[i][3], pos, 0.01);
|
assertEquals(exp[i][3], pos, 0.01);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} finally {
|
ppt.close();
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user