From: Andreas Beeker Date: Mon, 2 Nov 2015 00:05:14 +0000 (+0000) Subject: close resources, as SlideShow is now Closeable X-Git-Tag: REL_3_14_BETA1~185 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8e8de333576aa79275f5192f3a00e3cc9b1a2d4b;p=poi.git close resources, as SlideShow is now Closeable git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711865 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java b/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java index 9e705dffcc..7fde64dee8 100644 --- a/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java +++ b/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java @@ -26,6 +26,7 @@ import java.lang.reflect.Method; import java.security.GeneralSecurityException; import org.apache.poi.EncryptedDocumentException; +import org.apache.poi.OldFileFormatException; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.crypt.EncryptionInfo; @@ -274,6 +275,8 @@ public class SlideShowFactory { throw (IOException)t; } else if (t instanceof EncryptedDocumentException) { throw (EncryptedDocumentException)t; + } else if (t instanceof OldFileFormatException) { + throw (OldFileFormatException)t; } else { throw new IOException(t); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java index 22d750857a..3549a38e63 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -23,11 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.awt.Color; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -64,8 +60,6 @@ import org.apache.poi.util.StringUtil; import org.apache.poi.util.Units; import org.junit.Test; -import junit.framework.AssertionFailedError; - /** * Testcases for bugs entered in bugzilla * the Test name contains the bugzilla bug id @@ -79,11 +73,8 @@ public final class TestBugs { * Bug 41384: Array index wrong in record creation */ @Test - public void bug41384() throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("41384.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); - assertTrue("No Exceptions while reading file", true); + public void bug41384() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41384.ppt")); assertEquals(1, ppt.getSlides().size()); @@ -91,6 +82,8 @@ public final class TestBugs { assertEquals(2, pict.size()); assertEquals(PictureType.JPEG, pict.get(0).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 */ @Test - public void bug42474_1() throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42474-1.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); - assertTrue("No Exceptions while reading file", true); + public void bug42474_1() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42474-1.ppt")); assertEquals(2, ppt.getSlides().size()); List txrun; @@ -121,16 +111,15 @@ public final class TestBugs { assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun)); assertEquals(true, txrun.get(0).getTextRuns().get(0).isBold()); + ppt.close(); } /** * Second fix from Bug 42474: Incorrect matching of notes to slides */ @Test - public void bug42474_2() throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42474-2.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); + public void bug42474_2() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42474-2.ppt")); //map slide number and starting phrase of its notes Map notesMap = new HashMap(); @@ -151,16 +140,16 @@ public final class TestBugs { startingPhrase , text.startsWith(startingPhrase)); } } + + ppt.close(); } /** * Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns */ @Test - public void bug42485 () throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); + public void bug42485 () throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42485.ppt")); for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) { if(shape instanceof HSLFGroupShape){ HSLFGroupShape group = (HSLFGroupShape)shape; @@ -172,16 +161,15 @@ public final class TestBugs { } } } + ppt.close(); } /** * Bug 42484: NullPointerException from ShapeGroup.getAnchor() */ @Test - public void bug42484 () throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); + public void bug42484 () throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42485.ppt")); for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) { if(shape instanceof HSLFGroupShape){ 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 */ @Test - public void bug41381() throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("alterman_security.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); + public void bug41381() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("alterman_security.ppt")); assertTrue("No Exceptions while reading file", true); assertEquals(1, ppt.getSlideMasters().size()); @@ -213,6 +199,7 @@ public final class TestBugs { assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster); isFirst = false; } + ppt.close(); } /** @@ -220,25 +207,20 @@ public final class TestBugs { */ @SuppressWarnings("unused") @Test - public void bug42486 () throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); + public void bug42486 () throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42486.ppt")); for (HSLFSlide slide : ppt.getSlides()) { List shape = slide.getShapes(); } - assertTrue("No Exceptions while reading file", true); - + ppt.close(); } /** * Bug 42524: NPE in Shape.getShapeType() */ @Test - public void bug42524 () throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); + public void bug42524 () throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42486.ppt")); //walk down the tree and see if there were no errors while reading for (HSLFSlide slide : ppt.getSlides()) { 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") @Test - public void bug42520 () throws Exception { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt")); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); + public void bug42520 () throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("42520.ppt")); //test case from the bug report 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 ) */ @Test - public void bug38256 () throws Exception { - HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("38256.ppt")); - - assertTrue("No Exceptions while reading file", true); + public void bug38256 () throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("38256.ppt")); List slide = ppt.getSlides(); assertEquals(1, slide.size()); @@ -315,6 +291,7 @@ public final class TestBugs { assertTrue(text, txt.contains(text)); } + ppt.close(); } /** @@ -322,15 +299,13 @@ public final class TestBugs { * ( also fixed followup: getTextRuns() returns no text ) */ @Test - public void bug43781() throws Exception { - HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt")); - - assertTrue("No Exceptions while reading file", true); + public void bug43781() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("43781.ppt")); // Check the first slide HSLFSlide slide = ppt.getSlides().get(0); List> slTr = slide.getTextParagraphs(); - + // Has 3 text paragraphs, two from slide text (empty title / filled body), one from drawing assertEquals(3, slTr.size()); assertFalse(slTr.get(0).get(0).isDrawingBased()); @@ -349,18 +324,19 @@ public final class TestBugs { } } - + // There are two shapes in the ppt assertEquals(2, lst.size()); assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst)); + ppt.close(); } /** * Bug 44296: HSLF Not Extracting Slide Background Image */ @Test - public void bug44296 () throws Exception { - HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt")); + public void bug44296 () throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("44296.ppt")); HSLFSlide slide = ppt.getSlides().get(0); @@ -371,29 +347,25 @@ public final class TestBugs { HSLFPictureData pict = f.getPictureData(); assertNotNull(pict); 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 - public void bug44770() throws Exception { - try { - 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; - } + public void bug44770() throws IOException { + SlideShowFactory.create(_slTests.getFile("44770.ppt")).close(); } /** * Bug 41071: Will not extract text from Powerpoint TextBoxes */ @Test - public void bug41071() throws Exception { - HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt")); + public void bug41071() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41071.ppt")); HSLFSlide slide = ppt.getSlides().get(0); List sh = slide.getShapes(); @@ -405,73 +377,66 @@ public final class TestBugs { List> run = slide.getTextParagraphs(); assertEquals(3, run.size()); assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2))); + + ppt.close(); } /** * PowerPoint 95 files should throw a more helpful exception - * @throws Exception + * @throws IOException */ @Test(expected=OldPowerPointFormatException.class) - public void bug41711() throws Exception { + public void bug41711() throws IOException { // New file is fine - new HSLFSlideShow(_slTests.openResourceAsStream("SampleShow.ppt")); + SlideShowFactory.create(_slTests.getFile("SampleShow.ppt")).close(); // 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 */ @Test - public void bug49648() throws Exception { - HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt")); - for(HSLFSlide slide : ppt.getSlides()) { - for(List run : slide.getTextParagraphs()) { - String text = HSLFTextParagraph.getRawText(run); - text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode"); - HSLFTextParagraph.setText(run, text); - } - } + public void bug49648() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("49648.ppt")); + for (HSLFSlide slide : ppt.getSlides()) { + for (List run : slide.getTextParagraphs()) { + String text = HSLFTextParagraph.getRawText(run); + text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode"); + HSLFTextParagraph.setText(run, text); + } + } + ppt.close(); } /** * Bug 41246: AIOOB with illegal note references */ @Test - public void bug41246a() throws Exception { - InputStream fis = _slTests.openResourceAsStream("41246-1.ppt"); - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis); - fis.close(); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); - assertTrue("No Exceptions while reading file", true); + public void bug41246a() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41246-1.ppt")); - ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt); - assertTrue("No Exceptions while rewriting file", true); + HSLFTestDataSamples.writeOutAndReadBack(ppt).close(); + + ppt.close(); } @Test - public void bug41246b() throws Exception { - InputStream fis = _slTests.openResourceAsStream("41246-2.ppt"); - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis); - fis.close(); - - HSLFSlideShow ppt = new HSLFSlideShow(hslf); - assertTrue("No Exceptions while reading file", true); + public void bug41246b() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("41246-2.ppt")); - ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt); - assertTrue("No Exceptions while rewriting file", true); + HSLFTestDataSamples.writeOutAndReadBack(ppt).close(); + + ppt.close(); } /** * Bug 45776: Fix corrupt file problem using TextRun.setText */ @Test - public void bug45776() throws Exception { - InputStream is = _slTests.openResourceAsStream("45776.ppt"); - HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl(is)); - is.close(); + public void bug45776() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("45776.ppt")); // get slides for (HSLFSlide slide : ppt.getSlides()) { @@ -484,41 +449,39 @@ public final class TestBugs { if (!str.contains("$$DATE$$")) continue; str = str.replace("$$DATE$$", new Date().toString()); tb.setText(str); - + List tr = tb.getTextParagraphs(); assertEquals(str.length()+1,tr.get(0).getParagraphStyle().getCharactersCovered()); assertEquals(str.length()+1,tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered()); } } + + ppt.close(); } @Test - public void bug55732() throws Exception { - File file = _slTests.getFile("bug55732.ppt"); - - HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath()); - HSLFSlideShow _show = new HSLFSlideShow(ss); - List _slides = _show.getSlides(); + public void bug55732() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug55732.ppt")); + + List _slides = ppt.getSlides(); /* Iterate over slides and extract text */ for( HSLFSlide slide : _slides ) { HeadersFooters hf = slide.getHeadersFooters(); /*boolean visible =*/ hf.isHeaderVisible(); // exception happens here } - assertTrue("No Exceptions while reading headers", true); + + ppt.close(); } - + @Test - public void bug56260() throws Exception { - File file = _slTests.getFile("56260.ppt"); - - HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath()); - HSLFSlideShow _show = new HSLFSlideShow(ss); - List _slides = _show.getSlides(); + public void bug56260() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("56260.ppt")); + List _slides = ppt.getSlides(); assertEquals(13, _slides.size()); - + // Check the number of TextHeaderAtoms on Slide 1 - Document dr = _show.getDocumentRecord(); + Document dr = ppt.getDocumentRecord(); SlideListWithText slidesSLWT = dr.getSlideSlideListWithText(); SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0]; @@ -527,12 +490,12 @@ public final class TestBugs { if (r instanceof TextHeaderAtom) tha++; } assertEquals(2, tha); - + // Check to see that we have a pair next to each other assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[0].getClass()); assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[1].getClass()); - - + + // Check the number of text runs based on the slide (not textbox) // Will have skipped the empty one int str = 0; @@ -540,114 +503,91 @@ public final class TestBugs { if (! tr.get(0).isDrawingBased()) str++; } assertEquals(2, str); + + ppt.close(); } - + @Test public void bug37625() throws IOException { - InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt")); - try { - HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); - assertEquals(29, slideShow.getSlides().size()); - - HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow); - assertNotNull(slideBack); - assertEquals(29, slideBack.getSlides().size()); - } finally { - inputStream.close(); - } + HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("37625.ppt")); + assertEquals(29, ppt1.getSlides().size()); + + HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1); + assertNotNull(ppt2); + assertEquals(29, ppt2.getSlides().size()); + ppt2.close(); + ppt1.close(); } - + @Test - public void bug57272() throws Exception { - InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt")); - try { - HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); - assertEquals(6, slideShow.getSlides().size()); - - HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow); - assertNotNull(slideBack); - assertEquals(6, slideBack.getSlides().size()); - } finally { - inputStream.close(); - } + public void bug57272() throws IOException { + HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("57272_corrupted_usereditatom.ppt")); + assertEquals(6, ppt1.getSlides().size()); + + HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1); + assertNotNull(ppt2); + assertEquals(6, ppt2.getSlides().size()); + ppt2.close(); + ppt1.close(); } @Test - public void bug49541() throws Exception { - InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt")); - try { - HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); - HSLFSlide slide = slideShow.getSlides().get(0); - HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0); - HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0); - String text = StringUtil.mapMsCodepointString(tb.getText()); - assertEquals("\u226575 years", text); - } finally { - inputStream.close(); - } + public void bug49541() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("49541_symbol_map.ppt")); + HSLFSlide slide = ppt.getSlides().get(0); + HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0); + HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0); + String text = StringUtil.mapMsCodepointString(tb.getText()); + assertEquals("\u226575 years", text); + ppt.close(); } - + @Test - public void bug47261() throws Exception { - InputStream inputStream = new FileInputStream(_slTests.getFile("bug47261.ppt")); - try { - HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); - slideShow.removeSlide(0); - slideShow.createSlide(); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - slideShow.write(bos); - } finally { - inputStream.close(); - } + public void bug47261() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug47261.ppt")); + ppt.removeSlide(0); + ppt.createSlide(); + HSLFTestDataSamples.writeOutAndReadBack(ppt).close(); + ppt.close(); } - + @Test - public void bug56240() throws Exception { - InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt")); - try { - HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); - int slideCnt = slideShow.getSlides().size(); - assertEquals(105, slideCnt); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - slideShow.write(bos); - bos.close(); - } finally { - inputStream.close(); - } + public void bug56240() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug56240.ppt")); + int slideCnt = ppt.getSlides().size(); + assertEquals(105, slideCnt); + HSLFTestDataSamples.writeOutAndReadBack(ppt).close(); + ppt.close(); } - + @Test - public void bug46441() throws Exception { - InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt")); - try { - HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); - HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0); - AbstractEscherOptRecord opt = as.getEscherOptRecord(); - EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS); - double exp[][] = { - // r, g, b, position - { 94, 158, 255, 0 }, - { 133, 194, 255, 0.399994 }, - { 196, 214, 235, 0.699997 }, - { 255, 235, 250, 1 } - }; - - int i = 0; - for (byte data[] : ep) { - EscherColorRef ecr = new EscherColorRef(data, 0, 4); - int rgb[] = ecr.getRGB(); - double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4)); - assertEquals((int)exp[i][0], rgb[0]); - assertEquals((int)exp[i][1], rgb[1]); - assertEquals((int)exp[i][2], rgb[2]); - assertEquals(exp[i][3], pos, 0.01); - i++; - } - } finally { - inputStream.close(); + public void bug46441() throws IOException { + HSLFSlideShow ppt = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug46441.ppt")); + HSLFAutoShape as = (HSLFAutoShape)ppt.getSlides().get(0).getShapes().get(0); + AbstractEscherOptRecord opt = as.getEscherOptRecord(); + EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS); + double exp[][] = { + // r, g, b, position + { 94, 158, 255, 0 }, + { 133, 194, 255, 0.399994 }, + { 196, 214, 235, 0.699997 }, + { 255, 235, 250, 1 } + }; + + int i = 0; + for (byte data[] : ep) { + EscherColorRef ecr = new EscherColorRef(data, 0, 4); + int rgb[] = ecr.getRGB(); + double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4)); + assertEquals((int)exp[i][0], rgb[0]); + assertEquals((int)exp[i][1], rgb[1]); + assertEquals((int)exp[i][2], rgb[2]); + assertEquals(exp[i][3], pos, 0.01); + i++; } + ppt.close(); } - + @Test public void bug58516() throws IOException { SlideShowFactory.create(_slTests.getFile("bug58516.ppt")).close(); @@ -661,22 +601,22 @@ public final class TestBugs { TextBox res = slide1.createTextBox(); res.setAnchor(new java.awt.Rectangle(60, 150, 700, 100)); res.setText("I am italic-false, bold-true inserted text"); - + TextParagraph tp = res.getTextParagraphs().get(0); TextRun rt = tp.getTextRuns().get(0); rt.setItalic(false); assertTrue(rt.isBold()); - + tp.setBulletStyle(Color.red, 'A'); SlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack((HSLFSlideShow)ppt); ppt.close(); - + res = (TextBox)ppt2.getSlides().get(1).getShapes().get(1); tp = res.getTextParagraphs().get(0); rt = tp.getTextRuns().get(0); - + assertFalse(rt.isItalic()); assertTrue(rt.isBold()); PaintStyle ps = tp.getBulletStyle().getBulletFontColor(); @@ -684,15 +624,15 @@ public final class TestBugs { Color actColor = DrawPaint.applyColorTransform(((SolidPaint)ps).getSolidColor()); assertEquals(Color.red, actColor); assertEquals("A", tp.getBulletStyle().getBulletCharacter()); - + ppt2.close(); } - + @Test public void bug45088() throws IOException { String template = "[SYSDATE]"; String textExp = "REPLACED_DATE_WITH_A_LONG_ONE"; - + HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug45088.ppt")); for (HSLFSlide slide : ppt1.getSlides()) { for (List paraList : slide.getTextParagraphs()) { @@ -711,13 +651,13 @@ public final class TestBugs { HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1); ppt1.close(); - + HSLFTextBox tb = (HSLFTextBox)ppt2.getSlides().get(0).getShapes().get(1); String textAct = tb.getTextParagraphs().get(0).getTextRuns().get(0).getRawText().trim(); assertEquals(textExp, textAct); ppt2.close(); } - + @Test public void bug45908() throws IOException { HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug45908.ppt")); @@ -745,7 +685,7 @@ public final class TestBugs { tp.setSpaceAfter(tp0.getSpaceAfter()); tp.setSpaceBefore(tp0.getSpaceBefore()); tp.setBulletStyle(); - + HSLFTextRun tr = tp.getTextRuns().get(0); tr.setBold(tr0.isBold()); // rt.setEmbossed(); @@ -785,7 +725,7 @@ public final class TestBugs { assertEquals(tr0.isShadowed(), tr1.isShadowed()); assertEquals(tr0.isStrikethrough(), tr1.isStrikethrough()); assertEquals(tr0.isUnderlined(), tr1.isUnderlined()); - + ppt2.close(); } }