diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-03-27 14:03:16 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-03-27 14:03:16 +0000 |
commit | 37791e4bdfc706aa5684745594260f243b4be7ee (patch) | |
tree | a8dd8d0976fc478074d52cd3de79e0e6b5e6a33a /src/scratchpad/testcases/org/apache/poi/hslf/usermodel | |
parent | 2bb3839bfe3e3bacff79f8157465633e311239ce (diff) | |
download | poi-37791e4bdfc706aa5684745594260f243b4be7ee.tar.gz poi-37791e4bdfc706aa5684745594260f243b4be7ee.zip |
65206 - Migrate ant / maven to gradle build
update gradle files and project structure along https://github.com/centic9/poi/tree/gradle_build
remove eclipse IDE project files
remove obsolete record generator files
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1888111 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org/apache/poi/hslf/usermodel')
23 files changed, 0 insertions, 5375 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java deleted file mode 100644 index 35e5880406..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestAddingSlides.java +++ /dev/null @@ -1,274 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.List; - -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.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests that SlideShow adds additional sheets properly - */ -public final class TestAddingSlides { - // An empty SlideShow - private HSLFSlideShow ss_empty; - - // A SlideShow with one slide - private HSLFSlideShow ss_one; - - // A SlideShow with two slides - private HSLFSlideShow ss_two; - - /** - * Create/open the slideshows - */ - @BeforeEach - 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"); - } - - @AfterEach - void tearDown() throws IOException { - ss_two.close(); - ss_one.close(); - ss_empty.close(); - } - - /** - * Test adding a slide to an empty slideshow - */ - @Test - 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); - - // grab UserEditAtom - UserEditAtom usredit = null; - Record[] _records = ss_empty.getSlideShowImpl().getRecords(); - for ( org.apache.poi.hslf.record.Record record : _records) { - if (record.getRecordType() == RecordTypes.UserEditAtom.typeID) { - usredit = (UserEditAtom) record; - } - } - assertNotNull(usredit); - - // Add one - HSLFSlide slide = ss_empty.createSlide(); - assertEquals(1, ss_empty.getSlides().size()); - assertEquals(256, slide._getSheetNumber()); - assertEquals(3, slide._getSheetRefId()); - assertEquals(1, slide.getSlideNumber()); - assertEquals(usredit.getMaxPersistWritten(), slide._getSheetRefId()); - - // Write out, and read back in - 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); - - // 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 - */ - @Test - void testAddSlideToExisting() throws IOException { - // Has one slide - assertEquals(1, ss_one.getSlides().size()); - HSLFSlide s1 = ss_one.getSlides().get(0); - - // Should have two SLTWs - assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length); - - // Check slide 1 is as expected - assertEquals(256, s1._getSheetNumber()); - assertEquals(3, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - - // Add a second one - HSLFSlide s2 = ss_one.createSlide(); - assertEquals(2, ss_one.getSlides().size()); - assertEquals(257, s2._getSheetNumber()); - assertEquals(4, s2._getSheetRefId()); - assertEquals(2, s2.getSlideNumber()); - - // Write out, and read back in - 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); - - // And check it's as expected - s1 = ss_read.getSlides().get(0); - s2 = ss_read.getSlides().get(1); - assertEquals(256, s1._getSheetNumber()); - assertEquals(3, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - assertEquals(257, s2._getSheetNumber()); - assertEquals(4, s2._getSheetRefId()); - assertEquals(2, s2.getSlideNumber()); - ss_read.close(); - } - - /** - * Test adding a slide to an existing slideshow, with two slides already - */ - @Test - void testAddSlideToExisting2() throws IOException { - // grab UserEditAtom - UserEditAtom usredit = null; - Record[] _records = ss_two.getSlideShowImpl().getRecords(); - for ( org.apache.poi.hslf.record.Record record : _records) { - if (record.getRecordType() == RecordTypes.UserEditAtom.typeID) { - usredit = (UserEditAtom) record; - } - } - assertNotNull(usredit); - - // Has two slides - assertEquals(2, ss_two.getSlides().size()); - HSLFSlide s1 = ss_two.getSlides().get(0); - HSLFSlide s2 = ss_two.getSlides().get(1); - - // Check slide 1 is as expected - assertEquals(256, s1._getSheetNumber()); - assertEquals(4, s1._getSheetRefId()); // master has notes - assertEquals(1, s1.getSlideNumber()); - // Check slide 2 is as expected - assertEquals(257, s2._getSheetNumber()); - assertEquals(6, s2._getSheetRefId()); // master and 1 have notes - assertEquals(2, s2.getSlideNumber()); - - // Add a third one - HSLFSlide s3 = ss_two.createSlide(); - assertEquals(3, ss_two.getSlides().size()); - assertEquals(258, s3._getSheetNumber()); - assertEquals(8, s3._getSheetRefId()); // lots of notes before us - assertEquals(3, s3.getSlideNumber()); - assertEquals(usredit.getMaxPersistWritten(), s3._getSheetRefId()); - - // Write out, and read back in - HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two); - - // Check it now has three slides - assertEquals(3, ss_read.getSlides().size()); - - // And check it's as expected - s1 = ss_read.getSlides().get(0); - s2 = ss_read.getSlides().get(1); - s3 = ss_read.getSlides().get(2); - assertEquals(256, s1._getSheetNumber()); - assertEquals(4, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - assertEquals(257, s2._getSheetNumber()); - assertEquals(6, s2._getSheetRefId()); - assertEquals(2, s2.getSlideNumber()); - assertEquals(258, s3._getSheetNumber()); - assertEquals(8, s3._getSheetRefId()); - assertEquals(3, s3.getSlideNumber()); - ss_read.close(); - } - - /** - * Test SlideShow#removeSlide - */ - @Test - void testRemoving() throws IOException { - HSLFSlide slide1 = ss_empty.createSlide(); - HSLFSlide slide2 = ss_empty.createSlide(); - - List<HSLFSlide> s1 = ss_empty.getSlides(); - assertEquals(2, s1.size()); - assertThrows(Exception.class, () -> ss_empty.removeSlide(-1)); - assertThrows(Exception.class, () -> ss_empty.removeSlide(2)); - - assertEquals(1, slide1.getSlideNumber()); - - 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()); - - try (HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_empty)) { - assertEquals(1, ss_read.getSlides().size()); - } - } - - @Test - 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(); - assertTrue(notesId > 0); - assertNotNull(doc.getNotesSlideListWithText()); - assertEquals(14, doc.getNotesSlideListWithText().getSlideAtomsSets().length); - - // remove all slides, corresponding notes should be removed too - for (int i = slides.size(); i > 0; i--) { - ppt.removeSlide(0); - } - assertEquals(0, ppt.getSlides().size()); - assertEquals(0, ppt.getNotes().size()); - assertNull(doc.getSlideSlideListWithText()); - assertNull(doc.getNotesSlideListWithText()); - ppt.close(); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java deleted file mode 100644 index 38bc03bb28..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java +++ /dev/null @@ -1,219 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.awt.Color; -import java.io.IOException; -import java.util.List; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.ddf.AbstractEscherOptRecord; -import org.apache.poi.ddf.EscherBSERecord; -import org.apache.poi.ddf.EscherContainerRecord; -import org.apache.poi.ddf.EscherPropertyTypes; -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.sl.usermodel.PictureData.PictureType; -import org.apache.poi.sl.usermodel.ShapeType; -import org.junit.jupiter.api.Test; - - -/** - * Test <code>Fill</code> object. - * - * @author Yegor Kozlov - */ -public final class TestBackground { - private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); - - /** - * Default background for slide, shape and slide master. - */ - @Test - void defaults() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType()); - - HSLFSlide slide = ppt.createSlide(); - assertTrue(slide.getFollowMasterBackground()); - assertEquals(HSLFFill.FILL_SOLID, slide.getBackground().getFill().getFillType()); - - HSLFShape shape = new HSLFAutoShape(ShapeType.RECT); - assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType()); - ppt.close(); - } - - /** - * Read fill information from an reference ppt file - */ - @Test - void readBackground() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("backgrounds.ppt"); - HSLFFill fill; - HSLFShape shape; - - List<HSLFSlide> slide = ppt.getSlides(); - - fill = slide.get(0).getBackground().getFill(); - assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType()); - shape = slide.get(0).getShapes().get(0); - assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType()); - - fill = slide.get(1).getBackground().getFill(); - assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType()); - shape = slide.get(1).getShapes().get(0); - assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType()); - - fill = slide.get(2).getBackground().getFill(); - assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType()); - shape = slide.get(2).getShapes().get(0); - assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType()); - - fill = slide.get(3).getBackground().getFill(); - 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 - void backgroundPicture() throws IOException { - HSLFSlideShow ppt1 = new HSLFSlideShow(); - HSLFSlide slide; - HSLFFill fill; - HSLFShape shape; - HSLFPictureData data; - - //slide 1 - slide = ppt1.createSlide(); - slide.setFollowMasterBackground(false); - fill = slide.getBackground().getFill(); - data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG); - fill.setFillType(HSLFFill.FILL_PICTURE); - fill.setPictureData(data); - - shape = new HSLFAutoShape(ShapeType.RECT); - shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200)); - fill = shape.getFill(); - fill.setFillType(HSLFFill.FILL_SOLID); - slide.addShape(shape); - - //slide 2 - slide = ppt1.createSlide(); - slide.setFollowMasterBackground(false); - fill = slide.getBackground().getFill(); - data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG); - fill.setFillType(HSLFFill.FILL_PATTERN); - fill.setPictureData(data); - fill.setBackgroundColor(Color.green); - fill.setForegroundColor(Color.red); - - shape = new HSLFAutoShape(ShapeType.RECT); - shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200)); - fill = shape.getFill(); - fill.setFillType(HSLFFill.FILL_BACKGROUND); - slide.addShape(shape); - - //slide 3 - slide = ppt1.createSlide(); - slide.setFollowMasterBackground(false); - fill = slide.getBackground().getFill(); - data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG); - fill.setFillType(HSLFFill.FILL_TEXTURE); - fill.setPictureData(data); - - shape = new HSLFAutoShape(ShapeType.RECT); - shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200)); - fill = shape.getFill(); - fill.setFillType(HSLFFill.FILL_PICTURE); - data = ppt1.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG); - fill.setPictureData(data); - slide.addShape(shape); - - // slide 4 - slide = ppt1.createSlide(); - slide.setFollowMasterBackground(false); - fill = slide.getBackground().getFill(); - fill.setFillType(HSLFFill.FILL_SHADE_CENTER); - fill.setBackgroundColor(Color.white); - fill.setForegroundColor(Color.darkGray); - - shape = new HSLFAutoShape(ShapeType.RECT); - shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200)); - fill = shape.getFill(); - fill.setFillType(HSLFFill.FILL_SHADE); - fill.setBackgroundColor(Color.red); - fill.setForegroundColor(Color.green); - slide.addShape(shape); - - //serialize and read again - HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1); - List<HSLFSlide> slides = ppt2.getSlides(); - - fill = slides.get(0).getBackground().getFill(); - assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType()); - assertEquals(3, getFillPictureRefCount(slides.get(0).getBackground(), fill)); - shape = slides.get(0).getShapes().get(0); - assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType()); - - fill = slides.get(1).getBackground().getFill(); - assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType()); - shape = slides.get(1).getShapes().get(0); - assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType()); - - fill = slides.get(2).getBackground().getFill(); - assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType()); - assertEquals(3, getFillPictureRefCount(slides.get(2).getBackground(), fill)); - shape = slides.get(2).getShapes().get(0); - assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType()); - assertEquals(1, getFillPictureRefCount(shape, fill)); - - fill = slides.get(3).getBackground().getFill(); - 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) { - AbstractEscherOptRecord opt = shape.getEscherOptRecord(); - EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherPropertyTypes.FILL__PATTERNTEXTURE); - if(p != null) { - int idx = p.getPropertyValue(); - - HSLFSheet sheet = shape.getSheet(); - HSLFSlideShow ppt = sheet.getSlideShow(); - Document doc = ppt.getDocumentRecord(); - EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); - EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); - return ((EscherBSERecord) bstore.getChild(idx - 1)).getRef(); - } - return 0; - } - -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java deleted file mode 100644 index 17ddfa4a8a..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ /dev/null @@ -1,880 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.apache.poi.POITestCase.assertContains; -import static org.apache.poi.POITestCase.assertStartsWith; -import static org.apache.poi.hslf.HSLFTestDataSamples.writeOutAndReadBack; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.awt.Color; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Path2D; -import java.awt.geom.Rectangle2D; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.common.usermodel.fonts.FontGroup; -import org.apache.poi.ddf.AbstractEscherOptRecord; -import org.apache.poi.ddf.EscherArrayProperty; -import org.apache.poi.ddf.EscherColorRef; -import org.apache.poi.ddf.EscherPropertyTypes; -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.apache.poi.hslf.exceptions.OldPowerPointFormatException; -import org.apache.poi.hslf.model.HeadersFooters; -import org.apache.poi.hslf.record.DocInfoListContainer; -import org.apache.poi.hslf.record.Document; -import org.apache.poi.hslf.record.RecordTypes; -import org.apache.poi.hslf.record.SlideListWithText; -import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; -import org.apache.poi.hslf.record.TextHeaderAtom; -import org.apache.poi.hslf.record.VBAInfoAtom; -import org.apache.poi.hslf.record.VBAInfoContainer; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.poifs.macros.VBAMacroReader; -import org.apache.poi.sl.draw.DrawPaint; -import org.apache.poi.sl.extractor.SlideShowExtractor; -import org.apache.poi.sl.usermodel.ColorStyle; -import org.apache.poi.sl.usermodel.PaintStyle; -import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint; -import org.apache.poi.sl.usermodel.PictureData.PictureType; -import org.apache.poi.sl.usermodel.Placeholder; -import org.apache.poi.sl.usermodel.ShapeType; -import org.apache.poi.sl.usermodel.Slide; -import org.apache.poi.sl.usermodel.SlideShow; -import org.apache.poi.sl.usermodel.SlideShowFactory; -import org.apache.poi.sl.usermodel.TextBox; -import org.apache.poi.sl.usermodel.TextParagraph; -import org.apache.poi.sl.usermodel.TextParagraph.TextAlign; -import org.apache.poi.sl.usermodel.TextRun; -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.StringUtil; -import org.apache.poi.util.Units; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.junit.jupiter.params.provider.ValueSource; - -/** - * Testcases for bugs entered in bugzilla - * the Test name contains the bugzilla bug id - */ -public final class TestBugs { - /** - * Bug 41384: Array index wrong in record creation - */ - @Test - void bug41384() throws IOException { - try (HSLFSlideShow ppt = open("41384.ppt")) { - assertEquals(1, ppt.getSlides().size()); - - List<HSLFPictureData> pict = ppt.getPictureData(); - assertEquals(2, pict.size()); - assertEquals(PictureType.JPEG, pict.get(0).getType()); - assertEquals(PictureType.JPEG, pict.get(1).getType()); - } - } - - /** - * First fix from Bug 42474: NPE in RichTextRun.isBold() - * when the RichTextRun comes from a Notes model object - */ - @Test - void bug42474_1() throws IOException { - try (HSLFSlideShow ppt = open("42474-1.ppt")) { - assertEquals(2, ppt.getSlides().size()); - - List<HSLFTextParagraph> txrun; - HSLFNotes notes; - - notes = ppt.getSlides().get(0).getNotes(); - assertNotNull(notes); - txrun = notes.getTextParagraphs().get(0); - assertEquals("Notes-1", HSLFTextParagraph.getRawText(txrun)); - assertFalse(txrun.get(0).getTextRuns().get(0).isBold()); - - //notes for the second slide are in bold - notes = ppt.getSlides().get(1).getNotes(); - assertNotNull(notes); - txrun = notes.getTextParagraphs().get(0); - assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun)); - assertTrue(txrun.get(0).getTextRuns().get(0).isBold()); - } - } - - /** - * Second fix from Bug 42474: Incorrect matching of notes to slides - */ - @Test - void bug42474_2() throws IOException { - try (HSLFSlideShow ppt = open("42474-2.ppt")) { - - //map slide number and starting phrase of its notes - Map<Integer, String> notesMap = new HashMap<>(); - notesMap.put(4, "For decades before calculators"); - notesMap.put(5, "Several commercial applications"); - notesMap.put(6, "There are three variations of LNS that are discussed here"); - notesMap.put(7, "Although multiply and square root are easier"); - notesMap.put(8, "The bus Z is split into Z_H and Z_L"); - - for (HSLFSlide slide : ppt.getSlides()) { - Integer slideNumber = slide.getSlideNumber(); - HSLFNotes notes = slide.getNotes(); - if (notesMap.containsKey(slideNumber)) { - assertNotNull(notes); - String text = HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(0)); - String startingPhrase = notesMap.get(slideNumber); - assertStartsWith("Notes for slide " + slideNumber + " must start with starting phrase", - text, startingPhrase); - } - } - } - } - - /** - * Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns - */ - @Test - void bug42485 () throws IOException { - try (HSLFSlideShow ppt = open("42485.ppt")) { - for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) { - if (shape instanceof HSLFGroupShape) { - HSLFGroupShape group = (HSLFGroupShape) shape; - for (HSLFShape sh : group.getShapes()) { - if (sh instanceof HSLFTextBox) { - HSLFTextBox txt = (HSLFTextBox) sh; - assertNotNull(txt.getTextParagraphs()); - } - } - } - } - } - } - - /** - * Bug 42484: NullPointerException from ShapeGroup.getAnchor() - */ - @Test - void bug42484 () throws IOException { - try (HSLFSlideShow ppt = open("42485.ppt")) { - for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) { - if (shape instanceof HSLFGroupShape) { - HSLFGroupShape group = (HSLFGroupShape) shape; - assertNotNull(group.getAnchor()); - for (HSLFShape sh : group.getShapes()) { - assertNotNull(sh.getAnchor()); - } - } - } - } - } - - /** - * Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file - */ - @Test - void bug41381() throws IOException { - try (HSLFSlideShow ppt = open("alterman_security.ppt")) { - assertEquals(1, ppt.getSlideMasters().size()); - assertEquals(1, ppt.getTitleMasters().size()); - boolean isFirst = true; - for (HSLFSlide slide : ppt.getSlides()) { - HSLFMasterSheet master = slide.getMasterSheet(); - // the first slide follows TitleMaster - assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster); - isFirst = false; - } - } - } - - /** - * Bug 42524: NPE in Shape.getShapeType() - */ - @Test - void bug42524 () throws IOException { - try (HSLFSlideShow ppt = open("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()) { - assertNotNull(shape.getShapeName()); - if (shape instanceof HSLFGroupShape) { - HSLFGroupShape group = (HSLFGroupShape) shape; - for (HSLFShape comps : group.getShapes()) { - assertNotNull(comps.getShapeName()); - } - } - } - } - } - } - - /** - * Bug 42520: NPE in Picture.getPictureData() - */ - @SuppressWarnings("unused") - @Test - void bug42520() throws IOException { - try (HSLFSlideShow ppt = open("42520.ppt")) { - - //test case from the bug report - HSLFGroupShape shapeGroup = (HSLFGroupShape) ppt.getSlides().get(11).getShapes().get(10); - HSLFPictureShape picture = (HSLFPictureShape) shapeGroup.getShapes().get(0); - picture.getPictureData(); - - boolean found = false; - - //walk down the tree and see if there were no errors while reading - for (HSLFSlide slide : ppt.getSlides()) { - for (HSLFShape shape : slide.getShapes()) { - if (shape instanceof HSLFGroupShape) { - HSLFGroupShape group = (HSLFGroupShape) shape; - for (HSLFShape comp : group.getShapes()) { - if (comp instanceof HSLFPictureShape) { - HSLFPictureData pict = ((HSLFPictureShape) comp).getPictureData(); - assertEquals("Rectangle 35893", comp.getShapeName()); - found = true; - } - } - } - } - } - - assertTrue(found); - } - } - - /** - * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0. - * ( also fixed followup: getTextRuns() returns no text ) - */ - @Test - void bug38256 () throws IOException { - try (HSLFSlideShow ppt = open("38256.ppt")) { - List<HSLFSlide> slide = ppt.getSlides(); - assertEquals(1, slide.size()); - List<List<HSLFTextParagraph>> paras = slide.get(0).getTextParagraphs(); - assertEquals(4, paras.size()); - - Set<String> expected = new HashSet<>(); - expected.add("\u201CHAPPY BIRTHDAY SCOTT\u201D"); - expected.add("Have a HAPPY DAY"); - expected.add("PS Nobody is allowed to hassle Scott TODAY\u2026"); - expected.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!"); - - for (List<HSLFTextParagraph> para : paras) { - String text = HSLFTextParagraph.getRawText(para); - assertTrue(expected.contains(text), text); - } - } - } - - /** - * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0. - * ( also fixed followup: getTextRuns() returns no text ) - */ - @Test - void bug43781() throws IOException { - try (HSLFSlideShow ppt = open("43781.ppt")) { - // Check the first slide - HSLFSlide slide = ppt.getSlides().get(0); - List<List<HSLFTextParagraph>> 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()); - assertFalse(slTr.get(1).get(0).isDrawingBased()); - assertTrue(slTr.get(2).get(0).isDrawingBased()); - assertEquals("", HSLFTextParagraph.getRawText(slTr.get(0))); - assertEquals("First run", HSLFTextParagraph.getRawText(slTr.get(1))); - assertEquals("Second run", HSLFTextParagraph.getRawText(slTr.get(2))); - - // Check the shape based text runs - List<HSLFTextParagraph> lst = new ArrayList<>(); - for (HSLFShape shape : slide.getShapes()) { - if (shape instanceof HSLFTextShape) { - List<HSLFTextParagraph> textRun = ((HSLFTextShape) shape).getTextParagraphs(); - lst.addAll(textRun); - } - - } - - // There are two shapes in the ppt - assertEquals(2, lst.size()); - assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst)); - } - } - - /** - * Bug 44296: HSLF Not Extracting Slide Background Image - */ - @Test - void bug44296 () throws IOException { - try (HSLFSlideShow ppt = open("44296.ppt")) { - HSLFSlide slide = ppt.getSlides().get(0); - - HSLFBackground b = slide.getBackground(); - assertNotNull(b); - HSLFFill f = b.getFill(); - assertEquals(HSLFFill.FILL_PICTURE, f.getFillType()); - - HSLFPictureData pict = f.getPictureData(); - assertNotNull(pict); - assertEquals(PictureType.JPEG, pict.getType()); - } - } - - /** - * Bug 41071: Will not extract text from Powerpoint TextBoxes - */ - @Test - void bug41071() throws IOException { - try (HSLFSlideShow ppt = open("41071.ppt")) { - HSLFSlide slide = ppt.getSlides().get(0); - List<HSLFShape> sh = slide.getShapes(); - assertEquals(1, sh.size()); - assertTrue(sh.get(0) instanceof HSLFTextShape); - HSLFTextShape tx = (HSLFTextShape) sh.get(0); - assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(tx.getTextParagraphs())); - - List<List<HSLFTextParagraph>> run = slide.getTextParagraphs(); - assertEquals(3, run.size()); - assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2))); - } - } - - /** - * PowerPoint 95 files should throw a more helpful exception - */ - @Test - void bug41711() throws IOException { - // New file is fine - open("SampleShow.ppt").close(); - - // PowerPoint 95 gives an old format exception - assertThrows(OldPowerPointFormatException.class, () -> open("PPT95.ppt").close()); - } - - /** - * Changing text from Ascii to Unicode - */ - @Test - void bug49648() throws IOException { - try (HSLFSlideShow ppt = open("49648.ppt")) { - for (HSLFSlide slide : ppt.getSlides()) { - for (List<HSLFTextParagraph> run : slide.getTextParagraphs()) { - String repl = "With \u0123\u1234\u5678 unicode"; - String text = HSLFTextParagraph.getRawText(run); - text = text.replace("{txtTot}", repl); - HSLFTextParagraph.setText(run, text); - if (text.contains(repl)) { - assertTrue(HSLFTextParagraph.getText(run).contains(repl)); - } - } - } - } - } - - /** - * Bug 45776: Fix corrupt file problem using TextRun.setText - */ - @Test - void bug45776() throws IOException { - DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ROOT); - try (HSLFSlideShow ppt = open("45776.ppt")) { - - // get slides - for (HSLFSlide slide : ppt.getSlides()) { - for (HSLFShape shape : slide.getShapes()) { - if (!(shape instanceof HSLFTextBox)) { - continue; - } - HSLFTextBox tb = (HSLFTextBox) shape; - // work with TextBox - String str = tb.getText(); - - if (!str.contains("$$DATE$$")) { - continue; - } - str = str.replace("$$DATE$$", df.format(new Date())); - tb.setText(str); - - List<HSLFTextParagraph> tr = tb.getTextParagraphs(); - assertEquals(str.length() + 1, tr.get(0).getParagraphStyle().getCharactersCovered()); - assertEquals(str.length() + 1, tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered()); - } - } - - } - } - - @Test - void bug55732() throws IOException { - try (HSLFSlideShow ppt = open("bug55732.ppt")) { - /* Iterate over slides and extract text */ - for (HSLFSlide slide : ppt.getSlides()) { - HeadersFooters hf = slide.getHeadersFooters(); - assertDoesNotThrow(hf::isHeaderVisible); - } - } - } - - @Test - void bug56260() throws IOException { - try (HSLFSlideShow ppt = open("56260.ppt")) { - List<HSLFSlide> _slides = ppt.getSlides(); - assertEquals(13, _slides.size()); - - // Check the number of TextHeaderAtoms on Slide 1 - Document dr = ppt.getDocumentRecord(); - SlideListWithText slidesSLWT = dr.getSlideSlideListWithText(); - assertNotNull(slidesSLWT); - SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0]; - - int tha = 0; - for (org.apache.poi.hslf.record.Record r : s1.getSlideRecords()) { - 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; - for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) { - if (!tr.get(0).isDrawingBased()) { - str++; - } - } - assertEquals(2, str); - } - } - - @Test - void bug49541() throws IOException { - try (HSLFSlideShow ppt = open("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); - } - } - - @ParameterizedTest - @CsvSource({ - // bug47261.ppt has actually 16 slides, but also non-conforming multiple document records - "bug47261.ppt, 1", - "bug56240.ppt, 105", - "bug58516.ppt, 5", - "57272_corrupted_usereditatom.ppt, 6", - "37625.ppt, 29", - // Bug 41246: AIOOB with illegal note references - "41246-1.ppt, 36", - "41246-2.ppt, 16", - // Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for - // type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing - "44770.ppt, 19", - // Bug 42486: Failure parsing a seemingly valid PPT - "42486.ppt, 33" - }) - void testFile(String file, int slideCnt) throws IOException { - try (HSLFSlideShow ppt = open(file)) { - for (HSLFSlide slide : ppt.getSlides()) { - List<HSLFShape> shape = slide.getShapes(); - assertFalse(shape.isEmpty()); - } - - assertNotNull(ppt.getSlides().get(0)); - ppt.removeSlide(0); - ppt.createSlide(); - try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt)) { - assertEquals(slideCnt, ppt2.getSlides().size()); - }; - } - } - - @Test - void bug46441() throws IOException { - try (HSLFSlideShow ppt = open("bug46441.ppt")) { - HSLFAutoShape as = (HSLFAutoShape) ppt.getSlides().get(0).getShapes().get(0); - AbstractEscherOptRecord opt = as.getEscherOptRecord(); - EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherPropertyTypes.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++; - } - } - } - - @Test - void bug45124() throws IOException { - try (HSLFSlideShow ppt = open("bug45124.ppt")) { - Slide<?, ?> slide1 = ppt.getSlides().get(1); - - 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'); - - try (SlideShow<?, ?> ppt2 = writeOutAndReadBack(ppt)) { - 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(); - assertTrue(ps instanceof SolidPaint); - Color actColor = DrawPaint.applyColorTransform(((SolidPaint) ps).getSolidColor()); - assertEquals(Color.red, actColor); - assertEquals("A", tp.getBulletStyle().getBulletCharacter()); - } - } - } - - @Test - void bug45088() throws IOException { - String template = "[SYSDATE]"; - String textExp = "REPLACED_DATE_WITH_A_LONG_ONE"; - - try (HSLFSlideShow ppt1 = open("bug45088.ppt")) { - for (HSLFSlide slide : ppt1.getSlides()) { - for (List<HSLFTextParagraph> paraList : slide.getTextParagraphs()) { - for (HSLFTextParagraph para : paraList) { - for (HSLFTextRun run : para.getTextRuns()) { - String text = run.getRawText(); - if (text != null && text.contains(template)) { - String replacedText = text.replace(template, textExp); - run.setText(replacedText); - para.setDirty(); - } - } - } - } - } - - try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) { - HSLFTextBox tb = (HSLFTextBox) ppt2.getSlides().get(0).getShapes().get(1); - String textAct = tb.getTextParagraphs().get(0).getTextRuns().get(0).getRawText().trim(); - assertEquals(textExp, textAct); - } - } - } - - @Test - void bug45908() throws IOException { - try (HSLFSlideShow ppt1 = open("bug45908.ppt")) { - - HSLFSlide slide = ppt1.getSlides().get(0); - HSLFAutoShape styleShape = (HSLFAutoShape) slide.getShapes().get(1); - HSLFTextParagraph tp0 = styleShape.getTextParagraphs().get(0); - HSLFTextRun tr0 = tp0.getTextRuns().get(0); - - - int rows = 5; - int cols = 2; - HSLFTable table = slide.createTable(rows, cols); - for (int i = 0; i < rows; i++) { - for (int j = 0; j < cols; j++) { - - HSLFTableCell cell = table.getCell(i, j); - assertNotNull(cell); - cell.setText("Test"); - - HSLFTextParagraph tp = cell.getTextParagraphs().get(0); - tp.setBulletStyle('%', tp0.getBulletColor(), tp0.getBulletFont(), tp0.getBulletSize()); - tp.setIndent(tp0.getIndent()); - tp.setTextAlign(tp0.getTextAlign()); - tp.setIndentLevel(tp0.getIndentLevel()); - tp.setSpaceAfter(tp0.getSpaceAfter()); - tp.setSpaceBefore(tp0.getSpaceBefore()); - tp.setBulletStyle(); - - HSLFTextRun tr = tp.getTextRuns().get(0); - tr.setBold(tr0.isBold()); - // rt.setEmbossed(); - tr.setFontColor(Color.BLACK); - tr.setFontFamily(tr0.getFontFamily()); - tr.setFontSize(tr0.getFontSize()); - tr.setItalic(tr0.isItalic()); - tr.setShadowed(tr0.isShadowed()); - tr.setStrikethrough(tr0.isStrikethrough()); - tr.setUnderlined(tr0.isUnderlined()); - } - } - - table.moveTo(100, 100); - - try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) { - - HSLFTable tab = (HSLFTable) ppt2.getSlides().get(0).getShapes().get(2); - HSLFTableCell c2 = tab.getCell(0, 0); - assertNotNull(c2); - HSLFTextParagraph tp1 = c2.getTextParagraphs().get(0); - HSLFTextRun tr1 = tp1.getTextRuns().get(0); - assertFalse(tp1.isBullet()); - assertEquals(tp0.getBulletColor(), tp1.getBulletColor()); - assertEquals(tp0.getBulletFont(), tp1.getBulletFont()); - assertEquals(tp0.getBulletSize(), tp1.getBulletSize()); - assertEquals(tp0.getIndent(), tp1.getIndent()); - assertEquals(tp0.getTextAlign(), tp1.getTextAlign()); - assertEquals(tp0.getIndentLevel(), tp1.getIndentLevel()); - assertEquals(tp0.getSpaceAfter(), tp1.getSpaceAfter()); - assertEquals(tp0.getSpaceBefore(), tp1.getSpaceBefore()); - assertEquals(tr0.isBold(), tr1.isBold()); - assertNotNull(tr1.getFontColor()); - assertEquals(Color.black, DrawPaint.applyColorTransform(tr1.getFontColor().getSolidColor())); - assertEquals(tr0.getFontFamily(), tr1.getFontFamily()); - assertEquals(tr0.getFontSize(), tr1.getFontSize()); - assertEquals(tr0.isItalic(), tr1.isItalic()); - assertEquals(tr0.isShadowed(), tr1.isShadowed()); - assertEquals(tr0.isStrikethrough(), tr1.isStrikethrough()); - assertEquals(tr0.isUnderlined(), tr1.isUnderlined()); - } - } - } - - @Test - void bug47904() throws IOException { - try (HSLFSlideShow ppt1 = new HSLFSlideShow()) { - HSLFSlideMaster sm = ppt1.getSlideMasters().get(0); - HSLFAutoShape as = (HSLFAutoShape) sm.getPlaceholder(Placeholder.TITLE); - HSLFTextParagraph tp = as.getTextParagraphs().get(0); - HSLFTextRun tr = tp.getTextRuns().get(0); - tr.setFontFamily("Tahoma"); - tr.setShadowed(true); - tr.setFontSize(44.); - tr.setFontColor(Color.red); - tp.setTextAlign(TextAlign.RIGHT); - HSLFTextBox tb = ppt1.createSlide().addTitle(); - tb.setText("foobaa"); - - try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) { - HSLFTextShape ts = (HSLFTextShape) ppt2.getSlides().get(0).getShapes().get(0); - tp = ts.getTextParagraphs().get(0); - tr = tp.getTextRuns().get(0); - assertNotNull(tr); - assertNotNull(tr.getFontSize()); - assertEquals(44., tr.getFontSize(), 0); - assertEquals("Tahoma", tr.getFontFamily()); - assertNotNull(tr.getFontColor()); - Color colorAct = DrawPaint.applyColorTransform(tr.getFontColor().getSolidColor()); - assertEquals(Color.red, colorAct); - assertEquals(TextAlign.RIGHT, tp.getTextAlign()); - assertEquals("foobaa", tr.getRawText()); - } - } - } - - @ParameterizedTest - @ValueSource(strings = { - "bug58718_008524.ppt", "bug58718_008558.ppt", "bug58718_349008.ppt", "bug58718_008495.ppt", - "bug58733_671884.ppt" - }) - void bug58718(String file) throws IOException { - File sample = HSLFTestDataSamples.getSampleFile(file); - try (SlideShowExtractor<?,?> ex = new SlideShowExtractor<>(SlideShowFactory.create(sample))) { - assertNotNull(ex.getText()); - } - } - - @Test - void bug58159() throws IOException { - try (HSLFSlideShow ppt = open("bug58159_headers-and-footers.ppt")) { - HeadersFooters hf = ppt.getSlideHeadersFooters(); - assertNull(hf.getHeaderText()); - assertEquals("Slide footer", hf.getFooterText()); - hf = ppt.getNotesHeadersFooters(); - assertEquals("Notes header", hf.getHeaderText()); - assertEquals("Notes footer", hf.getFooterText()); - HSLFSlide sl = ppt.getSlides().get(0); - hf = sl.getHeadersFooters(); - assertNull(hf.getHeaderText()); - assertEquals("Slide footer", hf.getFooterText()); - for (HSLFShape shape : sl.getShapes()) { - if (shape instanceof HSLFTextShape) { - HSLFTextShape ts = (HSLFTextShape) shape; - Placeholder ph = ts.getPlaceholder(); - if (Placeholder.FOOTER == ph) { - assertEquals("Slide footer", ts.getText()); - } - } - } - } - } - - @Test - void bug55030() throws IOException { - try (HSLFSlideShow ppt = open("bug55030.ppt")) { - String expFamily = "\u96b6\u4e66"; - - HSLFSlide sl = ppt.getSlides().get(0); - for (List<HSLFTextParagraph> paraList : sl.getTextParagraphs()) { - for (HSLFTextParagraph htp : paraList) { - for (HSLFTextRun htr : htp) { - String actFamily = htr.getFontFamily(FontGroup.EAST_ASIAN); - assertEquals(expFamily, actFamily); - } - } - } - } - } - - private static HSLFSlideShow open(String fileName) throws IOException { - File sample = HSLFTestDataSamples.getSampleFile(fileName); - // Note: don't change the code here, it is required for Eclipse to compile the code - SlideShow<?,?> slideShowOrig = SlideShowFactory.create(sample, null, false); - return (HSLFSlideShow)slideShowOrig; - } - - @Test - void bug55983() throws IOException { - try (HSLFSlideShow ppt1 = new HSLFSlideShow()) { - HSLFSlide sl = ppt1.createSlide(); - assertNotNull(sl.getBackground()); - HSLFFill fill = sl.getBackground().getFill(); - assertNotNull(fill); - fill.setForegroundColor(Color.blue); - HSLFFreeformShape fs = sl.createFreeform(); - Ellipse2D.Double el = new Ellipse2D.Double(0, 0, 300, 200); - fs.setAnchor(new Rectangle2D.Double(100, 100, 300, 200)); - fs.setPath(new Path2D.Double(el)); - Color cExp = new Color(50, 100, 150, 200); - fs.setFillColor(cExp); - - try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) { - sl = ppt2.getSlides().get(0); - fs = (HSLFFreeformShape) sl.getShapes().get(0); - Color cAct = fs.getFillColor(); - assertEquals(cExp.getRed(), cAct.getRed()); - assertEquals(cExp.getGreen(), cAct.getGreen()); - assertEquals(cExp.getBlue(), cAct.getBlue()); - assertEquals(cExp.getAlpha(), cAct.getAlpha(), 1); - - PaintStyle ps = fs.getFillStyle().getPaint(); - assertTrue(ps instanceof SolidPaint); - ColorStyle cs = ((SolidPaint) ps).getSolidColor(); - cAct = cs.getColor(); - assertEquals(cExp.getRed(), cAct.getRed()); - assertEquals(cExp.getGreen(), cAct.getGreen()); - assertEquals(cExp.getBlue(), cAct.getBlue()); - assertEquals(255, cAct.getAlpha()); - assertEquals(cExp.getAlpha() * 100000. / 255., cs.getAlpha(), 1); - } - } - } - - @Test - void bug59302() throws IOException { - //add extraction from PPT - Map<String, String> macros = getMacrosFromHSLF("59302.ppt"); - assertNotNull(macros, "couldn't find macros"); - assertNotNull(macros.get("Module2"), "couldn't find second module"); - assertContains(macros.get("Module2"), "newMacro in Module2"); - - assertNotNull(macros.get("Module1"), "couldn't find first module"); - assertContains(macros.get("Module1"), "Italicize"); - - macros = getMacrosFromHSLF("SimpleMacro.ppt"); - assertNotNull(macros); - assertNotNull(macros.get("Module1")); - assertContains(macros.get("Module1"), "This is a macro slideshow"); - } - - //It isn't pretty, but it works... - private Map<String, String> getMacrosFromHSLF(String fileName) throws IOException { - try (InputStream is = new FileInputStream(POIDataSamples.getSlideShowInstance().getFile(fileName)); - POIFSFileSystem poifs = new POIFSFileSystem(is); - HSLFSlideShow ppt = new HSLFSlideShow(poifs)) { - //TODO: should we run the VBAMacroReader on this poifs? - //TBD: We know that ppt typically don't store macros in the regular place, - //but _can_ they? - - //get macro persist id - DocInfoListContainer list = (DocInfoListContainer)ppt.getDocumentRecord().findFirstOfType(RecordTypes.List.typeID); - VBAInfoContainer vbaInfo = (VBAInfoContainer)list.findFirstOfType(RecordTypes.VBAInfo.typeID); - VBAInfoAtom vbaAtom = (VBAInfoAtom)vbaInfo.findFirstOfType(RecordTypes.VBAInfoAtom.typeID); - long persistId = vbaAtom.getPersistIdRef(); - for (HSLFObjectData objData : ppt.getEmbeddedObjects()) { - if (objData.getExOleObjStg().getPersistId() == persistId) { - try (VBAMacroReader mr = new VBAMacroReader(objData.getInputStream())) { - return mr.readMacros(); - } - } - } - } - return null; - } - - /** - * Bug 60294: Add "unknown" ShapeType for 4095 - */ - @Test - void bug60294() throws IOException { - try (HSLFSlideShow ppt = open("60294.ppt")) { - List<HSLFShape> shList = ppt.getSlides().get(0).getShapes(); - assertEquals(ShapeType.NOT_PRIMITIVE, shList.get(2).getShapeType()); - } - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java deleted file mode 100644 index d4dce2b13f..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java +++ /dev/null @@ -1,79 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.util.List; - -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.junit.jupiter.api.Test; - -/** - * Tests that SlideShow returns the right number of Sheets and MetaSheets - */ -public final class TestCounts { - @Test - void testSheetsCount() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); - - List<HSLFSlide> slides = ppt.getSlides(); - // Two sheets - master sheet is separate - assertEquals(2, slides.size()); - - // They are slides 1+2 - assertEquals(1, slides.get(0).getSlideNumber()); - assertEquals(2, slides.get(1).getSlideNumber()); - - // The ref IDs are 4 and 6 - assertEquals(4, slides.get(0)._getSheetRefId()); - assertEquals(6, slides.get(1)._getSheetRefId()); - - // These are slides 1+2 -> 256+257 - assertEquals(256, slides.get(0)._getSheetNumber()); - assertEquals(257, slides.get(1)._getSheetNumber()); - - ppt.close(); - } - - @Test - void testNotesCount() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); - - List<HSLFNotes> notes = ppt.getNotes(); - // Two sheets -> two notes - // Note: there are also notes on the slide master - //assertEquals(3, notes.length); // When we do slide masters - assertEquals(2, notes.size()); - - // First is for master - //assertEquals(-2147483648, notes.get(0)._getSheetNumber()); // When we do slide masters - - // Next two are for the two slides - assertEquals(256, notes.get(0)._getSheetNumber()); - assertEquals(257, notes.get(1)._getSheetNumber()); - - // They happen to go between the two slides in Ref terms - assertEquals(5, notes.get(0)._getSheetRefId()); - assertEquals(7, notes.get(1)._getSheetRefId()); - - ppt.close(); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java deleted file mode 100644 index b3d6785aec..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java +++ /dev/null @@ -1,124 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontFormatException; -import java.awt.Graphics2D; -import java.awt.GraphicsEnvironment; -import java.awt.RenderingHints; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferByte; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import javax.imageio.ImageIO; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.sl.draw.Drawable; -import org.apache.poi.util.TempFile; -import org.junit.jupiter.api.Test; - -/** - * Test font rendering of alternative and fallback fonts - */ -public class TestFontRendering { - private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); - - // @Disabled2("This fails on some systems because fonts are rendered slightly different") - @Test - void bug55902mixedFontWithChineseCharacters() throws IOException, FontFormatException { - // font files need to be downloaded first via - // ant test-scratchpad-download-resources - String[][] fontFiles = { - // Calibri is not available on *nix systems, so we need to use another similar free font - {"build/scratchpad-test-resources/Cabin-Regular.ttf", "mapped", "Calibri"}, - - // use "MS PGothic" if available (Windows only) ... - // for the junit test not all chars are rendered - {"build/scratchpad-test-resources/mona.ttf", "fallback", "Cabin"} - }; - - // setup fonts (especially needed, when run under *nix systems) - GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); - Map<String,String> fontMap = new HashMap<>(); - Map<String,String> fallbackMap = new HashMap<>(); - - for (String[] fontFile : fontFiles) { - File f = new File(fontFile[0]); - assumeTrue(f.exists(), "necessary font file "+f.getName()+" not downloaded."); - - Font font = Font.createFont(Font.TRUETYPE_FONT, f); - ge.registerFont(font); - - Map<String,String> map = ("mapped".equals(fontFile[1]) ? fontMap : fallbackMap); - map.put(fontFile[2], font.getFamily()); - } - - InputStream is = slTests.openResourceAsStream("bug55902-mixedFontChineseCharacters.ppt"); - HSLFSlideShow ss = new HSLFSlideShow(is); - is.close(); - - Dimension pgsize = ss.getPageSize(); - - HSLFSlide slide = ss.getSlides().get(0); - - // render it - double zoom = 1; - AffineTransform at = new AffineTransform(); - at.setToScale(zoom, zoom); - - BufferedImage imgActual = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_3BYTE_BGR); - Graphics2D graphics = imgActual.createGraphics(); - graphics.setRenderingHint(Drawable.FONT_FALLBACK, fallbackMap); - graphics.setRenderingHint(Drawable.FONT_MAP, fontMap); - graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - graphics.setTransform(at); - graphics.setPaint(Color.white); - graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); - slide.draw(graphics); - - BufferedImage imgExpected = ImageIO.read(slTests.getFile("bug55902-mixedChars.png")); - DataBufferByte expectedDB = (DataBufferByte)imgExpected.getRaster().getDataBuffer(); - DataBufferByte actualDB = (DataBufferByte)imgActual.getRaster().getDataBuffer(); - byte[] expectedData = expectedDB.getData(0); - byte[] actualData = actualDB.getData(0); - - // allow to find out what the actual difference is in CI where this fails currently - if(!Arrays.equals(expectedData, actualData)) { - ImageIO.write(imgActual, "PNG", TempFile.createTempFile("TestFontRendering", ".png")); - } - - assertArrayEquals(expectedData, actualData, "Expected to have matching raster-arrays, but found differences"); - ss.close(); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java deleted file mode 100644 index e1f453327d..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java +++ /dev/null @@ -1,52 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.apache.poi.sl.usermodel.BaseTestSlideShow; -import org.apache.poi.sl.usermodel.SlideShow; -import org.junit.jupiter.api.Test; - -public class TestHSLFSlideShow extends BaseTestSlideShow<HSLFShape, HSLFTextParagraph> { - @Override - public HSLFSlideShow createSlideShow() { - return new HSLFSlideShow(); - } - - // make sure junit4 executes this test class - @Test - void dummy() { - assertNotNull(createSlideShow()); - } - - public HSLFSlideShow reopen(SlideShow<HSLFShape, HSLFTextParagraph> show) throws IOException { - BufAccessBAOS bos = new BufAccessBAOS(); - show.write(bos); - return new HSLFSlideShow(new ByteArrayInputStream(bos.getBuf())); - } - - private static class BufAccessBAOS extends ByteArrayOutputStream { - byte[] getBuf() { - return buf; - } - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java deleted file mode 100644 index d82c659d71..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShowFactory.java +++ /dev/null @@ -1,28 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import org.apache.poi.sl.usermodel.BaseTestSlideShowFactory; -import org.junit.jupiter.api.Test; - -public final class TestHSLFSlideShowFactory extends BaseTestSlideShowFactory { - @Test - void testFactory() throws Exception { - testFactory("pictures.ppt", "Password_Protected-hello.ppt", "hello"); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java deleted file mode 100644 index d96201b89f..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java +++ /dev/null @@ -1,100 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.apache.poi.POIDataSamples; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests that SlideShow finds the right records as its most recent ones - */ -public final class TestMostRecentRecords { - // HSLFSlideShow primed on the test data - private HSLFSlideShowImpl hss; - // SlideShow primed on the test data - private HSLFSlideShow ss; - - @BeforeEach - void setup() throws Exception { - POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); - hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); - ss = new HSLFSlideShow(hss); - } - - @Test - void testCount() { - // Most recent core records - org.apache.poi.hslf.record.Record[] mrcr = ss.getMostRecentCoreRecords(); - - // Master sheet + master notes + 2 slides + 2 notes + document - assertEquals(7, mrcr.length); - } - - @Test - void testRightRecordTypes() { - // Most recent core records - org.apache.poi.hslf.record.Record[] mrcr = ss.getMostRecentCoreRecords(); - - // Document - assertEquals(1000, mrcr[0].getRecordType()); - // Notes of master - assertEquals(1008, mrcr[1].getRecordType()); - // Master - assertEquals(1016, mrcr[2].getRecordType()); - - // Slide - assertEquals(1006, mrcr[3].getRecordType()); - // Notes - assertEquals(1008, mrcr[4].getRecordType()); - // Slide - assertEquals(1006, mrcr[5].getRecordType()); - // Notes - assertEquals(1008, mrcr[6].getRecordType()); - } - - @Test - void testCorrectRecords() { - // Most recent core records - org.apache.poi.hslf.record.Record[] mrcr = ss.getMostRecentCoreRecords(); - - // All records - org.apache.poi.hslf.record.Record[] allr = hss.getRecords(); - - // Ensure they are the right (latest) version of each - - // Document - late version - assertEquals(allr[12], mrcr[0]); - // Notes of master - unchanged - assertEquals(allr[2], mrcr[1]); - // Master - unchanged - assertEquals(allr[1], mrcr[2]); - - // Slide - added at start - assertEquals(allr[3], mrcr[3]); - // Notes - added at start - assertEquals(allr[4], mrcr[4]); - // Slide - added later and then changed - assertEquals(allr[13], mrcr[5]); - // Notes - added later but not changed - assertEquals(allr[9], mrcr[6]); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java deleted file mode 100644 index 69863e5685..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java +++ /dev/null @@ -1,58 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; - -import org.apache.poi.POIDataSamples; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests that SlideShow returns MetaSheets which have the right text in them - */ -public final class TestNotesText { - // SlideShow primed on the test data - private HSLFSlideShow ss; - - @BeforeEach - void setup() throws Exception { - POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); - HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); - ss = new HSLFSlideShow(hss); - } - - @Test - void testNotesOne() { - HSLFNotes notes = ss.getNotes().get(0); - String[] expectText = {"These are the notes for page 1"}; - assertArrayEquals(expectText, toStrings(notes)); - } - - @Test - void testNotesTwo() { - HSLFNotes notes = ss.getNotes().get(1); - String[] expectText = {"These are the notes on page two, again lacking formatting"}; - assertArrayEquals(expectText, toStrings(notes)); - } - - private static String[] toStrings(HSLFNotes notes) { - return notes.getTextParagraphs().stream().map(HSLFTextParagraph::getRawText).toArray(String[]::new); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java deleted file mode 100644 index 6591a13ac7..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; - -import java.util.List; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.hslf.model.textproperties.TextPFException9; -import org.apache.poi.hslf.model.textproperties.TextPropCollection; -import org.apache.poi.hslf.record.EscherTextboxWrapper; -import org.apache.poi.hslf.record.StyleTextProp9Atom; -import org.apache.poi.hslf.record.StyleTextPropAtom; -import org.apache.poi.sl.usermodel.AutoNumberingScheme; -import org.junit.jupiter.api.Test; - - -/** - * Test that checks numbered list functionality. - * - * @author Alex Nikiforov [mailto:anikif@gmail.com] - */ -public final class TestNumberedList { - private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); - - @Test - void testNumberedList() throws Exception { - HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers.ppt")); - final List<HSLFSlide> slides = ppt.getSlides(); - assertEquals(2, slides.size()); - checkSlide0(slides.get(0)); - checkSlide1(slides.get(1)); - ppt.close(); - } - - private void checkSlide0(final HSLFSlide s) { - final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo(); - assertNotNull(numberedListArray); - assertEquals(1, numberedListArray.length);//Just one text box here - final StyleTextProp9Atom numberedListInfo = numberedListArray[0]; - assertNotNull(numberedListInfo); - final TextPFException9[] autoNumbers = numberedListInfo.getAutoNumberTypes(); - assertNotNull(autoNumbers); - assertEquals(4, autoNumbers.length); - assertEquals(4, (short) autoNumbers[0].getAutoNumberStartNumber()); - assertNull(autoNumbers[1].getAutoNumberStartNumber()); - assertEquals(3, (short) autoNumbers[2].getAutoNumberStartNumber()); - assertSame(AutoNumberingScheme.arabicPeriod, autoNumbers[0].getAutoNumberScheme()); - assertNull(autoNumbers[1].getAutoNumberScheme()); - assertSame(AutoNumberingScheme.alphaLcParenRight, autoNumbers[2].getAutoNumberScheme()); - - List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs(); - assertEquals(2, textParass.size()); - - List<HSLFTextParagraph> textParas = textParass.get(0); - assertEquals("titTe", HSLFTextParagraph.getRawText(textParas)); - assertEquals(1, textParas.size()); - assertFalse(textParas.get(0).isBullet()); - - String expected = - "This is a text placeholder that \r" + - "follows the design pattern\r" + - "Just a test\rWithout any paragraph\r" + - "Second paragraph first line c) ;\r" + - "Second paragraph second line d) . \r"; - assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1))); - - final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers(); - assertEquals(textParass.size(), styleAtoms.length); - final EscherTextboxWrapper wrapper = styleAtoms[1]; - final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom(); - final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles(); - assertEquals(60, textProps.get(0).getCharactersCovered()); - assertEquals(34, textProps.get(1).getCharactersCovered()); - assertEquals(68, textProps.get(2).getCharactersCovered()); - } - - private void checkSlide1(final HSLFSlide s) { - final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo(); - assertNotNull(numberedListArray); - assertEquals(1, numberedListArray.length);//Just one text box here - final StyleTextProp9Atom numberedListInfo = numberedListArray[0]; - assertNotNull(numberedListInfo); - final TextPFException9[] autoNumbers = numberedListInfo.getAutoNumberTypes(); - assertNotNull(autoNumbers); - assertEquals(4, autoNumbers.length); - assertEquals(9, (short) autoNumbers[0].getAutoNumberStartNumber()); - assertNull(autoNumbers[1].getAutoNumberStartNumber()); - assertEquals(3, (short) autoNumbers[2].getAutoNumberStartNumber()); - assertSame(AutoNumberingScheme.arabicParenRight, autoNumbers[0].getAutoNumberScheme()); - assertNull(autoNumbers[1].getAutoNumberScheme()); - assertSame(AutoNumberingScheme.alphaUcPeriod, autoNumbers[2].getAutoNumberScheme()); - - final List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs(); - assertEquals(2, textParass.size()); - - List<HSLFTextParagraph> textParas = textParass.get(0); - assertEquals("Second Slide Title", HSLFTextParagraph.getRawText(textParas)); - assertEquals(1, textParas.size()); - assertFalse(textParas.get(0).isBullet()); - - String expected = - "This is a text placeholder that \r" + - "follows the design pattern\r" + - "Just a test\rWithout any paragraph\r" + - "Second paragraph first line c) ;\r" + - "Second paragraph second line d) . \r"; - assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1))); - - final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers(); - assertEquals(textParass.size(), styleAtoms.length); - final EscherTextboxWrapper wrapper = styleAtoms[1]; - final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom(); - final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles(); - - assertEquals(33, textProps.get(0).getCharactersCovered()); - assertEquals(61, textProps.get(1).getCharactersCovered()); - assertEquals(68, textProps.get(2).getCharactersCovered()); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java deleted file mode 100644 index 6e49fd10d7..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.List; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.hslf.model.textproperties.TextPFException9; -import org.apache.poi.hslf.model.textproperties.TextPropCollection; -import org.apache.poi.hslf.record.EscherTextboxWrapper; -import org.apache.poi.hslf.record.StyleTextProp9Atom; -import org.apache.poi.hslf.record.StyleTextPropAtom; -import org.apache.poi.sl.usermodel.AutoNumberingScheme; -import org.junit.jupiter.api.Test; - - -/** - * Test that checks numbered list functionality. - * if a paragraph has autonumber () - * @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28"> - * PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a> - */ -public final class TestNumberedList2 { - private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); - - @Test - void testNumberedList() throws IOException { - try (HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers2.ppt"))) { - final List<HSLFSlide> slides = ppt.getSlides(); - assertEquals(2, slides.size()); - checkSlide0(slides.get(0)); - checkSlide1(slides.get(1)); - } - } - - private void checkSlide0(final HSLFSlide s) { - final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo(); - assertNotNull(numberedListArray); - assertEquals(2, numberedListArray.length); - final StyleTextProp9Atom numberedListInfoForTextBox0 = numberedListArray[0]; - final StyleTextProp9Atom numberedListInfoForTextBox1 = numberedListArray[1]; - assertNotNull(numberedListInfoForTextBox0); - assertNotNull(numberedListInfoForTextBox1); - final TextPFException9[] autoNumbersOfTextBox0 = numberedListInfoForTextBox0.getAutoNumberTypes(); - assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getfBulletHasAutoNumber()); - assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());//Default value = 1 will be used - assertSame(AutoNumberingScheme.arabicPeriod, autoNumbersOfTextBox0[0].getAutoNumberScheme()); - final TextPFException9[] autoNumbersOfTextBox1 = numberedListInfoForTextBox1.getAutoNumberTypes(); - assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox1[0].getfBulletHasAutoNumber()); - assertEquals(Short.valueOf((short)6), autoNumbersOfTextBox1[0].getAutoNumberStartNumber());//Default value = 1 will be used - assertSame(AutoNumberingScheme.arabicPeriod, autoNumbersOfTextBox1[0].getAutoNumberScheme()); - - - List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs(); - assertEquals(2, textParass.size()); - - List<HSLFTextParagraph> textParas = textParass.get(0); - assertEquals("List Item One\rList Item Two\rList Item Three", HSLFTextParagraph.getRawText(textParas)); - assertEquals(3, textParas.size()); - assertTrue(textParas.get(0).isBullet()); - - String expected = - "A numbered list may start at any number \r" + - "This would be used as a continuation list on another page\r" + - "This list should start with #6"; - assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1))); - - final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers(); - assertEquals(textParass.size(), styleAtoms.length); - checkSingleRunWrapper(44, styleAtoms[0]); - checkSingleRunWrapper(130, styleAtoms[1]); - } - - private void checkSlide1(final HSLFSlide s) { - final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo(); - assertNotNull(numberedListArray); - assertEquals(1, numberedListArray.length); - final StyleTextProp9Atom numberedListInfoForTextBox = numberedListArray[0]; - assertNotNull(numberedListInfoForTextBox); - final TextPFException9[] autoNumbersOfTextBox = numberedListInfoForTextBox.getAutoNumberTypes(); - assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox[0].getfBulletHasAutoNumber()); - assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox[0].getAutoNumberStartNumber());//Default value = 1 will be used - assertSame(AutoNumberingScheme.arabicPeriod, autoNumbersOfTextBox[0].getAutoNumberScheme()); - - List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs(); - assertEquals(3, textParass.size()); - - List<HSLFTextParagraph> textParas = textParass.get(0); - assertEquals("Bulleted list\rMore bullets", HSLFTextParagraph.getRawText(textParas)); - assertEquals(2, textParas.size()); - assertTrue(textParas.get(0).isBullet()); - - String expected = "Numbered list between two bulleted lists\rSecond numbered list item"; - assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1))); - expected = "Second bulleted list \u2013 should appear after numbered list\rMore bullets"; - assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(2))); - - final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers(); - assertEquals(textParass.size(), styleAtoms.length); - checkSingleRunWrapper(27, styleAtoms[0]); - checkSingleRunWrapper(67, styleAtoms[1]); - checkSingleRunWrapper(70, styleAtoms[2]); - } - - private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) { - final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom(); - final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles(); - assertEquals(1, textProps.size()); - assertEquals(exceptedLength, textProps.get(0).getCharactersCovered()); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList3.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList3.java deleted file mode 100644 index 6aa90ff6d9..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList3.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.List; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.hslf.model.textproperties.TextPFException9; -import org.apache.poi.hslf.model.textproperties.TextPropCollection; -import org.apache.poi.hslf.record.EscherTextboxWrapper; -import org.apache.poi.hslf.record.StyleTextProp9Atom; -import org.apache.poi.hslf.record.StyleTextPropAtom; -import org.apache.poi.sl.usermodel.AutoNumberingScheme; -import org.junit.jupiter.api.Test; - - -/** - * Test that checks numbered list functionality. - * if a paragraph has autonumber () - * @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28"> - * PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a> - * - * @author Alex Nikiforov [mailto:anikif@gmail.com] - */ -public final class TestNumberedList3 { - private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); - - @Test - void testNumberedList() throws IOException { - try (HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers3.ppt"))) { - final List<HSLFSlide> slides = ppt.getSlides(); - assertEquals(1, slides.size()); - final HSLFSlide slide = slides.get(0); - checkSlide(slide); - } - } - private void checkSlide(final HSLFSlide s) { - final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo(); - assertNotNull(numberedListArray); - assertEquals(1, numberedListArray.length); - final StyleTextProp9Atom numberedListInfoForTextBox = numberedListArray[0]; - assertNotNull(numberedListInfoForTextBox); - final TextPFException9[] autoNumbersOfTextBox0 = numberedListInfoForTextBox.getAutoNumberTypes(); - assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getfBulletHasAutoNumber()); - assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());//Default value = 1 will be used - assertSame(AutoNumberingScheme.arabicPeriod, autoNumbersOfTextBox0[0].getAutoNumberScheme()); - - final List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs(); - assertEquals(3, textParass.size()); - assertEquals("Bulleted list\rMore bullets\rNo bullets here", HSLFTextParagraph.getRawText(textParass.get(0))); - assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", HSLFTextParagraph.getRawText(textParass.get(1))); - assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", HSLFTextParagraph.getRawText(textParass.get(2))); - assertEquals(3, textParass.get(0).size()); - assertEquals(2, textParass.get(1).size()); - assertEquals(2, textParass.get(2).size()); - assertNull(textParass.get(0).get(0).getStyleTextProp9Atom()); - assertNotNull(textParass.get(1).get(0).getStyleTextProp9Atom()); - assertNull(textParass.get(2).get(0).getStyleTextProp9Atom()); - final TextPFException9[] autoNumbers = textParass.get(1).get(0).getStyleTextProp9Atom().getAutoNumberTypes(); - assertEquals(1, autoNumbers.length); - assertEquals(Short.valueOf((short)1), autoNumbers[0].getfBulletHasAutoNumber()); - assertEquals(Short.valueOf((short)1), autoNumbers[0].getAutoNumberStartNumber());//Default value = 1 will be used - assertSame(AutoNumberingScheme.arabicPeriod, autoNumbersOfTextBox0[0].getAutoNumberScheme()); - - int chCovered = 0; - for (HSLFTextParagraph htp : textParass.get(1)) { - for (HSLFTextRun htr : htp.getTextRuns()) { - TextPropCollection textProp = htr.getCharacterStyle(); - chCovered += textProp.getCharactersCovered(); - } - } - assertEquals(67, chCovered); - - assertTrue(textParass.get(0).get(0).isBullet()); - - final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers(); - assertEquals(textParass.size(), styleAtoms.length); - checkSingleRunWrapper(43, styleAtoms[0]); - checkSingleRunWrapper(67, styleAtoms[1]); - } - private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) { - final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom(); - final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles(); - assertEquals(1, textProps.size()); - assertEquals(exceptedLength, textProps.get(0).getCharactersCovered()); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java deleted file mode 100644 index 55a50be321..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java +++ /dev/null @@ -1,159 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; - -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import javax.imageio.ImageIO; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.ddf.EscherBSERecord; -import org.apache.poi.ddf.EscherContainerRecord; -import org.apache.poi.sl.usermodel.PictureData.PictureType; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -/** - * Test Picture shape. - */ -public final class TestPicture { - private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); - - @BeforeAll - public static void disableImageIOCache() { - ImageIO.setUseCache(false); - } - - /** - * Test that the reference count of a blip is incremented every time the picture is inserted. - * This is important when the same image appears multiple times in a slide show. - * - */ - @Test - void multiplePictures() throws IOException { - try (HSLFSlideShow ppt = new HSLFSlideShow()) { - HSLFSlide s = ppt.createSlide(); - HSLFSlide s2 = ppt.createSlide(); - HSLFSlide s3 = ppt.createSlide(); - - HSLFPictureData data = ppt.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG); - HSLFPictureShape pict = new HSLFPictureShape(data); - HSLFPictureShape pict2 = new HSLFPictureShape(data); - HSLFPictureShape pict3 = new HSLFPictureShape(data); - - pict.setAnchor(new Rectangle(10, 10, 100, 100)); - s.addShape(pict); - EscherBSERecord bse1 = pict.getEscherBSERecord(); - assertEquals(1, bse1.getRef()); - - pict2.setAnchor(new Rectangle(10, 10, 100, 100)); - s2.addShape(pict2); - EscherBSERecord bse2 = pict.getEscherBSERecord(); - assertSame(bse1, bse2); - assertEquals(2, bse1.getRef()); - - pict3.setAnchor(new Rectangle(10, 10, 100, 100)); - s3.addShape(pict3); - EscherBSERecord bse3 = pict.getEscherBSERecord(); - assertSame(bse2, bse3); - assertEquals(3, bse1.getRef()); - } - } - - /** - * {@link HSLFPictureShape#getEscherBSERecord()} threw {@link NullPointerException} if - * {@link EscherContainerRecord#BSTORE_CONTAINER} was not found. The correct behaviour is to return null. - */ - @Test - void bug46122() throws IOException { - HSLFPictureData detachedData; - try (HSLFSlideShow ppt = new HSLFSlideShow()) { - detachedData = ppt.addPicture(new byte[0], PictureType.PNG); - } - try (HSLFSlideShow ppt = new HSLFSlideShow()) { - HSLFSlide slide = ppt.createSlide(); - - HSLFPictureShape pict = new HSLFPictureShape(detachedData); //index to non-existing picture data - pict.setAnchor(new Rectangle2D.Double(50, 50, 100, 100)); - pict.setSheet(slide); - HSLFPictureData data = pict.getPictureData(); - assertNull(data); - - BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); - Graphics2D graphics = img.createGraphics(); - pict.draw(graphics, null); - } - } - - @Test - void macImages() throws IOException { - try (InputStream is = _slTests.openResourceAsStream("53446.ppt"); - HSLFSlideShowImpl hss = new HSLFSlideShowImpl(is)) { - - List<HSLFPictureData> pictures = hss.getPictureData(); - assertEquals(15, pictures.size()); - - int[][] expectedSizes = { - null, // WMF - {427, 428}, // PNG - {371, 370}, // PNG - {288, 183}, // PNG - {285, 97}, // PNG - {288, 168}, // PNG - null, // WMF - null, // WMF - {199, 259}, // PNG - {432, 244}, // PNG - {261, 258}, // PNG - null, // WMF - null, // WMF - null, // WMF - null // EMF - }; - - int i = 0; - for (HSLFPictureData pd : pictures) { - int[] dimensions = expectedSizes[i++]; - BufferedImage image = ImageIO.read(new ByteArrayInputStream(pd.getData())); - switch (pd.getType()) { - case WMF: - case EMF: - break; - default: - assertNotNull(image); - assertNotNull(dimensions); - assertEquals(dimensions[0], image.getWidth()); - assertEquals(dimensions[1], image.getHeight()); - break; - } - } - } - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java deleted file mode 100644 index a196ed685b..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java +++ /dev/null @@ -1,736 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.awt.Dimension; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Random; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.ddf.EscherBSERecord; -import org.apache.poi.ddf.EscherContainerRecord; -import org.apache.poi.ddf.EscherRecord; -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.apache.poi.hslf.blip.DIB; -import org.apache.poi.hslf.blip.EMF; -import org.apache.poi.hslf.blip.JPEG; -import org.apache.poi.hslf.blip.PICT; -import org.apache.poi.hslf.blip.PNG; -import org.apache.poi.hslf.blip.WMF; -import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; -import org.apache.poi.sl.image.ImageHeaderEMF; -import org.apache.poi.sl.image.ImageHeaderPICT; -import org.apache.poi.sl.image.ImageHeaderWMF; -import org.apache.poi.sl.usermodel.PictureData.PictureType; -import org.apache.poi.util.Units; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -/** - * Test adding/reading pictures - * - * @author Yegor Kozlov - */ -public final class TestPictures { - private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); - - /** - * Test read/write Macintosh PICT - */ - @Test - void testPICT() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - HSLFSlide slide = ppt.createSlide(); - byte[] src_bytes = slTests.readFile("cow.pict"); - HSLFPictureData data = ppt.addPicture(src_bytes, PictureType.PICT); - ImageHeaderPICT nHeader = new ImageHeaderPICT(src_bytes, 512); - final int expWidth = 197, expHeight = 137; - Dimension nDim = nHeader.getSize(); - assertEquals(expWidth, nDim.getWidth(), 0); - assertEquals(expHeight, nDim.getHeight(), 0); - - Dimension dim = data.getImageDimensionInPixels(); - assertEquals(Units.pointsToPixel(expWidth), dim.getWidth(), 0); - assertEquals(Units.pointsToPixel(expHeight), dim.getHeight(), 0); - - HSLFPictureShape pict = new HSLFPictureShape(data); - assertEquals(data.getIndex(), pict.getPictureIndex()); - slide.addShape(pict); - - //serialize and read again - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray()))); - - //make sure we can read this picture shape and it refers to the correct picture data - List<HSLFShape> sh = ppt.getSlides().get(0).getShapes(); - assertEquals(1, sh.size()); - pict = (HSLFPictureShape)sh.get(0); - assertEquals(data.getIndex(), pict.getPictureIndex()); - - //check picture data - List<HSLFPictureData> pictures = ppt.getPictureData(); - assertEquals(1, pictures.size()); - - HSLFPictureData pd = pictures.get(0); - dim = pd.getImageDimension(); - assertEquals(expWidth, dim.width); - assertEquals(expHeight, dim.height); - - //the Picture shape refers to the PictureData object in the Presentation - assertEquals(pict.getPictureData(), pd); - - assertEquals(1, pictures.size()); - assertEquals(PictureType.PICT, pd.getType()); - assertTrue(pd instanceof PICT); - //compare the content of the initial file with what is stored in the PictureData - byte[] ppt_bytes = pd.getData(); - assertEquals(src_bytes.length, ppt_bytes.length); - //in PICT the first 512 bytes are MAC specific and may not be preserved, ignore them - byte[] b1 = Arrays.copyOfRange(src_bytes, 512, src_bytes.length); - byte[] b2 = Arrays.copyOfRange(ppt_bytes, 512, ppt_bytes.length); - assertArrayEquals(b1, b2); - } - - /** - * Test read/write WMF - */ - @Test - void testWMF() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - HSLFSlide slide = ppt.createSlide(); - byte[] src_bytes = slTests.readFile("santa.wmf"); - HSLFPictureData data = ppt.addPicture(src_bytes, PictureType.WMF); - ImageHeaderWMF nHeader = new ImageHeaderWMF(src_bytes, 0); - final int expWidth = 136, expHeight = 146; - Dimension nDim = nHeader.getSize(); - assertEquals(expWidth, nDim.getWidth(), 0); - assertEquals(expHeight, nDim.getHeight(), 0); - - Dimension dim = data.getImageDimensionInPixels(); - assertEquals(Units.pointsToPixel(expWidth), dim.getWidth(), 0); - assertEquals(Units.pointsToPixel(expHeight), dim.getHeight(), 0); - - HSLFPictureShape pict = new HSLFPictureShape(data); - assertEquals(data.getIndex(), pict.getPictureIndex()); - slide.addShape(pict); - - //serialize and read again - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray()))); - - //make sure we can read this picture shape and it refers to the correct picture data - List<HSLFShape> sh = ppt.getSlides().get(0).getShapes(); - assertEquals(1, sh.size()); - pict = (HSLFPictureShape)sh.get(0); - assertEquals(data.getIndex(), pict.getPictureIndex()); - - //check picture data - List<HSLFPictureData> pictures = ppt.getPictureData(); - assertEquals(1, pictures.size()); - - HSLFPictureData pd = pictures.get(0); - dim = pd.getImageDimension(); - assertEquals(expWidth, dim.width); - assertEquals(expHeight, dim.height); - - //the Picture shape refers to the PictureData object in the Presentation - assertEquals(pict.getPictureData(), pd); - - assertEquals(PictureType.WMF, pd.getType()); - assertTrue(pd instanceof WMF); - //compare the content of the initial file with what is stored in the PictureData - byte[] ppt_bytes = pd.getData(); - assertEquals(src_bytes.length, ppt_bytes.length); - //in WMF the first 22 bytes - is a metafile header - byte[] b1 = Arrays.copyOfRange(src_bytes, 22, src_bytes.length); - byte[] b2 = Arrays.copyOfRange(ppt_bytes, 22, ppt_bytes.length); - assertArrayEquals(b1, b2); - } - - /** - * Test read/write EMF - */ - @Test - void testEMF() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - HSLFSlide slide = ppt.createSlide(); - byte[] src_bytes = slTests.readFile("wrench.emf"); - HSLFPictureData data = ppt.addPicture(src_bytes, PictureType.EMF); - ImageHeaderEMF nHeader = new ImageHeaderEMF(src_bytes, 0); - final int expWidth = 190, expHeight = 115; - Dimension nDim = nHeader.getSize(); - assertEquals(expWidth, nDim.getWidth(), 0); - assertEquals(expHeight, nDim.getHeight(), 0); - - Dimension dim = data.getImageDimensionInPixels(); - assertEquals(Units.pointsToPixel(expWidth), dim.getWidth(), 0); - assertEquals(Units.pointsToPixel(expHeight), dim.getHeight(), 0); - - HSLFPictureShape pict = new HSLFPictureShape(data); - assertEquals(data.getIndex(), pict.getPictureIndex()); - slide.addShape(pict); - - //serialize and read again - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray()))); - - //make sure we can get this picture shape and it refers to the correct picture data - List<HSLFShape> sh = ppt.getSlides().get(0).getShapes(); - assertEquals(1, sh.size()); - pict = (HSLFPictureShape)sh.get(0); - assertEquals(data.getIndex(), pict.getPictureIndex()); - - //check picture data - List<HSLFPictureData> pictures = ppt.getPictureData(); - assertEquals(1, pictures.size()); - - HSLFPictureData pd = pictures.get(0); - dim = pd.getImageDimension(); - assertEquals(expWidth, dim.width); - assertEquals(expHeight, dim.height); - - //the Picture shape refers to the PictureData object in the Presentation - assertEquals(pict.getPictureData(), pd); - - assertEquals(1, pictures.size()); - assertEquals(PictureType.EMF, pd.getType()); - assertTrue(pd instanceof EMF); - //compare the content of the initial file with what is stored in the PictureData - byte[] ppt_bytes = pd.getData(); - assertArrayEquals(src_bytes, ppt_bytes); - } - - /** - * Test read/write PNG - */ - @Test - void testPNG() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - HSLFSlide slide = ppt.createSlide(); - byte[] src_bytes = slTests.readFile("tomcat.png"); - HSLFPictureData data = ppt.addPicture(src_bytes, PictureType.PNG); - HSLFPictureShape pict = new HSLFPictureShape(data); - assertEquals(data.getIndex(), pict.getPictureIndex()); - slide.addShape(pict); - - //serialize and read again - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray()))); - - //make sure we can read this picture shape and it refers to the correct picture data - List<HSLFShape> sh = ppt.getSlides().get(0).getShapes(); - assertEquals(1, sh.size()); - pict = (HSLFPictureShape)sh.get(0); - assertEquals(data.getIndex(), pict.getPictureIndex()); - - //check picture data - List<HSLFPictureData> pictures = ppt.getPictureData(); - //the Picture shape refers to the PictureData object in the Presentation - assertEquals(pict.getPictureData(), pictures.get(0)); - - assertEquals(1, pictures.size()); - assertEquals(PictureType.PNG, pictures.get(0).getType()); - assertTrue(pictures.get(0) instanceof PNG); - //compare the content of the initial file with what is stored in the PictureData - byte[] ppt_bytes = pictures.get(0).getData(); - assertArrayEquals(src_bytes, ppt_bytes); - } - - /** - * Test read/write JPEG - */ - @Test - void testJPEG() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - HSLFSlide slide = ppt.createSlide(); - byte[] src_bytes = slTests.readFile("clock.jpg"); - HSLFPictureData data = ppt.addPicture(src_bytes, PictureType.JPEG); - - HSLFPictureShape pict = new HSLFPictureShape(data); - assertEquals(data.getIndex(), pict.getPictureIndex()); - slide.addShape(pict); - - //serialize and read again - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray()))); - - //make sure we can read this picture shape and it refers to the correct picture data - List<HSLFShape> sh = ppt.getSlides().get(0).getShapes(); - assertEquals(1, sh.size()); - pict = (HSLFPictureShape)sh.get(0); - assertEquals(data.getIndex(), pict.getPictureIndex()); - - //check picture data - List<HSLFPictureData> pictures = ppt.getPictureData(); - //the Picture shape refers to the PictureData object in the Presentation - assertEquals(pict.getPictureData(), pictures.get(0)); - - assertEquals(1, pictures.size()); - assertEquals(PictureType.JPEG, pictures.get(0).getType()); - assertTrue(pictures.get(0) instanceof JPEG); - //compare the content of the initial file with what is stored in the PictureData - byte[] ppt_bytes = pictures.get(0).getData(); - assertArrayEquals(src_bytes, ppt_bytes); - } - - /** - * Test read/write DIB - */ - @Test - void testDIB() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - HSLFSlide slide = ppt.createSlide(); - byte[] src_bytes = slTests.readFile("clock.dib"); - HSLFPictureData data = ppt.addPicture(src_bytes, PictureType.DIB); - HSLFPictureShape pict = new HSLFPictureShape(data); - assertEquals(data.getIndex(), pict.getPictureIndex()); - slide.addShape(pict); - - //serialize and read again - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray()))); - - //make sure we can read this picture shape and it refers to the correct picture data - List<HSLFShape> sh = ppt.getSlides().get(0).getShapes(); - assertEquals(1, sh.size()); - pict = (HSLFPictureShape)sh.get(0); - assertEquals(data.getIndex(), pict.getPictureIndex()); - - //check picture data - List<HSLFPictureData> pictures = ppt.getPictureData(); - //the Picture shape refers to the PictureData object in the Presentation - assertEquals(pict.getPictureData(), pictures.get(0)); - - assertEquals(1, pictures.size()); - assertEquals(PictureType.DIB, pictures.get(0).getType()); - assertTrue(pictures.get(0) instanceof DIB); - //compare the content of the initial file with what is stored in the PictureData - byte[] ppt_bytes = pictures.get(0).getData(); - assertArrayEquals(src_bytes, ppt_bytes); - } - - /** - * Read pictures in different formats from a reference slide show - */ - @Test - void testReadPictures() throws IOException { - - byte[] src_bytes, ppt_bytes, b1, b2; - HSLFPictureShape pict; - HSLFPictureData pdata; - - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("pictures.ppt"); - List<HSLFSlide> slides = ppt.getSlides(); - List<HSLFPictureData> pictures = ppt.getPictureData(); - assertEquals(5, pictures.size()); - - pict = (HSLFPictureShape)slides.get(0).getShapes().get(0); //the first slide contains JPEG - pdata = pict.getPictureData(); - assertTrue(pdata instanceof JPEG); - assertEquals(PictureType.JPEG, pdata.getType()); - src_bytes = pdata.getData(); - ppt_bytes = slTests.readFile("clock.jpg"); - assertArrayEquals(src_bytes, ppt_bytes); - - pict = (HSLFPictureShape)slides.get(1).getShapes().get(0); //the second slide contains PNG - pdata = pict.getPictureData(); - assertTrue(pdata instanceof PNG); - assertEquals(PictureType.PNG, pdata.getType()); - src_bytes = pdata.getData(); - ppt_bytes = slTests.readFile("tomcat.png"); - assertArrayEquals(src_bytes, ppt_bytes); - - pict = (HSLFPictureShape)slides.get(2).getShapes().get(0); //the third slide contains WMF - pdata = pict.getPictureData(); - assertTrue(pdata instanceof WMF); - assertEquals(PictureType.WMF, pdata.getType()); - src_bytes = pdata.getData(); - ppt_bytes = slTests.readFile("santa.wmf"); - assertEquals(src_bytes.length, ppt_bytes.length); - //ignore the first 22 bytes - it is a WMF metafile header - b1 = Arrays.copyOfRange(src_bytes, 22, src_bytes.length); - b2 = Arrays.copyOfRange(ppt_bytes, 22, ppt_bytes.length); - assertArrayEquals(b1, b2); - - pict = (HSLFPictureShape)slides.get(3).getShapes().get(0); //the forth slide contains PICT - pdata = pict.getPictureData(); - assertTrue(pdata instanceof PICT); - assertEquals(PictureType.PICT, pdata.getType()); - src_bytes = pdata.getData(); - ppt_bytes = slTests.readFile("cow.pict"); - assertEquals(src_bytes.length, ppt_bytes.length); - //ignore the first 512 bytes - it is a MAC specific crap - b1 = Arrays.copyOfRange(src_bytes, 512, src_bytes.length); - b2 = Arrays.copyOfRange(ppt_bytes, 512, ppt_bytes.length); - assertArrayEquals(b1, b2); - - pict = (HSLFPictureShape)slides.get(4).getShapes().get(0); //the fifth slide contains EMF - pdata = pict.getPictureData(); - assertTrue(pdata instanceof EMF); - assertEquals(PictureType.EMF, pdata.getType()); - src_bytes = pdata.getData(); - ppt_bytes = slTests.readFile("wrench.emf"); - assertArrayEquals(src_bytes, ppt_bytes); - - ppt.close(); - } - - /** - * Test that on a party corrupt powerpoint document, which has - * crazy pictures of type 0, we do our best. - */ - @Test - void testZeroPictureType() throws IOException { - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("PictureTypeZero.ppt")); - - // Should still have 2 real pictures - assertEquals(2, hslf.getPictureData().size()); - // Both are real pictures, both WMF - assertEquals(PictureType.WMF, hslf.getPictureData().get(0).getType()); - assertEquals(PictureType.WMF, hslf.getPictureData().get(1).getType()); - - // Now test what happens when we use the SlideShow interface - HSLFSlideShow ppt = new HSLFSlideShow(hslf); - List<HSLFSlide> slides = ppt.getSlides(); - List<HSLFPictureData> pictures = ppt.getPictureData(); - assertEquals(12, slides.size()); - assertEquals(2, pictures.size()); - - HSLFPictureShape pict; - HSLFPictureData pdata; - - pict = (HSLFPictureShape)slides.get(0).getShapes().get(1); // 2nd object on 1st slide - pdata = pict.getPictureData(); - assertTrue(pdata instanceof WMF); - assertEquals(PictureType.WMF, pdata.getType()); - - pict = (HSLFPictureShape)slides.get(0).getShapes().get(2); // 3rd object on 1st slide - pdata = pict.getPictureData(); - assertTrue(pdata instanceof WMF); - assertEquals(PictureType.WMF, pdata.getType()); - - ppt.close(); - } - - /** - * YK: The test is disabled because the owner asked to delete the test file from POI svn. - * See "Please remove my file from your svn" on @poi-dev from Dec 12, 2013 - */ - @Test - @Disabled("requires an internet connection to a 3rd party site") - // As of 2017-06-20, the file still exists at the specified URL and the test passes. - void testZeroPictureLength() throws IOException { - // take the data from www instead of test directory - URL url = new URL("http://www.cs.sfu.ca/~anoop/courses/CMPT-882-Fall-2002/chris.ppt"); - HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(url.openStream()); - /* Assume that the file could retrieved... - InputStream is; - HSLFSlideShowImpl hslf; - try { - is = url.openStream(); - hslf = new HSLFSlideShowImpl(is); - is.close(); - } catch (final IOException e) { - Assume.assumeTrue(e.getMessage(), false); - throw e; - } - */ - - // Should still have 2 real pictures - assertEquals(2, hslf.getPictureData().size()); - // Both are real pictures, both WMF - assertEquals(PictureType.WMF, hslf.getPictureData().get(0).getType()); - assertEquals(PictureType.WMF, hslf.getPictureData().get(1).getType()); - - // Now test what happens when we use the SlideShow interface - HSLFSlideShow ppt = new HSLFSlideShow(hslf); - List<HSLFSlide> slides = ppt.getSlides(); - List<HSLFPictureData> pictures = ppt.getPictureData(); - assertEquals(27, slides.size()); - assertEquals(2, pictures.size()); - - HSLFPictureShape pict; - HSLFPictureData pdata; - - pict = (HSLFPictureShape)slides.get(6).getShapes().get(13); - pdata = pict.getPictureData(); - assertTrue(pdata instanceof WMF); - assertEquals(PictureType.WMF, pdata.getType()); - - pict = (HSLFPictureShape)slides.get(7).getShapes().get(13); - pdata = pict.getPictureData(); - assertTrue(pdata instanceof WMF); - assertEquals(PictureType.WMF, pdata.getType()); - - //add a new picture, it should be correctly appended to the Pictures stream - ByteArrayOutputStream out = new ByteArrayOutputStream(); - for(HSLFPictureData p : pictures) p.write(out); - out.close(); - - int streamSize = out.size(); - - HSLFPictureData data = ppt.addPicture(new byte[100], PictureType.JPEG); - int offset = data.getOffset(); - assertEquals(streamSize, offset); - assertEquals(3, ppt.getPictureData().size()); - - ppt.close(); - } - - @Test - void testGetPictureName() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("ppt_with_png.ppt"); - HSLFSlide slide = ppt.getSlides().get(0); - - HSLFPictureShape p = (HSLFPictureShape)slide.getShapes().get(0); //the first slide contains JPEG - assertEquals("test", p.getPictureName()); - ppt.close(); - } - - @Test - void testSetPictureName() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - - HSLFSlide slide = ppt.createSlide(); - byte[] img = slTests.readFile("tomcat.png"); - HSLFPictureData data = ppt.addPicture(img, PictureType.PNG); - HSLFPictureShape pict = new HSLFPictureShape(data); - pict.setPictureName("tomcat.png"); - slide.addShape(pict); - - //serialize and read again - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())); - - HSLFPictureShape p = (HSLFPictureShape)ppt.getSlides().get(0).getShapes().get(0); - assertEquals("tomcat.png", p.getPictureName()); - } - - @Test - void testPictureIndexIsOneBased() throws IOException { - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("ppt_with_png.ppt")) { - HSLFPictureData picture = ppt.getPictureData().get(0); - assertEquals(1, picture.getIndex()); - } - } - - /** - * Verify that it is possible for a user to change the contents of a {@link HSLFPictureData} using - * {@link HSLFPictureData#setData(byte[])}, and that the changes are saved to the slideshow. - */ - @Test - void testEditPictureData() throws IOException { - byte[] newImage = slTests.readFile("tomcat.png"); - ByteArrayOutputStream modifiedSlideShow = new ByteArrayOutputStream(); - - // Load an existing slideshow and modify the image - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("ppt_with_png.ppt")) { - HSLFPictureData picture = ppt.getPictureData().get(0); - picture.setData(newImage); - ppt.write(modifiedSlideShow); - } - - // Load the modified slideshow and verify the image content - try (HSLFSlideShow ppt = new HSLFSlideShow(new ByteArrayInputStream(modifiedSlideShow.toByteArray()))) { - HSLFPictureData picture = ppt.getPictureData().get(0); - byte[] modifiedImageData = picture.getData(); - assertArrayEquals(newImage, modifiedImageData); - } - } - - /** - * Verify that it is possible for a user to change the contents of an encrypted {@link HSLFPictureData} using - * {@link HSLFPictureData#setData(byte[])}, and that the changes are saved to the slideshow. - */ - @Test - void testEditPictureDataEncrypted() throws IOException { - byte[] newImage = slTests.readFile("tomcat.png"); - ByteArrayOutputStream modifiedSlideShow = new ByteArrayOutputStream(); - - Biff8EncryptionKey.setCurrentUserPassword("password"); - try { - // Load an existing slideshow and modify the image - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("ppt_with_png_encrypted.ppt")) { - HSLFPictureData picture = ppt.getPictureData().get(0); - picture.setData(newImage); - ppt.write(modifiedSlideShow); - } - - // Load the modified slideshow and verify the image content - try (HSLFSlideShow ppt = new HSLFSlideShow(new ByteArrayInputStream(modifiedSlideShow.toByteArray()))) { - HSLFPictureData picture = ppt.getPictureData().get(0); - byte[] modifiedImageData = picture.getData(); - assertArrayEquals(newImage, modifiedImageData); - } - } finally { - Biff8EncryptionKey.setCurrentUserPassword(null); - } - } - - /** - * Verify that the {@link EscherBSERecord#getOffset()} values are modified for all images after the image being - * changed. - */ - @Test - void testEditPictureDataRecordOffsetsAreShifted() throws IOException { - int[] originalOffsets = {0, 12013, 15081, 34162, 59563}; - int[] modifiedOffsets = {0, 35, 3103, 22184, 47585}; - - ByteArrayOutputStream inMemory = new ByteArrayOutputStream(); - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("pictures.ppt")) { - int[] offsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - assertArrayEquals(originalOffsets, offsets); - - HSLFPictureData imageBeingChanged = ppt.getPictureData().get(0); - // It doesn't matter that this isn't a valid image. We are just testing offsets here. - imageBeingChanged.setData(new byte[10]); - - // Verify that the in-memory representations have all been updated - offsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - assertArrayEquals(modifiedOffsets, offsets); - - ppt.write(inMemory); - } - - try (HSLFSlideShow ppt = new HSLFSlideShow(new ByteArrayInputStream(inMemory.toByteArray()))) { - - // Verify that the persisted representations have all been updated - int[] offsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - assertArrayEquals(modifiedOffsets, offsets); - } - } - - /** - * Verify that the {@link EscherBSERecord#getOffset()} values are modified for all images after the image being - * changed, but assuming that the records are not stored in a sorted-by-offset fashion. - * - * We have not encountered a file that has meaningful data that is not sorted. However, we have encountered files - * that have records with an offset of 0 interspersed between meaningful records. See {@code 53446.ppt} and - * {@code alterman_security.ppt} for examples. - */ - @Test - void testEditPictureDataOutOfOrderRecords() throws IOException { - int[] modifiedOffsets = {0, 35, 3103, 22184, 47585}; - - ByteArrayOutputStream inMemory = new ByteArrayOutputStream(); - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("pictures.ppt")) { - - // For this test we're going to intentionally manipulate the records into a shuffled order. - EscherContainerRecord container = ppt.getPictureData().get(0).bStore; - List<EscherRecord> children = container.getChildRecords(); - for (EscherRecord child : children) { - container.removeChildRecord(child); - } - Collections.shuffle(children); - for (EscherRecord child : children) { - container.addChildRecord(child); - } - - HSLFPictureData imageBeingChanged = ppt.getPictureData().get(0); - // It doesn't matter that this isn't a valid image. We are just testing offsets here. - imageBeingChanged.setData(new byte[10]); - - // Verify that the in-memory representations have all been updated - int[] offsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - Arrays.sort(offsets); - assertArrayEquals(modifiedOffsets, offsets); - - ppt.write(inMemory); - } - - try (HSLFSlideShow ppt = new HSLFSlideShow(new ByteArrayInputStream(inMemory.toByteArray()))) { - - // Verify that the persisted representations have all been updated - int[] offsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - Arrays.sort(offsets); - assertArrayEquals(modifiedOffsets, offsets); - } - } - - /** - * Verify that a slideshow with records that have offsets not matching those of the pictures in the stream still - * correctly pairs the records and pictures. - */ - @Test - void testSlideshowWithIncorrectOffsets() throws IOException { - int[] originalOffsets; - int originalNumberOfRecords; - - // Create a presentation that has records with unmatched offsets, but with matched UIDs. - ByteArrayOutputStream inMemory = new ByteArrayOutputStream(); - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("pictures.ppt")) { - originalOffsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - originalNumberOfRecords = ppt.getPictureData().get(0).bStore.getChildCount(); - - Random random = new Random(); - for (HSLFPictureData picture : ppt.getPictureData()) { - // Bound is arbitrary and irrelevant to the test. - picture.bse.setOffset(random.nextInt(500_000)); - } - ppt.write(inMemory); - } - - try (HSLFSlideShow ppt = new HSLFSlideShow(new ByteArrayInputStream(inMemory.toByteArray()))) { - - // Verify that the offsets all got fixed. - int[] offsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - assertArrayEquals(originalOffsets, offsets); - - // Verify that there are the same number of records as in the original slideshow. - int numberOfRecords = ppt.getPictureData().get(0).bStore.getChildCount(); - assertEquals(originalNumberOfRecords, numberOfRecords); - } - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java deleted file mode 100644 index 0b9255050b..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java +++ /dev/null @@ -1,298 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests that SlideShow can re-order slides properly - */ -public final class TestReOrderingSlides { - // 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; - - // A SlideShow with three slides - private HSLFSlideShowImpl hss_three; - private HSLFSlideShow ss_three; - - /** - * Create/open the slideshows - */ - @BeforeEach - void setUp() throws Exception { - 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); - - hss_three = new HSLFSlideShowImpl(slTests.openResourceAsStream("incorrect_slide_order.ppt")); - ss_three = new HSLFSlideShow(hss_three); - } - - /** - * Test that we can "re-order" a slideshow with only 1 slide on it - */ - @Test - void testReOrder1() throws IOException { - // Has one slide - assertEquals(1, ss_one.getSlides().size()); - HSLFSlide s1 = ss_one.getSlides().get(0); - - // Check slide 1 is as expected - assertEquals(256, s1._getSheetNumber()); - assertEquals(3, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - - // Now move it to one - ss_one.reorderSlide(1, 1); - - // Write out, and read back in - HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_one); - - // Check it still has 1 slide - assertEquals(1, ss_read.getSlides().size()); - - // And check it's as expected - s1 = ss_read.getSlides().get(0); - assertEquals(256, s1._getSheetNumber()); - assertEquals(3, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - - ss_read.close(); - } - - /** - * Test doing a dummy re-order on a slideshow with - * two slides in it - */ - @Test - void testReOrder2() throws IOException { - // Has two slides - assertEquals(2, ss_two.getSlides().size()); - HSLFSlide s1 = ss_two.getSlides().get(0); - HSLFSlide s2 = ss_two.getSlides().get(1); - - // Check slide 1 is as expected - assertEquals(256, s1._getSheetNumber()); - assertEquals(4, s1._getSheetRefId()); // master has notes - assertEquals(1, s1.getSlideNumber()); - // Check slide 2 is as expected - assertEquals(257, s2._getSheetNumber()); - assertEquals(6, s2._getSheetRefId()); // master and 1 have notes - assertEquals(2, s2.getSlideNumber()); - - // Don't swap them around - ss_two.reorderSlide(2, 2); - - // Write out, and read back in - HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two); - - // Check it still has 2 slides - assertEquals(2, ss_read.getSlides().size()); - - // And check it's as expected - s1 = ss_read.getSlides().get(0); - s2 = ss_read.getSlides().get(1); - assertEquals(256, s1._getSheetNumber()); - assertEquals(4, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - assertEquals(257, s2._getSheetNumber()); - assertEquals(6, s2._getSheetRefId()); - assertEquals(2, s2.getSlideNumber()); - - ss_read.close(); - } - - /** - * Test re-ordering slides in a slideshow with 2 slides on it - */ - @Test - void testReOrder2swap() throws IOException { - // Has two slides - assertEquals(2, ss_two.getSlides().size()); - HSLFSlide s1 = ss_two.getSlides().get(0); - HSLFSlide s2 = ss_two.getSlides().get(1); - - // Check slide 1 is as expected - assertEquals(256, s1._getSheetNumber()); - assertEquals(4, s1._getSheetRefId()); // master has notes - assertEquals(1, s1.getSlideNumber()); - // Check slide 2 is as expected - assertEquals(257, s2._getSheetNumber()); - assertEquals(6, s2._getSheetRefId()); // master and 1 have notes - assertEquals(2, s2.getSlideNumber()); - - // Swap them around - ss_two.reorderSlide(2, 1); - - // Write out, and read back in - HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two); - - // Check it still has 2 slides - assertEquals(2, ss_read.getSlides().size()); - - // And check it's as expected - s1 = ss_read.getSlides().get(0); - s2 = ss_read.getSlides().get(1); - assertEquals(257, s1._getSheetNumber()); - assertEquals(6, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - assertEquals(256, s2._getSheetNumber()); - assertEquals(4, s2._getSheetRefId()); - assertEquals(2, s2.getSlideNumber()); - - ss_read.close(); - } - - /** - * Test doing a dummy re-order on a slideshow with - * three slides in it - */ - @Test - void testReOrder3() throws IOException { - // Has three slides - assertEquals(3, ss_three.getSlides().size()); - HSLFSlide s1 = ss_three.getSlides().get(0); - HSLFSlide s2 = ss_three.getSlides().get(1); - HSLFSlide s3 = ss_three.getSlides().get(2); - - // Check slide 1 is as expected - assertEquals(256, s1._getSheetNumber()); - assertEquals(3, s1._getSheetRefId()); // no notes on master - assertEquals(1, s1.getSlideNumber()); - // Check slide 2 is as expected (was re-ordered from 3) - assertEquals(258, s2._getSheetNumber()); - assertEquals(5, s2._getSheetRefId()); // no notes on slide - assertEquals(2, s2.getSlideNumber()); - // Check slide 3 is as expected (was re-ordered from 2) - assertEquals(257, s3._getSheetNumber()); - assertEquals(4, s3._getSheetRefId()); // no notes on slide - assertEquals(3, s3.getSlideNumber()); - - // Don't swap them around - ss_three.reorderSlide(2, 2); - - // Write out, and read back in - HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_three); - - // Check it still has 3 slides - assertEquals(3, ss_read.getSlides().size()); - - // And check it's as expected - s1 = ss_read.getSlides().get(0); - s2 = ss_read.getSlides().get(1); - s3 = ss_read.getSlides().get(2); - - assertEquals(256, s1._getSheetNumber()); - assertEquals(3, s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - assertEquals(258, s2._getSheetNumber()); - assertEquals(5, s2._getSheetRefId()); - assertEquals(2, s2.getSlideNumber()); - assertEquals(257, s3._getSheetNumber()); - assertEquals(4, s3._getSheetRefId()); - assertEquals(3, s3.getSlideNumber()); - - ss_read.close(); - } - - /** - * Test re-ordering slides in a slideshow with 3 slides on it - */ - @Test - void testReOrder3swap() throws IOException { - // Has three slides - assertEquals(3, ss_three.getSlides().size()); - HSLFSlide s1 = ss_three.getSlides().get(0); - HSLFSlide s2 = ss_three.getSlides().get(1); - HSLFSlide s3 = ss_three.getSlides().get(2); - - // Check slide 1 is as expected - assertEquals(256, s1._getSheetNumber()); - assertEquals(3, s1._getSheetRefId()); // no notes on master - assertEquals(1, s1.getSlideNumber()); - // Check slide 2 is as expected (was re-ordered from 3) - assertEquals(258, s2._getSheetNumber()); - assertEquals(5, s2._getSheetRefId()); // no notes on slide - assertEquals(2, s2.getSlideNumber()); - // Check slide 3 is as expected (was re-ordered from 2) - assertEquals(257, s3._getSheetNumber()); - assertEquals(4, s3._getSheetRefId()); // no notes on slide - assertEquals(3, s3.getSlideNumber()); - - // Put 3 in place of 1 - // (1 -> 2, 2 -> 3) - ss_three.reorderSlide(3, 1); - - // refresh the slides - s1 = ss_three.getSlides().get(0); - s2 = ss_three.getSlides().get(1); - s3 = ss_three.getSlides().get(2); - - assertEquals(1, s1.getSlideNumber()); - assertEquals(2, s2.getSlideNumber()); - assertEquals(3, s3.getSlideNumber()); - - assertEquals("Slide 3", ((HSLFTextShape)s1.getShapes().get(0)).getText()); - assertEquals("Slide 1", ((HSLFTextShape)s3.getShapes().get(0)).getText()); - - // Write out, and read back in - HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_three); - - // Check it still has 3 slides - assertEquals(3, ss_read.getSlides().size()); - - // And check it's as expected - HSLFSlide _s1 = ss_read.getSlides().get(0); - HSLFSlide _s2 = ss_read.getSlides().get(1); - HSLFSlide _s3 = ss_read.getSlides().get(2); - - // 1 --> 3 - assertEquals(s1._getSheetNumber(), _s1._getSheetNumber()); - assertEquals(s1._getSheetRefId(), _s1._getSheetRefId()); - assertEquals(1, s1.getSlideNumber()); - - // 2nd slide is not updated - assertEquals(s2._getSheetNumber(), _s2._getSheetNumber()); - assertEquals(s2._getSheetRefId(), _s2._getSheetRefId()); - assertEquals(2, s2.getSlideNumber()); - - // 3 --> 1 - assertEquals(s3._getSheetNumber(), _s3._getSheetNumber()); - assertEquals(s3._getSheetRefId(), _s3._getSheetRefId()); - assertEquals(3, s3.getSlideNumber()); - - ss_read.close(); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java deleted file mode 100644 index 0eba4ae56e..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java +++ /dev/null @@ -1,67 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.apache.poi.POIDataSamples; -import org.apache.poi.hslf.record.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests that the record setup done by SlideShow - * has worked correctly - * Note: most recent record stuff has its own test - * - * @author Nick Burch (nick at torchbox dot com) - */ -public final class TestRecordSetup { - // SlideShow primed on the test data - @SuppressWarnings("unused") - private HSLFSlideShow ss; - private HSLFSlideShowImpl hss; - - @BeforeEach - void init() throws Exception { - POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); - hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); - ss = new HSLFSlideShow(hss); - } - - @Test - void testHandleParentAwareRecords() { - org.apache.poi.hslf.record.Record[] records = hss.getRecords(); - for ( org.apache.poi.hslf.record.Record record : records) { - ensureParentAware(record,null); - } - } - private void ensureParentAware( org.apache.poi.hslf.record.Record r,RecordContainer parent) { - if(r instanceof ParentAwareRecord) { - ParentAwareRecord pr = (ParentAwareRecord)r; - assertEquals(parent, pr.getParentRecord()); - } - if(r instanceof RecordContainer) { - RecordContainer rc = (RecordContainer)r; - org.apache.poi.hslf.record.Record[] children = rc.getChildRecords(); - for ( org.apache.poi.hslf.record.Record rec : children) { - ensureParentAware(rec, rc); - } - } - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java deleted file mode 100644 index 8081528a9f..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java +++ /dev/null @@ -1,663 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.apache.poi.POITestCase.assertContains; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -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.POIFSFileSystem; -import org.apache.poi.util.IOUtils; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Test that the friendly getters and setters on RichTextRun - * behave as expected. - * (model.TestTextRun tests the other functionality) - */ -public final class TestRichTextRun { - // SlideShow primed on the test data - private HSLFSlideShow ss; - private HSLFSlideShow ssRichA; - private HSLFSlideShow ssRichB; - private HSLFSlideShow ssRichC; - private HSLFSlideShow ssChinese; - private static String filenameC; - - @BeforeEach - void setUp() throws IOException { - // Basic (non rich) test file - ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); - - // Rich test file A - ssRichA = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt"); - - // Rich test file B - 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"; - ssRichC = HSLFTestDataSamples.getSlideShow(filenameC); - - // Rich test file with Chinese + English text in it - ssChinese = HSLFTestDataSamples.getSlideShow("54880_chinese.ppt"); - } - - @AfterEach - void tearDown() throws IOException { - ss.close(); - ssRichA.close(); - ssRichB.close(); - ssRichC.close(); - ssChinese.close(); - } - - /** - * Test the stuff about getting/setting bold - * on a non rich text run - */ - @Test - void testBoldNonRich() { - HSLFSlide slideOne = ss.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - List<HSLFTextParagraph> textParas = textParass.get(0); - HSLFTextRun rtr = textParas.get(0).getTextRuns().get(0); - - assertNotNull(rtr.getCharacterStyle()); - assertNotNull(textParas.get(0).getParagraphStyle()); - assertFalse(rtr.isBold()); - - // Now set it to not bold - rtr.setBold(false); - // in Pre 3.12: setting bold=false doesn't change the internal state - // now: also allow explicitly disable styles and there aren't any non rich text runs anymore - assertNotNull(rtr.getCharacterStyle()); - assertNotNull(textParas.get(0).getParagraphStyle()); - - assertFalse(rtr.isBold()); - - // And now make it bold - rtr.setBold(true); - assertNotNull(rtr.getCharacterStyle()); - assertNotNull(textParas.get(0).getParagraphStyle()); - assertTrue(rtr.isBold()); - } - - /** - * Test the stuff about getting/setting bold - * on a rich text run - */ - @Test - void testBoldRich() { - HSLFSlide slideOneR = ssRichA.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOneR.getTextParagraphs(); - List<HSLFTextParagraph> textParas = textParass.get(1); - assertEquals(3, textParas.size()); - - assertTrue(textParas.get(0).getTextRuns().get(0).isBold()); - assertFalse(textParas.get(1).getTextRuns().get(0).isBold()); - assertFalse(textParas.get(2).getTextRuns().get(0).isBold()); - - textParas.get(0).getTextRuns().get(0).setBold(true); - textParas.get(1).getTextRuns().get(0).setBold(true); - - assertTrue(textParas.get(0).getTextRuns().get(0).isBold()); - assertTrue(textParas.get(1).getTextRuns().get(0).isBold()); - - textParas.get(0).getTextRuns().get(0).setBold(false); - textParas.get(1).getTextRuns().get(0).setBold(false); - - assertFalse(textParas.get(0).getTextRuns().get(0).isBold()); - assertFalse(textParas.get(1).getTextRuns().get(0).isBold()); - } - - /** - * Tests getting and setting the font size on rich and non - * rich text runs - */ - @Test - void testFontSize() { - - HSLFSlide slideOne = ss.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - HSLFTextRun rtr = textParass.get(0).get(0).getTextRuns().get(0); - - HSLFSlide slideOneR = ssRichB.getSlides().get(0); - List<List<HSLFTextParagraph>> textParassR = slideOneR.getTextParagraphs(); - HSLFTextRun rtrRa = textParassR.get(0).get(0).getTextRuns().get(0); - HSLFTextRun rtrRb = textParassR.get(1).get(0).getTextRuns().get(0); - HSLFTextRun rtrRc = textParassR.get(1).get(3).getTextRuns().get(0); - - String defaultFont = "Arial"; - - // Start off with rich one - // First run has defaults - assertNotNull(rtrRa.getFontSize()); - assertEquals(44, rtrRa.getFontSize(), 0); - assertEquals(defaultFont, rtrRa.getFontFamily()); - - // Second is size 20, default font - assertNotNull(rtrRb.getFontSize()); - assertEquals(20, rtrRb.getFontSize(), 0); - assertEquals(defaultFont, rtrRb.getFontFamily()); - // Third is size 24, alt font - assertNotNull(rtrRc.getFontSize()); - assertEquals(24, rtrRc.getFontSize(), 0); - assertEquals("Times New Roman", rtrRc.getFontFamily()); - - // Change 2nd to different size and font - assertEquals(2, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR - rtrRb.setFontSize(18d); - rtrRb.setFontFamily("Courier"); - assertEquals(3, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR + Courier - assertEquals(18, rtrRb.getFontSize(), 0); - assertEquals("Courier", rtrRb.getFontFamily()); - - - // Now do non rich one - assertNotNull(rtr.getFontSize()); - assertEquals(44, rtr.getFontSize(), 0); - assertEquals(defaultFont, rtr.getFontFamily()); - assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default - assertNotNull(rtr.getCharacterStyle()); - assertNotNull(rtr.getTextParagraph().getParagraphStyle()); - - // Change Font size - rtr.setFontSize(99d); - assertEquals(99, rtr.getFontSize(), 0); - assertEquals(defaultFont, rtr.getFontFamily()); - assertNotNull(rtr.getCharacterStyle()); - assertNotNull(rtr.getTextParagraph().getParagraphStyle()); - assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default - - // Change Font size and name - rtr.setFontSize(25d); - rtr.setFontFamily("Times New Roman"); - assertEquals(25, rtr.getFontSize(), 0); - assertEquals("Times New Roman", rtr.getFontFamily()); - assertNotNull(rtr.getCharacterStyle()); - assertNotNull(rtr.getTextParagraph().getParagraphStyle()); - assertEquals(2, ss.getFontCollection().getChildRecords().length); - } - - @Test - void testChangeWriteRead() throws IOException { - for(HSLFSlideShow h : new HSLFSlideShow[] { ss, ssRichA, ssRichB }) { - // Change - HSLFSlide slideOne = h.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - HSLFTextRun rtr = textParass.get(0).get(0).getTextRuns().get(0); - - rtr.setBold(true); - rtr.setFontSize(18d); - rtr.setFontFamily("Courier"); - HSLFTextParagraph.storeText(textParass.get(0)); - - // Check it took those - assertTrue(rtr.isBold()); - assertNotNull(rtr.getFontSize()); - assertEquals(18., rtr.getFontSize(), 0); - assertEquals("Courier", rtr.getFontFamily()); - - // Write out and back in - HSLFSlideShow readS = HSLFTestDataSamples.writeOutAndReadBack(h); - - // Tweak existing one again, to ensure really worked - rtr.setBold(false); - rtr.setFontSize(17d); - rtr.setFontFamily("CourierZZ"); - - // Check it took those changes - assertFalse(rtr.isBold()); - assertEquals(17., rtr.getFontSize(), 0); - assertEquals("CourierZZ", rtr.getFontFamily()); - - - // Now, look at the one we changed, wrote out, and read back in - // Ensure it does contain our original modifications - HSLFSlide slideOneRR = readS.getSlides().get(0); - List<List<HSLFTextParagraph>> textParassRR = slideOneRR.getTextParagraphs(); - HSLFTextRun rtrRRa = textParassRR.get(0).get(0).getTextRuns().get(0); - - assertTrue(rtrRRa.isBold()); - assertNotNull(rtrRRa.getFontSize()); - assertEquals(18., rtrRRa.getFontSize(), 0); - assertEquals("Courier", rtrRRa.getFontFamily()); - readS.close(); - } - } - - /** - * Test that we can do the right things when the paragraph styles - * run out before the character styles do - */ - @Test - void testParagraphStylesShorterTheCharStyles() { - // Check we have the right number of sheets - List<HSLFSlide> slides = ssRichC.getSlides(); - assertEquals(14, slides.size()); - - // Check the number of text runs on interesting sheets - HSLFSlide slideThreeC = ssRichC.getSlides().get(2); - HSLFSlide slideSevenC = ssRichC.getSlides().get(6); - assertEquals(4, slideThreeC.getTextParagraphs().size()); - assertEquals(5, slideSevenC.getTextParagraphs().size()); - - // On slide three, we should have: - // TR: - // You are an important supplier of various items that I need - // . - // TR: - // Source: Internal focus groups - // TR: - // Illustrative Example - // . - - List<List<HSLFTextParagraph>> s3tr = slideThreeC.getTextParagraphs(); - List<HSLFTextRun> s3rtr0 = s3tr.get(0).get(0).getTextRuns(); - List<HSLFTextRun> s3rtr1 = s3tr.get(2).get(0).getTextRuns(); - List<HSLFTextRun> s3rtr2 = s3tr.get(3).get(0).getTextRuns(); - - assertEquals(2, s3rtr0.size()); - assertEquals(1, s3rtr1.size()); - assertEquals(2, s3rtr2.size()); - - assertEquals("You are an important supplier of various items that I need", s3rtr0.get(0).getRawText()); - assertEquals("", s3rtr0.get(1).getRawText()); - assertEquals("Source: Internal focus groups", s3rtr1.get(0).getRawText()); - assertEquals("Illustrative Example", s3rtr2.get(0).getRawText()); - assertEquals("", s3rtr2.get(1).getRawText()); - - // On slide seven, we have: - // TR: - // (text) - // TR: - // <ps>(text a)</ps><ps>(text a)(text b)</ps> - // TR: - // (text) - List<List<HSLFTextParagraph>> s7tr = slideSevenC.getTextParagraphs(); - List<HSLFTextParagraph> s7rtr0 = s7tr.get(0); - List<HSLFTextParagraph> s7rtr1 = s7tr.get(1); - List<HSLFTextParagraph> s7rtr2 = s7tr.get(2); - - assertEquals(1, s7rtr0.size()); - assertEquals(8, s7rtr1.size()); - assertEquals(1, s7rtr2.size()); - } - - /** - * Test that we can do the right things when the paragraph styles - * run out before the character styles do, when we tweak something - * and write back out. - */ - @Test - @SuppressWarnings("unused") - void testParagraphStylesShorterTheCharStylesWrite() throws IOException { - assertMatchesSLTWC(ssRichC); - assertMatchesFileC(ssRichC); - - HSLFSlide slideSevenC = ssRichC.getSlides().get(6); - List<List<HSLFTextParagraph>> s7tr = slideSevenC.getTextParagraphs(); - List<HSLFTextRun> s7rtr0 = s7tr.get(0).get(0).getTextRuns(); - List<HSLFTextRun> s7rtr1 = s7tr.get(1).get(0).getTextRuns(); - List<HSLFTextRun> s7rtr2 = s7tr.get(2).get(0).getTextRuns(); - - String oldText; - - // Reset the text on the last run - // Need to ensure it's a run that really has styles! - oldText = s7rtr2.get(0).getRawText(); - s7rtr2.get(0).setText( oldText ); - HSLFTextParagraph.storeText(s7tr.get(2)); - assertEquals(oldText, s7rtr2.get(0).getRawText()); - assertEquals(oldText, HSLFTextParagraph.getRawText(s7tr.get(2))); - assertEquals(oldText.length() + 1, s7rtr2.get(0).getCharacterStyle().getCharactersCovered()); - assertEquals(oldText.length() + 1, s7rtr2.get(0).getTextParagraph().getParagraphStyle().getCharactersCovered()); - assertMatchesSLTWC(ssRichC); - assertMatchesFileC(ssRichC); - - // Reset the text on a shared paragraph - oldText = s7rtr1.get(0).getRawText(); - s7rtr1.get(0).setText( oldText ); - HSLFTextParagraph.storeText(s7tr.get(1)); - assertEquals(oldText, s7rtr1.get(0).getRawText()); - assertEquals(oldText.length(), s7rtr1.get(0).getCharacterStyle().getCharactersCovered()); - assertMatchesSLTWC(ssRichC); - assertMatchesFileC(ssRichC); - - // Reset the text on a shared paragraph+character - s7rtr1.get(0).setText( s7rtr1.get(0).getRawText() ); - HSLFTextParagraph.storeText(s7tr.get(1)); - assertMatchesSLTWC(ssRichC); - assertMatchesFileC(ssRichC); - } - - /** - * Opens a new copy of SlideShow C, writes the active - * SlideListWithText out, and compares it to the write - * out of the supplied SlideShow. Also compares the - * contents. - */ - private void assertMatchesSLTWC(HSLFSlideShow s) throws IOException { - // Grab a new copy of slideshow C - HSLFSlideShow refC = HSLFTestDataSamples.getSlideShow(filenameC); - - // Write out the 2nd SLWT in the active document - SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1]; - byte[] raw_slwt = writeRecord(refSLWT); - - // Write out the same for the supplied slideshow - SlideListWithText s_SLWT = s.getDocumentRecord().getSlideListWithTexts()[1]; - byte[] s_slwt = writeRecord(s_SLWT); - - // Check the records are the same - assertEquals(refSLWT.getChildRecords().length, s_SLWT.getChildRecords().length); - for(int i=0; i<refSLWT.getChildRecords().length; i++) { - Record ref_r = refSLWT.getChildRecords()[i]; - Record s_r = s_SLWT.getChildRecords()[i]; - - byte[] r_rb = writeRecord(ref_r); - byte[] s_rb = writeRecord(s_r); - assertArrayEquals(r_rb, s_rb); - } - - // Check the bytes are the same - assertArrayEquals(raw_slwt, s_slwt); - } - - /** - * Checks that the supplied slideshow still matches the bytes - * of slideshow c - */ - private static void assertMatchesFileC(HSLFSlideShow s) throws IOException { - // Grab the bytes of the file - POIFSFileSystem fs = new POIFSFileSystem(HSLFTestDataSamples.openSampleFileStream(filenameC)); - InputStream is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT); - byte[] raw_file = IOUtils.toByteArray(is); - is.close(); - fs.close(); - - // Now write out the slideshow - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - s.write(baos); - fs = new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray())); - is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT); - byte[] raw_ss = IOUtils.toByteArray(is); - is.close(); - fs.close(); - - // different paragraph mask, because of sanitizing - raw_ss[169030] = 0x0a; - - // Ensure they're the same - assertArrayEquals(raw_file, raw_ss); - } - - private byte[] writeRecord( org.apache.poi.hslf.record.Record r) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - r.writeOut(baos); - return baos.toByteArray(); - } - - @Test - void testIndentationLevel() throws Exception { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("ParagraphStylesShorterThanCharStyles.ppt"); - for (HSLFSlide sl : ppt.getSlides()) { - for (List<HSLFTextParagraph> txt : sl.getTextParagraphs()) { - for (HSLFTextParagraph p : txt) { - int indent = p.getIndentLevel(); - assertTrue(indent >= 0 && indent <= 4 ); - } - - } - } - ppt.close(); - } - - @Test - void testReadParagraphStyles() throws Exception { - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("bullets.ppt")) { - HSLFTextParagraph rt; - List<List<HSLFTextParagraph>> txt; - List<HSLFSlide> slide = ppt.getSlides(); - assertEquals(2, slide.size()); - - txt = slide.get(0).getTextParagraphs(); - assertEquals(2, txt.size()); - - assertEquals("Title text", HSLFTextParagraph.getRawText(txt.get(0))); - assertEquals(1, txt.get(0).size()); - rt = txt.get(0).get(0); - assertFalse(rt.isBullet()); - - String expected = - "This is a text placeholder that \r" + - "follows the design pattern\r" + - "Defined in the slide master\r" + - "and has bullets by default"; - assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(1))); - assertEquals(4, txt.get(1).size()); - rt = txt.get(1).get(0); - assertNotNull(rt.getBulletChar()); - assertEquals('\u2022', (char) rt.getBulletChar()); - assertTrue(rt.isBullet()); - - - txt = slide.get(1).getTextParagraphs(); - assertEquals(2, txt.size()); - - expected = - "I\u2019m a text box\r" + - "With bullets\r" + - "That follow the design pattern\r" + - "From the slide master"; - assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(0))); - assertEquals(4, txt.get(0).size()); - rt = txt.get(0).get(0); - assertTrue(rt.isBullet()); - assertNotNull(rt.getBulletChar()); - assertEquals('\u2022', (char) rt.getBulletChar()); - - expected = - "I\u2019m a text box with user-defined\r" + - "bullet character"; - assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(1))); - assertEquals(2, txt.get(1).size()); - rt = txt.get(1).get(0); - assertTrue(rt.isBullet()); - assertNotNull(rt.getBulletChar()); - assertEquals('\u263A', (char) rt.getBulletChar()); - } - } - - @Test - void testSetParagraphStyles() throws IOException { - HSLFSlideShow ppt1 = new HSLFSlideShow(); - - HSLFSlide slide = ppt1.createSlide(); - - HSLFTextBox shape = new HSLFTextBox(); - shape.setText( - "Hello, World!\r" + - "This should be\r" + - "Multiline text"); - HSLFTextParagraph rt = shape.getTextParagraphs().get(0); - HSLFTextRun tr = rt.getTextRuns().get(0); - tr.setFontSize(42d); - rt.setBullet(true); - rt.setLeftMargin(50d); - rt.setIndent(0d); - rt.setBulletChar('\u263A'); - slide.addShape(shape); - - assertNotNull(tr.getFontSize()); - assertEquals(42.0, tr.getFontSize(), 0); - assertTrue(rt.isBullet()); - assertNotNull(rt.getLeftMargin()); - assertEquals(50.0, rt.getLeftMargin(), 0); - assertNotNull(rt.getIndent()); - assertEquals(0, rt.getIndent(), 0); - assertNotNull(rt.getBulletChar()); - assertEquals('\u263A', (char)rt.getBulletChar()); - - shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); - slide.addShape(shape); - - //serialize and read again - 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); - assertNotNull(tr.getFontSize()); - assertEquals(42.0, tr.getFontSize(), 0); - assertTrue(rt.isBullet()); - assertNotNull(rt.getLeftMargin()); - assertEquals(50.0, rt.getLeftMargin(), 0); - assertNotNull(rt.getIndent()); - assertEquals(0, rt.getIndent(), 0); - assertNotNull(rt.getBulletChar()); - assertEquals('\u263A', (char)rt.getBulletChar()); - ppt2.close(); - ppt1.close(); - } - - @Test - void testAddText() throws Exception { - try (HSLFSlideShow ppt1 = HSLFTestDataSamples.getSlideShow("bullets.ppt")) { - - HSLFTextParagraph rt; - HSLFTextRun tr; - List<List<HSLFTextParagraph>> txt; - List<HSLFSlide> slides = ppt1.getSlides(); - - assertEquals(2, slides.size()); - txt = slides.get(0).getTextParagraphs(); - assertEquals(2, txt.size()); - - assertEquals("Title text", HSLFTextParagraph.getRawText(txt.get(0))); - assertEquals(1, txt.get(0).size()); - rt = txt.get(0).get(0); - assertFalse(rt.isBullet()); - - // Add some new text - HSLFTextParagraph.appendText(txt.get(0), "Foo! I'm new!", true); - assertEquals(2, txt.get(0).size()); - - rt = txt.get(0).get(0); - tr = rt.getTextRuns().get(0); - assertFalse(tr.isBold()); - assertEquals("Title text\r", tr.getRawText()); - rt = txt.get(0).get(1); - tr = rt.getTextRuns().get(0); - assertFalse(tr.isBold()); - assertEquals("Foo! I'm new!", tr.getRawText()); - tr.setBold(true); - HSLFTextParagraph.storeText(txt.get(0)); - - // And some more, attributes will be copied from previous run - HSLFTextParagraph.appendText(txt.get(0), "Me too!", true); - HSLFTextParagraph.storeText(txt.get(0)); - assertEquals(3, txt.get(0).size()); - rt = txt.get(0).get(0); - tr = rt.getTextRuns().get(0); - assertFalse(tr.isBold()); - assertEquals("Title text\r", tr.getRawText()); - rt = txt.get(0).get(1); - tr = rt.getTextRuns().get(0); - assertTrue(tr.isBold()); - assertEquals("Foo! I'm new!\r", tr.getRawText()); - rt = txt.get(0).get(2); - tr = rt.getTextRuns().get(0); - assertTrue(tr.isBold()); - assertEquals("Me too!", tr.getRawText()); - - // Save and re-open - try (HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1)) { - slides = ppt2.getSlides(); - - assertEquals(2, slides.size()); - - txt = slides.get(0).getTextParagraphs(); - assertEquals(2, txt.size()); - assertEquals(3, txt.get(0).size()); - rt = txt.get(0).get(0); - tr = rt.getTextRuns().get(0); - assertFalse(tr.isBold()); - assertEquals("Title text\r", tr.getRawText()); - rt = txt.get(0).get(1); - tr = rt.getTextRuns().get(0); - assertTrue(tr.isBold()); - assertEquals("Foo! I'm new!\r", tr.getRawText()); - rt = txt.get(0).get(2); - tr = rt.getTextRuns().get(0); - assertTrue(tr.isBold()); - assertEquals("Me too!", tr.getRawText()); - } - } - } - - @Test - void testChineseParagraphs() { - List<HSLFTextRun> rts; - HSLFTextRun rt; - List<List<HSLFTextParagraph>> txt; - List<HSLFSlide> slides = ssChinese.getSlides(); - - // One slide - assertEquals(1, slides.size()); - - // One block of text within that - txt = slides.get(0).getTextParagraphs(); - assertEquals(1, txt.size()); - - // One rich block of text in that - text is all the same style - // TODO Is this completely correct? - rts = txt.get(0).get(0).getTextRuns(); - assertEquals(1, rts.size()); - rt = rts.get(0); - - // Check we can get the english text out of that - String text = rt.getRawText(); - assertContains(text, "Single byte"); - // And the chinese - assertContains(txt.get(0).get(3).getTextRuns().get(0).getRawText(), "\uff8a\uff9d\uff76\uff78"); - - // It isn't bold or italic - assertFalse(rt.isBold()); - assertFalse(rt.isItalic()); - - // Font is Calibri - assertEquals("Calibri", rt.getFontFamily()); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java deleted file mode 100644 index a2c0469bc1..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java +++ /dev/null @@ -1,96 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.util.List; - -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests that SlideShow returns Sheets which have the right text in them - */ -public final class TestSheetText { - // SlideShow primed on the test data - private HSLFSlideShow ss; - - @BeforeEach - void init() throws IOException { - ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); - } - - @AfterEach - void tearDown() throws IOException { - ss.close(); - } - - @Test - void testSheetOne() { - HSLFSheet slideOne = ss.getSlides().get(0); - - String[] expectText = new String[] {"This is a test title","This is a test subtitle\rThis is on page 1"}; - assertEquals(expectText.length, slideOne.getTextParagraphs().size()); - int i = 0; - for(List<HSLFTextParagraph> textParas : slideOne.getTextParagraphs()) { - assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas)); - } - } - - void testSheetTwo() { - HSLFSheet slideTwo = ss.getSlides().get(1); - String[] expectText = new String[] {"This is the title on page 2","This is page two\rIt has several blocks of text\rNone of them have formatting"}; - assertEquals(expectText.length, slideTwo.getTextParagraphs().size()); - int i = 0; - for(List<HSLFTextParagraph> textParas : slideTwo.getTextParagraphs()) { - assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas)); - } - } - - /** - * Check we can still get the text from a file where the - * TextProps don't have enough data. - * (Make sure we don't screw up / throw an exception etc) - */ - void testWithShortTextPropData() throws IOException { - HSLFSlideShow sss = HSLFTestDataSamples.getSlideShow("iisd_report.ppt"); - - // Should come out with 10 slides, no notes - assertEquals(10, sss.getSlides().size()); - assertEquals(0, sss.getNotes().size()); - - // Check text on first slide - HSLFSlide s = sss.getSlides().get(0); - String exp = - "Realizing the Development Dividend:\n" + - "Community Capacity Building and CDM.\n" + - "Can they co-exist?\n\n" + - "Gay Harley\n" + - "Clean Development Alliance\n" + - "COP 11 \u2013 MOP 1\n" + // special long hyphen - "December 5, 2005\n"; - - assertEquals(1, s.getTextParagraphs().size()); - assertEquals(exp, HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0))); - sss.close(); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java deleted file mode 100644 index 0a5df4dde3..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java +++ /dev/null @@ -1,134 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.util.List; - -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests that SlideShow returns Sheets in the right order - */ -public final class TestSlideOrdering { - // Simple slideshow, record order matches slide order - private HSLFSlideShow ssA; - // Complex slideshow, record order doesn't match slide order - private HSLFSlideShow ssB; - - @BeforeEach - void init() throws IOException { - ssA = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); - ssB = HSLFTestDataSamples.getSlideShow("incorrect_slide_order.ppt"); - } - - @AfterEach - void tearDown() throws IOException { - ssA.close(); - ssB.close(); - } - - /** - * Test the simple case - record order matches slide order - */ - @Test - void testSimpleCase() { - assertEquals(2, ssA.getSlides().size()); - - HSLFSlide s1 = ssA.getSlides().get(0); - HSLFSlide s2 = ssA.getSlides().get(1); - - String[] firstTRs = new String[] { "This is a test title", "This is the title on page 2" }; - - assertEquals(firstTRs[0], HSLFTextParagraph.getRawText(s1.getTextParagraphs().get(0))); - assertEquals(firstTRs[1], HSLFTextParagraph.getRawText(s2.getTextParagraphs().get(0))); - } - - /** - * Test the complex case - record order differs from slide order - */ - @Test - void testComplexCase() { - assertEquals(3, ssB.getSlides().size()); - int i=1; - for (HSLFSlide s : ssB.getSlides()) { - assertEquals("Slide "+(i++), HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0))); - } - } - - /** - * Assert that the order of slides is correct. - * - * @param filename - * file name of the slide show to assert - * @param titles - * array of reference slide titles - */ - protected void assertSlideOrdering(String filename, String[] titles) throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow(filename); - List<HSLFSlide> slide = ppt.getSlides(); - - assertEquals(titles.length, slide.size()); - for (int i = 0; i < slide.size(); i++) { - String title = slide.get(i).getTitle(); - assertEquals(titles[i], title, "Wrong slide title in " + filename); - } - ppt.close(); - } - - @Test - void testTitles() throws Exception { - assertSlideOrdering("basic_test_ppt_file.ppt", new String[] { - "This is a test title", "This is the title on page 2" }); - - assertSlideOrdering("incorrect_slide_order.ppt", new String[] { "Slide 1", - "Slide 2", "Slide 3" }); - - assertSlideOrdering("next_test_ppt_file.ppt", new String[] { - "This is a test title", "This is the title on page 2" }); - - assertSlideOrdering("Single_Coloured_Page.ppt", - new String[] { "This is a title, it" + (char) 0x2019 + "s in black" }); - - assertSlideOrdering("Single_Coloured_Page_With_Fonts_and_Alignments.ppt", - new String[] { "This is a title, it" + (char) 0x2019 + "s in black" }); - - assertSlideOrdering( - "ParagraphStylesShorterThanCharStyles.ppt", - new String[] { - "ROMANCE: AN ANALYSIS", - "AGENDA", - "You are an important supplier of various items that I need", - '\n' + "Although The Psycho set back my relationship process, recovery is luckily enough under way", - "Since the time that we seriously go out together, you rank highly among existing relationships", - "Although our personal interests are mostly compatible, the greatest gap exists in Sex and Shopping", - "Your physical characteristics are strong when compared with your competition", - "The combination of your high physical appearance and personality rank you highly, although your sister is also a top prospect", - "When people found out that we were going out, their responses have been mixed", - "The benchmark of relationship lifecycles, suggests that we are on schedule", - "In summary we can say that we are on the right track, but we must remain aware of possible roadblocks ", - "THE ANSWER", - "Unfortunately a huge disconnect exists between my needs and your existing service", - "SUMMARY", }); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSoundData.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSoundData.java deleted file mode 100644 index 3ac70bd00d..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSoundData.java +++ /dev/null @@ -1,46 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.junit.jupiter.api.Test; - -/** - * Test reading sound data from a ppt - */ -public final class TestSoundData { - /** - * Read a reference sound file from disk and compare it from the data extracted from the slide show - */ - @Test - void testSounds() throws Exception { - //read the reference sound file - byte[] ref_data = HSLFTestDataSamples.getTestDataFileContent("ringin.wav"); - - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("sound.ppt"); - - HSLFSoundData[] sound = ppt.getSoundData(); - assertEquals(1, sound.length, "Expected 1 sound"); - - assertArrayEquals(ref_data, sound[0].getData()); - ppt.close(); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java deleted file mode 100644 index 1176003e7a..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.awt.Color; -import java.awt.geom.Rectangle2D; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.List; - -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.apache.poi.sl.draw.DrawTableShape; -import org.apache.poi.sl.usermodel.StrokeStyle; -import org.junit.jupiter.api.Test; - - -/** - * Table related tests - */ -public class TestTable { - @Test - void moveTable() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - HSLFSlide slide = ppt.createSlide(); - int rows = 3, cols = 5; - HSLFTable table = slide.createTable(rows, cols); - for (int row=0; row<rows; row++) { - for (int col=0; col<cols; col++) { - HSLFTableCell c = table.getCell(row, col); - assertNotNull(c); - c.setText("r"+row+"c"+col); - } - } - - new DrawTableShape(table).setAllBorders(1.0, Color.black, StrokeStyle.LineDash.DASH_DOT); - - table.setAnchor(new Rectangle2D.Double(100, 100, 400, 400)); - - Rectangle2D rectExp = new Rectangle2D.Double(420,366.625,80,133.375); - HSLFTableCell c = table.getCell(rows - 1, cols - 1); - assertNotNull(c); - Rectangle2D rectAct = c.getAnchor(); - assertEquals(rectExp, rectAct); - ppt.close(); - } - - @Test - void testTable() throws IOException { - try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("54111.ppt")) { - List<HSLFSlide> slides = ppt.getSlides(); - assertEquals(1, slides.size()); - checkSlide(slides.get(0)); - } - } - - private void checkSlide(final HSLFSlide s) { - List<List<HSLFTextParagraph>> textRuns = s.getTextParagraphs(); - assertEquals(2, textRuns.size()); - - HSLFTextRun textRun = textRuns.get(0).get(0).getTextRuns().get(0); - assertEquals("Table sample", textRun.getRawText().trim()); - assertEquals(1, textRuns.get(0).get(0).getTextRuns().size()); - assertFalse(textRun.getTextParagraph().isBullet()); - - assertEquals("Dummy text", HSLFTextParagraph.getRawText(textRuns.get(1))); - - List<HSLFShape> shapes = s.getShapes(); - assertNotNull(shapes); - assertEquals(3, shapes.size()); - assertTrue(shapes.get(2) instanceof HSLFTable); - final HSLFTable table = (HSLFTable) shapes.get(2); - assertEquals(4, table.getNumberOfColumns()); - assertEquals(6, table.getNumberOfRows()); - for (int x = 0; x < 4; x ++) { - HSLFTableCell c = table.getCell(0, x); - assertNotNull(c); - assertEquals("TH Cell " + (x + 1), HSLFTextParagraph.getRawText(c.getTextParagraphs())); - for (int y = 1; y < 6; y++) { - c = table.getCell(y, x); - assertNotNull(c); - assertEquals("Row " + y + ", Cell " + (x + 1), c.getText()); - } - } - } - - @Test - void testAddText() throws IOException { - HSLFSlideShow ppt1 = new HSLFSlideShow(); - HSLFSlide slide = ppt1.createSlide(); - HSLFTable tab = slide.createTable(4, 5); - - int rows = tab.getNumberOfRows(); - int cols = tab.getNumberOfColumns(); - for (int row=0; row<rows; row++) { - for (int col=0; col<cols; col++) { - HSLFTableCell c = tab.getCell(row, col); - assertNotNull(c); - c.setText("r"+(row+1)+"c"+(col+1)); - } - } - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ppt1.write(bos); - ppt1.close(); - - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - HSLFSlideShow ppt2 = new HSLFSlideShow(bis); - slide = ppt2.getSlides().get(0); - tab = (HSLFTable)slide.getShapes().get(0); - - rows = tab.getNumberOfRows(); - cols = tab.getNumberOfColumns(); - for (int row=0; row<rows; row++) { - for (int col=0; col<cols; col++) { - HSLFTableCell c = tab.getCell(row, col); - assertNotNull(c); - c.setText(c.getText()+"..."); - } - } - - bos.reset(); - ppt2.write(bos); - ppt2.close(); - - bis = new ByteArrayInputStream(bos.toByteArray()); - HSLFSlideShow ppt3 = new HSLFSlideShow(bis); - slide = ppt3.getSlides().get(0); - tab = (HSLFTable)slide.getShapes().get(0); - - rows = tab.getNumberOfRows(); - cols = tab.getNumberOfColumns(); - for (int row=0; row<rows; row++) { - for (int col=0; col<cols; col++) { - HSLFTableCell c = tab.getCell(row, col); - assertNotNull(c); - assertEquals("r"+(row+1)+"c"+(col+1)+"...", c.getText()); - } - } - - ppt3.close(); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java deleted file mode 100644 index 6fc4dc6030..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java +++ /dev/null @@ -1,586 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.apache.poi.sl.usermodel.BaseTestSlideShow.getColor; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.awt.Color; -import java.io.IOException; -import java.util.List; - -import org.apache.poi.hslf.HSLFTestDataSamples; -import org.apache.poi.hslf.model.textproperties.TextPropCollection; -import org.apache.poi.hslf.record.TextBytesAtom; -import org.apache.poi.hslf.record.TextCharsAtom; -import org.apache.poi.hslf.record.TextHeaderAtom; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests for TextRuns - */ -@SuppressWarnings("UnusedAssignment") -public final class TestTextRun { - // SlideShow primed on the test data - private HSLFSlideShow ss; - private HSLFSlideShow ssRich; - - @BeforeEach - void setUp() throws IOException { - // Basic (non rich) test file - ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); - - // Rich test file - ssRich = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt"); - } - - @AfterEach - void tearDown() throws IOException { - ssRich.close(); - ss.close(); - } - - /** - * Test to ensure that getting the text works correctly - */ - @Test - void testGetText() { - HSLFSlide slideOne = ss.getSlides().get(0); - List<List<HSLFTextParagraph>> textParas = slideOne.getTextParagraphs(); - - assertEquals(2, textParas.size()); - - // Get text works with \n - assertEquals("This is a test title", HSLFTextParagraph.getText(textParas.get(0))); - assertEquals("This is a test subtitle\nThis is on page 1", HSLFTextParagraph.getText(textParas.get(1))); - - // Raw text has \r instead - assertEquals("This is a test title", HSLFTextParagraph.getRawText(textParas.get(0))); - assertEquals("This is a test subtitle\rThis is on page 1", HSLFTextParagraph.getRawText(textParas.get(1))); - - - // Now check on a rich text run - HSLFSlide slideOneR = ssRich.getSlides().get(0); - textParas = slideOneR.getTextParagraphs(); - - assertEquals(2, textParas.size()); - assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getText(textParas.get(0))); - assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", HSLFTextParagraph.getText(textParas.get(1))); - assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getRawText(textParas.get(0))); - assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", HSLFTextParagraph.getRawText(textParas.get(1))); - } - - /** - * Test to ensure changing non rich text bytes->bytes works correctly - */ - @Test - void testSetText() { - HSLFSlide slideOne = ss.getSlides().get(0); - List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs(); - HSLFTextParagraph run = textRuns.get(0).get(0); - HSLFTextRun tr = run.getTextRuns().get(0); - - // Check current text - assertEquals("This is a test title", tr.getRawText()); - - // Change - String changeTo = "New test title"; - tr.setText(changeTo); - assertEquals(changeTo, tr.getRawText()); - - // Ensure trailing \n's are NOT stripped, it is legal to set a text with a trailing '\r' - tr.setText(changeTo + "\n"); - assertEquals(changeTo + "\r", tr.getRawText()); - } - - /** - * Test to ensure that changing non rich text between bytes and - * chars works correctly - */ - @SuppressWarnings("unused") - @Test - void testAdvancedSetText() { - HSLFSlide slideOne = ss.getSlides().get(0); - List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0); - HSLFTextParagraph para = paras.get(0); - - TextHeaderAtom tha = null; - TextBytesAtom tba = null; - TextCharsAtom tca = null; - for ( org.apache.poi.hslf.record.Record r : para.getRecords()) { - if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r; - else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r; - else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r; - } - - // Bytes -> Bytes - assertNull(tca); - assertNotNull(tba); - // assertFalse(run._isUnicode); - assertEquals("This is a test title", para.getTextRuns().get(0).getRawText()); - - String changeBytesOnly = "New Test Title"; - HSLFTextParagraph.setText(paras, changeBytesOnly); - para = paras.get(0); - tha = null; tba = null; tca = null; - for ( org.apache.poi.hslf.record.Record r : para.getRecords()) { - if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r; - else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r; - else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r; - } - - assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras)); - assertNull(tca); - assertNotNull(tba); - - // Bytes -> Chars - assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras)); - - String changeByteChar = "This is a test title with a '\u0121' g with a dot"; - HSLFTextParagraph.setText(paras, changeByteChar); - para = paras.get(0); - tha = null; tba = null; tca = null; - for ( org.apache.poi.hslf.record.Record r : para.getRecords()) { - if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r; - else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r; - else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r; - } - - assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras)); - assertNotNull(tca); - assertNull(tba); - - // Chars -> Chars - assertNotNull(tca); - assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras)); - - String changeCharChar = "This is a test title with a '\u0147' N with a hat"; - HSLFTextParagraph.setText(paras, changeCharChar); - para = paras.get(0); - tha = null; tba = null; tca = null; - for ( org.apache.poi.hslf.record.Record r : para.getRecords()) { - if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r; - else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r; - else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r; - } - - assertEquals(changeCharChar, HSLFTextParagraph.getRawText(paras)); - assertNotNull(tca); - assertNull(tba); - } - - /** - * Tests to ensure that non rich text has the right default rich text run - * set up for it - */ - @Test - void testGetRichTextNonRich() { - HSLFSlide slideOne = ss.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - - assertEquals(2, textParass.size()); - - List<HSLFTextParagraph> trA = textParass.get(0); - List<HSLFTextParagraph> trB = textParass.get(1); - - assertEquals(1, trA.size()); - assertEquals(2, trB.size()); - - HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0); - HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0); - - assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText()); - assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), rtrB.getRawText()); - } - - /** - * Tests to ensure that the rich text runs are built up correctly - */ - @Test - void testGetRichText() { - HSLFSlide slideOne = ssRich.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - - assertEquals(2, textParass.size()); - - List<HSLFTextParagraph> trA = textParass.get(0); - List<HSLFTextParagraph> trB = textParass.get(1); - - assertEquals(1, trA.size()); - assertEquals(3, trB.size()); - - HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0); - HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0); - HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0); - HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0); - - assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText()); - - String trBstr = HSLFTextParagraph.getRawText(trB); - assertEquals(trBstr.substring(0, 30), rtrB.getRawText()); - assertEquals(trBstr.substring(30,58), rtrC.getRawText()); - assertEquals(trBstr.substring(58,82), rtrD.getRawText()); - - // Same paragraph styles - assertEquals(trB.get(0).getParagraphStyle(), trB.get(1).getParagraphStyle()); - assertEquals(trB.get(0).getParagraphStyle(), trB.get(2).getParagraphStyle()); - - // Different char styles - assertNotEquals(rtrB.getCharacterStyle(), rtrC.getCharacterStyle()); - assertNotEquals(rtrB.getCharacterStyle(), rtrD.getCharacterStyle()); - assertNotEquals(rtrC.getCharacterStyle(), rtrD.getCharacterStyle()); - } - - /** - * Tests to ensure that setting the text where the text isn't rich, - * ensuring that everything stays with the same default styling - */ - @Test - void testSetTextWhereNotRich() { - HSLFSlide slideOne = ss.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - List<HSLFTextParagraph> trB = textParass.get(0); - assertEquals(1, trB.size()); - - HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0); - assertEquals(HSLFTextParagraph.getText(trB), rtrB.getRawText()); - - // Change text via normal - HSLFTextParagraph.setText(trB, "Test Foo Test"); - rtrB = trB.get(0).getTextRuns().get(0); - assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB)); - assertEquals("Test Foo Test", rtrB.getRawText()); - } - - /** - * Tests to ensure that setting the text where the text is rich - * sets everything to the same styling - */ - @Test - void testSetTextWhereRich() { - HSLFSlide slideOne = ssRich.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - List<HSLFTextParagraph> trB = textParass.get(1); - assertEquals(3, trB.size()); - - HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0); - HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0); - HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0); - TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle(); - TextPropCollection tpBC = rtrB.getCharacterStyle(); - TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle(); - TextPropCollection tpCC = rtrC.getCharacterStyle(); - TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle(); - TextPropCollection tpDC = rtrD.getCharacterStyle(); - -// assertEquals(trB.getRawText().substring(0, 30), rtrB.getRawText()); - assertNotNull(tpBP); - assertNotNull(tpBC); - assertNotNull(tpCP); - assertNotNull(tpCC); - assertNotNull(tpDP); - assertNotNull(tpDC); - assertEquals(tpBP,tpCP); - assertEquals(tpBP,tpDP); - assertEquals(tpCP,tpDP); - assertNotEquals(tpBC,tpCC); - assertNotEquals(tpBC,tpDC); - assertNotEquals(tpCC,tpDC); - - // Change text via normal - HSLFTextParagraph.setText(trB, "Test Foo Test"); - - // Ensure now have first style - assertEquals(1, trB.get(0).getTextRuns().size()); - rtrB = trB.get(0).getTextRuns().get(0); - assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB)); - assertEquals("Test Foo Test", rtrB.getRawText()); - assertNotNull(rtrB.getCharacterStyle()); - assertNotNull(rtrB.getTextParagraph().getParagraphStyle()); - assertEquals( tpBP, rtrB.getTextParagraph().getParagraphStyle() ); - assertEquals( tpBC, rtrB.getCharacterStyle() ); - } - - /** - * Test to ensure the right stuff happens if we change the text - * in a rich text run, that doesn't happen to actually be rich - */ - @Test - void testChangeTextInRichTextRunNonRich() { - HSLFSlide slideOne = ss.getSlides().get(0); - List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs(); - List<HSLFTextParagraph> trB = textRuns.get(1); - assertEquals(1, trB.get(0).getTextRuns().size()); - - HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0); - assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), rtrB.getRawText()); - assertNotNull(rtrB.getCharacterStyle()); - assertNotNull(rtrB.getTextParagraph().getParagraphStyle()); - - // Change text via rich - rtrB.setText("Test Test Test"); - assertEquals("Test Test Test", HSLFTextParagraph.getRawText(trB.subList(0, 1))); - assertEquals("Test Test Test", rtrB.getRawText()); - - // Will now have dummy props - assertNotNull(rtrB.getCharacterStyle()); - assertNotNull(rtrB.getTextParagraph().getParagraphStyle()); - } - - /** - * Tests to ensure changing the text within rich text runs works - * correctly - */ - @Test - void testChangeTextInRichTextRun() { - HSLFSlide slideOne = ssRich.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs(); - List<HSLFTextParagraph> trB = textParass.get(1); - assertEquals(3, trB.size()); - - // We start with 3 text runs, each with their own set of styles, - // but all sharing the same paragraph styles - HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0); - HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0); - HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0); - TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle(); - TextPropCollection tpBC = rtrB.getCharacterStyle(); - TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle(); - TextPropCollection tpCC = rtrC.getCharacterStyle(); - TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle(); - TextPropCollection tpDC = rtrD.getCharacterStyle(); - - // Check text and stylings - assertEquals(HSLFTextParagraph.getRawText(trB).substring(0, 30), rtrB.getRawText()); - assertNotNull(tpBP); - assertNotNull(tpBC); - assertNotNull(tpCP); - assertNotNull(tpCC); - assertNotNull(tpDP); - assertNotNull(tpDC); - assertEquals(tpBP, tpCP); - assertEquals(tpBP, tpDP); - assertEquals(tpCP, tpDP); - assertNotEquals(tpBC, tpCC); - assertNotEquals(tpBC, tpDC); - assertNotEquals(tpCC, tpDC); - - // Check text in the rich runs - assertEquals("This is the subtitle, in bold\r", rtrB.getRawText()); - assertEquals("This bit is blue and italic\r", rtrC.getRawText()); - assertEquals("This bit is red (normal)", rtrD.getRawText()); - - String newBText = "New Subtitle, will still be bold\n"; - String newCText = "New blue and italic text\n"; - String newDText = "Funky new normal red text"; - rtrB.setText(newBText); - rtrC.setText(newCText); - rtrD.setText(newDText); - HSLFTextParagraph.storeText(trB); - - assertEquals(newBText.replace('\n','\r'), rtrB.getRawText()); - assertEquals(newCText.replace('\n','\r'), rtrC.getRawText()); - assertEquals(newDText.replace('\n','\r'), rtrD.getRawText()); - - assertEquals(newBText.replace('\n','\r') + newCText.replace('\n','\r') + newDText.replace('\n','\r'), HSLFTextParagraph.getRawText(trB)); - - // The styles should have been updated for the new sizes - assertEquals(newBText.length(), tpBC.getCharactersCovered()); - assertEquals(newCText.length(), tpCC.getCharactersCovered()); - assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // Last one is always one larger - - // Paragraph style should be sum of text length - assertEquals( - newBText.length() + newCText.length() + newDText.length() +1, - tpBP.getCharactersCovered() + tpCP.getCharactersCovered() + tpDP.getCharactersCovered() - ); - - // Check stylings still as expected - TextPropCollection ntpBC = rtrB.getCharacterStyle(); - TextPropCollection ntpCC = rtrC.getCharacterStyle(); - TextPropCollection ntpDC = rtrD.getCharacterStyle(); - assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList()); - assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList()); - assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList()); - } - - - /** - * Test case for Bug 41015. - * - * In some cases RichTextRun.getText() threw StringIndexOutOfBoundsException because - * of the wrong list of potential paragraph properties defined in StyleTextPropAtom. - * - */ - @Test - void testBug41015() throws IOException { - List<HSLFTextRun> rt; - - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("bug-41015.ppt"); - HSLFSlide sl = ppt.getSlides().get(0); - List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs(); - assertEquals(2, textParass.size()); - - List<HSLFTextParagraph> textParas = textParass.get(0); - rt = textParass.get(0).get(0).getTextRuns(); - assertEquals(1, rt.size()); - assertEquals(0, textParass.get(0).get(0).getIndentLevel()); - assertEquals("sdfsdfsdf", rt.get(0).getRawText()); - - textParas = textParass.get(1); - String[] texts = {"Sdfsdfsdf\r", "Dfgdfg\r", "Dfgdfgdfg\r", "Sdfsdfs\r", "Sdfsdf\r"}; - int[] indents = {0, 0, 0, 1, 1}; - int i=0; - for (HSLFTextParagraph p : textParas) { - assertEquals(texts[i], p.getTextRuns().get(0).getRawText()); - assertEquals(indents[i], p.getIndentLevel()); - i++; - } - ppt.close(); - } - - /** - * Test creation of TextRun objects. - */ - @Test - void testAddTextRun() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - HSLFSlide slide = ppt.createSlide(); - - assertEquals(0, slide.getTextParagraphs().size()); - - HSLFTextBox shape1 = new HSLFTextBox(); - List<HSLFTextParagraph> run1 = shape1.getTextParagraphs(); - shape1.setText("Text 1"); - slide.addShape(shape1); - - //The array of Slide's text runs must be updated when new text shapes are added. - List<List<HSLFTextParagraph>> runs = slide.getTextParagraphs(); - assertNotNull(runs); - assertSame(run1, runs.get(0)); - - HSLFTextBox shape2 = new HSLFTextBox(); - List<HSLFTextParagraph> run2 = shape2.getTextParagraphs(); - shape2.setText("Text 2"); - slide.addShape(shape2); - - runs = slide.getTextParagraphs(); - assertEquals(2, runs.size()); - - assertSame(run1, runs.get(0)); - assertSame(run2, runs.get(1)); - - // as getShapes() - List<HSLFShape> sh = slide.getShapes(); - assertEquals(2, sh.size()); - assertTrue(sh.get(0) instanceof HSLFTextBox); - HSLFTextBox box1 = (HSLFTextBox)sh.get(0); - assertSame(run1, box1.getTextParagraphs()); - HSLFTextBox box2 = (HSLFTextBox)sh.get(1); - assertSame(run2, box2.getTextParagraphs()); - - // test Table - a complex group of shapes containing text objects - HSLFSlide slide2 = ppt.createSlide(); - assertTrue(slide2.getTextParagraphs().isEmpty()); - HSLFTable table = new HSLFTable(2, 2); - slide2.addShape(table); - runs = slide2.getTextParagraphs(); - assertNotNull(runs); - assertEquals(4, runs.size()); - ppt.close(); - } - - @Test - void test48916() throws IOException { - 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; - HSLFTextShape tx = (HSLFTextShape)sh; - List<HSLFTextParagraph> paras = tx.getTextParagraphs(); - //verify that records cached in TextRun and EscherTextboxWrapper are the same - org.apache.poi.hslf.record.Record[] runChildren = paras.get(0).getRecords(); - org.apache.poi.hslf.record.Record[] txboxChildren = tx.getEscherTextboxWrapper().getChildRecords(); - assertEquals(runChildren.length, txboxChildren.length); - for(int i=0; i < txboxChildren.length; i++){ - assertSame(txboxChildren[i], runChildren[i]); - } - // caused NPE prior to fix of Bugzilla #48916 - for (HSLFTextParagraph p : paras) { - for (HSLFTextRun rt : p.getTextRuns()) { - rt.setBold(true); - rt.setFontColor(Color.RED); - } - } - // tx.storeText(); - } - } - - HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1); - for(HSLFSlide slide : ppt2.getSlides()){ - for(HSLFShape sh : slide.getShapes()){ - if(sh instanceof HSLFTextShape){ - HSLFTextShape tx = (HSLFTextShape)sh; - List<HSLFTextParagraph> run = tx.getTextParagraphs(); - HSLFTextRun rt = run.get(0).getTextRuns().get(0); - assertTrue(rt.isBold()); - assertEquals(Color.RED, getColor(rt.getFontColor())); - } - } - } - ppt2.close(); - ppt1.close(); - } - - @Test - void test52244() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("52244.ppt"); - HSLFSlide slide = ppt.getSlides().get(0); - - int[] sizes = {36, 24, 12, 32, 12, 12}; - - int i=0; - for (List<HSLFTextParagraph> textParas : slide.getTextParagraphs()) { - HSLFTextRun first = textParas.get(0).getTextRuns().get(0); - assertEquals("Arial", first.getFontFamily()); - assertNotNull(first.getFontSize()); - assertEquals(sizes[i++], first.getFontSize().intValue()); - } - ppt.close(); - } - - @Test - void testAppendEmpty() throws IOException { - try (HSLFSlideShow ppt = new HSLFSlideShow()) { - HSLFSlide s = ppt.createSlide(); - HSLFTextBox title = s.addTitle(); - title.setText(""); - title.appendText("\n", true); - title.appendText("para", true); - assertEquals("\npara", title.getText()); - } - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java deleted file mode 100644 index 1b577eb273..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java +++ /dev/null @@ -1,224 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hslf.usermodel; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -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.hslf.HSLFTestDataSamples; -import org.apache.poi.sl.usermodel.ShapeType; -import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder; -import org.junit.jupiter.api.Test; - -/** - * Verify behavior of <code>TextShape</code> and its sub-classes - */ -public final class TestTextShape { - @Test - void createAutoShape(){ - HSLFTextShape shape = new HSLFAutoShape(ShapeType.TRAPEZOID); - assertNull(shape.getEscherTextboxWrapper()); - assertNotNull(shape.getTextParagraphs()); - assertNotNull(shape.getEscherTextboxWrapper()); - assertEquals("", shape.getText()); - assertEquals(-1, shape.getTextParagraphs().get(0).getIndex()); - } - - @Test - void createTextBox(){ - HSLFTextShape shape = new HSLFTextBox(); - List<HSLFTextParagraph> paras = shape.getTextParagraphs(); - assertNotNull(paras); - assertNotNull(shape.getText()); - assertNotNull(shape.getEscherTextboxWrapper()); - - assertNotNull(shape.getTextParagraphs()); - assertNotNull(shape.getEscherTextboxWrapper()); - assertEquals("", shape.getText()); - - } - - /** - * Verify we can get text from TextShape in the following cases: - * - placeholders - * - normal TextBox object - * - text in auto-shapes - */ - @Test - void read() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("text_shapes.ppt"); - - List<String> lst1 = new ArrayList<>(); - HSLFSlide slide = ppt.getSlides().get(0); - for (HSLFShape shape : slide.getShapes()) { - assertTrue(shape instanceof HSLFTextShape, "Expected TextShape but found " + shape.getClass().getName()); - HSLFTextShape tx = (HSLFTextShape)shape; - List<HSLFTextParagraph> paras = tx.getTextParagraphs(); - assertNotNull(paras); - int runType = paras.get(0).getRunType(); - - ShapeType type = shape.getShapeType(); - String rawText = HSLFTextParagraph.getRawText(paras); - switch (type){ - case TEXT_BOX: - assertEquals("Text in a TextBox", rawText); - break; - case RECT: - if(runType == TextPlaceholder.OTHER.nativeId) { - assertEquals("Rectangle", rawText); - } else if(runType == TextPlaceholder.TITLE.nativeId) { - assertEquals("Title Placeholder", rawText); - } - break; - case OCTAGON: - assertEquals("Octagon", rawText); - break; - case ELLIPSE: - assertEquals("Ellipse", rawText); - break; - case ROUND_RECT: - assertEquals("RoundRectangle", rawText); - break; - default: - fail("Unexpected shape: " + shape.getShapeName()); - - } - lst1.add(rawText); - } - - List<String> lst2 = new ArrayList<>(); - for (List<HSLFTextParagraph> paras : slide.getTextParagraphs()) { - lst2.add(HSLFTextParagraph.getRawText(paras)); - } - - assertTrue(lst1.containsAll(lst2)); - ppt.close(); - } - - @Test - void readWrite() throws IOException { - HSLFSlideShow ppt = new HSLFSlideShow(); - HSLFSlide slide = ppt.createSlide(); - - HSLFTextShape shape1 = new HSLFTextBox(); - shape1.setText("Hello, World!"); - slide.addShape(shape1); - - shape1.moveTo(100, 100); - - HSLFTextShape shape2 = new HSLFAutoShape(ShapeType.RIGHT_ARROW); - shape2.setText("Testing TextShape"); - slide.addShape(shape2); - shape2.moveTo(300, 300); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ppt.write(out); - out.close(); - - ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())); - slide = ppt.getSlides().get(0); - List<HSLFShape> shape = slide.getShapes(); - - assertTrue(shape.get(0) instanceof HSLFTextShape); - shape1 = (HSLFTextShape)shape.get(0); - assertEquals(ShapeType.TEXT_BOX, shape1.getShapeType()); - assertEquals("Hello, World!", shape1.getText()); - - assertTrue(shape.get(1) instanceof HSLFTextShape); - shape1 = (HSLFTextShape)shape.get(1); - assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType()); - assertEquals("Testing TextShape", shape1.getText()); - ppt.close(); - } - - @Test - void margins() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("text-margins.ppt"); - - HSLFSlide slide = ppt.getSlides().get(0); - - Map<String,HSLFTextShape> map = new HashMap<>(); - for (HSLFShape shape : slide.getShapes()) { - if(shape instanceof HSLFTextShape){ - HSLFTextShape tx = (HSLFTextShape)shape; - map.put(tx.getText(), tx); - } - } - - HSLFTextShape tx; - - tx = map.get("TEST1"); - assertEquals(7.2, tx.getLeftInset(), 0); - assertEquals(7.2, tx.getRightInset(), 0); - assertEquals(28.34, tx.getTopInset(), 0.01); - assertEquals(3.6, tx.getBottomInset(), 0); - - tx = map.get("TEST2"); - assertEquals(7.2, tx.getLeftInset(), 0); - assertEquals(7.2, tx.getRightInset(), 0); - assertEquals(3.6, tx.getTopInset(), 0); - assertEquals(28.34, tx.getBottomInset(), 0.01); - - tx = map.get("TEST3"); - assertEquals(28.34, tx.getLeftInset(), 0.01); - assertEquals(7.2, tx.getRightInset(), 0); - assertEquals(3.6, tx.getTopInset(), 0); - assertEquals(3.6, tx.getBottomInset(), 0); - - tx = map.get("TEST4"); - assertEquals(7.2, tx.getLeftInset(), 0); - assertEquals(28.34, tx.getRightInset(), 0.01); - assertEquals(3.6, tx.getTopInset(), 0); - assertEquals(3.6, tx.getBottomInset(), 0); - - ppt.close(); - } - - @Test - void bug52599() throws IOException { - HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("52599.ppt"); - - HSLFSlide slide = ppt.getSlides().get(0); - List<HSLFShape> sh = slide.getShapes(); - assertEquals(3, sh.size()); - - HSLFTextShape sh0 = (HSLFTextShape)sh.get(0); - assertNotNull(sh0.getTextParagraphs()); - assertEquals("", sh0.getText()); - - HSLFTextShape sh1 = (HSLFTextShape)sh.get(1); - assertNotNull(sh1.getTextParagraphs()); - assertEquals("", sh1.getText()); - - 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(); - } -} |