From 6e7bba8cac71e6cd9c262d8fd645c7f88796dffa Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sun, 17 Jul 2016 13:25:02 +0000 Subject: [PATCH] bug 58190: push down XMLSlideShow tests to BaseTestSlideShow, add coverage for HSLFSlideShow add tests for SlideShow.findPicture and SlideShow.addPicture git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753073 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/sl/usermodel/SlideShow.java | 14 ++- .../poi/xslf/usermodel/XMLSlideShow.java | 6 +- .../poi/xslf/usermodel/TestXMLSlideShow.java | 62 +++---------- .../poi/hslf/usermodel/HSLFSlideShow.java | 66 ++++++-------- .../poi/hslf/usermodel/TestHSLFSlideShow.java | 35 ++++++++ .../poi/sl/usermodel/BaseTestSlideShow.java | 89 +++++++++++++++++++ 6 files changed, 183 insertions(+), 89 deletions(-) create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java create mode 100644 src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java diff --git a/src/java/org/apache/poi/sl/usermodel/SlideShow.java b/src/java/org/apache/poi/sl/usermodel/SlideShow.java index 10f442ae68..e46ce243f8 100644 --- a/src/java/org/apache/poi/sl/usermodel/SlideShow.java +++ b/src/java/org/apache/poi/sl/usermodel/SlideShow.java @@ -18,7 +18,11 @@ package org.apache.poi.sl.usermodel; import java.awt.Dimension; -import java.io.*; +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.List; import org.apache.poi.sl.usermodel.PictureData.PictureType; @@ -91,6 +95,14 @@ public interface SlideShow< * @return the picture data reference */ PictureData addPicture(File pict, PictureType format) throws IOException; + + /** + * check if a picture with this picture data already exists in this presentation + * + * @param pictureData The picture data to find in the SlideShow + * @return {@code null} if picture data is not found in this slideshow + */ + PictureData findPictureData(byte[] pictureData); /** * Writes out the slideshow file the is represented by an instance of this diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index 17a736859d..fe969d36b5 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -504,8 +504,12 @@ implements SlideShow { /** * check if a picture with this picture data already exists in this presentation + * + * @param pictureData The picture data to find in the SlideShow + * @return {@code null} if picture data is not found in this slideshow */ - XSLFPictureData findPictureData(byte[] pictureData){ + @Override + public XSLFPictureData findPictureData(byte[] pictureData) { long checksum = IOUtils.calculateChecksum(pictureData); byte cs[] = new byte[LittleEndianConsts.LONG_SIZE]; LittleEndian.putLong(cs,0,checksum); diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java index 06e55aeca1..0e58d410c3 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java @@ -19,32 +19,37 @@ package org.apache.poi.xslf.usermodel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import java.io.File; import java.io.IOException; -import java.io.InputStream; -import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; -import org.apache.poi.sl.usermodel.PictureData.PictureType; +import org.apache.poi.sl.usermodel.BaseTestSlideShow; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; -public class TestXMLSlideShow { - private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); +public class TestXMLSlideShow extends BaseTestSlideShow { private OPCPackage pack; + + @Override + public XMLSlideShow createSlideShow() { + return new XMLSlideShow(); + } @Before public void setUp() throws Exception { pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx")); } + + @After + public void tearDown() throws IOException { + pack.revert(); + } @Test public void testContainsMainContentType() throws Exception { @@ -173,45 +178,4 @@ public class TestXMLSlideShow { xmlComments.close(); xml.close(); } - - @Test - public void addPicture_File() throws IOException { - XMLSlideShow xml = new XMLSlideShow(); - File f = slTests.getFile("clock.jpg"); - - assertEquals(0, xml.getPictureData().size()); - XSLFPictureData picture = xml.addPicture(f, PictureType.JPEG); - assertEquals(1, xml.getPictureData().size()); - assertSame(picture, xml.getPictureData().get(0)); - - xml.close(); - } - - @Test - public void addPicture_Stream() throws IOException { - XMLSlideShow xml = new XMLSlideShow(); - InputStream stream = slTests.openResourceAsStream("clock.jpg"); - - assertEquals(0, xml.getPictureData().size()); - XSLFPictureData picture = xml.addPicture(stream, PictureType.JPEG); - assertEquals(1, xml.getPictureData().size()); - assertSame(picture, xml.getPictureData().get(0)); - - xml.close(); - } - - /** also tests {@link XMLSlideShow#addPicture(byte[], PictureType)} */ - @Test - public void findPicture() throws IOException { - XMLSlideShow xml = new XMLSlideShow(); - byte[] data = slTests.readFile("clock.jpg"); - - assertNull(xml.findPictureData(data)); - XSLFPictureData picture = xml.addPicture(data, PictureType.JPEG); - XSLFPictureData found = xml.findPictureData(data); - assertNotNull(found); - assertEquals(picture, found); - - xml.close(); - } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java index 10990eaf4c..7903d2a9c7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java @@ -42,35 +42,8 @@ import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.model.HeadersFooters; import org.apache.poi.hslf.model.MovieShape; import org.apache.poi.hslf.model.PPFont; -import org.apache.poi.hslf.record.Document; -import org.apache.poi.hslf.record.DocumentAtom; -import org.apache.poi.hslf.record.ExAviMovie; -import org.apache.poi.hslf.record.ExControl; -import org.apache.poi.hslf.record.ExEmbed; -import org.apache.poi.hslf.record.ExEmbedAtom; -import org.apache.poi.hslf.record.ExMCIMovie; -import org.apache.poi.hslf.record.ExObjList; -import org.apache.poi.hslf.record.ExObjListAtom; -import org.apache.poi.hslf.record.ExOleObjAtom; -import org.apache.poi.hslf.record.ExOleObjStg; -import org.apache.poi.hslf.record.ExVideoContainer; -import org.apache.poi.hslf.record.FontCollection; -import org.apache.poi.hslf.record.FontEntityAtom; -import org.apache.poi.hslf.record.HeadersFootersContainer; -import org.apache.poi.hslf.record.MainMaster; -import org.apache.poi.hslf.record.Notes; -import org.apache.poi.hslf.record.PersistPtrHolder; -import org.apache.poi.hslf.record.PositionDependentRecord; -import org.apache.poi.hslf.record.PositionDependentRecordContainer; -import org.apache.poi.hslf.record.Record; -import org.apache.poi.hslf.record.RecordContainer; -import org.apache.poi.hslf.record.RecordTypes; -import org.apache.poi.hslf.record.Slide; -import org.apache.poi.hslf.record.SlideListWithText; +import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; -import org.apache.poi.hslf.record.SlidePersistAtom; -import org.apache.poi.hslf.record.TxMasterStyleAtom; -import org.apache.poi.hslf.record.UserEditAtom; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; @@ -768,16 +741,14 @@ public final class HSLFSlideShow implements SlideShow createSlideShow(); + + @Test + public void addPicture_File() throws IOException { + SlideShow show = createSlideShow(); + File f = slTests.getFile("clock.jpg"); + + assertEquals(0, show.getPictureData().size()); + PictureData picture = show.addPicture(f, PictureType.JPEG); + assertEquals(1, show.getPictureData().size()); + assertSame(picture, show.getPictureData().get(0)); + + show.close(); + } + + @Test + public void addPicture_Stream() throws IOException { + SlideShow show = createSlideShow(); + InputStream stream = slTests.openResourceAsStream("clock.jpg"); + + assertEquals(0, show.getPictureData().size()); + PictureData picture = show.addPicture(stream, PictureType.JPEG); + assertEquals(1, show.getPictureData().size()); + assertSame(picture, show.getPictureData().get(0)); + + show.close(); + } + + @Test + public void addPicture_ByteArray() throws IOException { + SlideShow show = createSlideShow(); + byte[] data = slTests.readFile("clock.jpg"); + + assertEquals(0, show.getPictureData().size()); + PictureData picture = show.addPicture(data, PictureType.JPEG); + assertEquals(1, show.getPictureData().size()); + assertSame(picture, show.getPictureData().get(0)); + + show.close(); + } + + @Test + public void findPicture() throws IOException { + SlideShow show = createSlideShow(); + byte[] data = slTests.readFile("clock.jpg"); + + assertNull(show.findPictureData(data)); + PictureData picture = show.addPicture(data, PictureType.JPEG); + PictureData found = show.findPictureData(data); + assertNotNull(found); + assertEquals(picture, found); + + show.close(); + } +} -- 2.39.5