You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/07/17 13:25:02 UTC

svn commit: r1753073 - in /poi/trunk/src: java/org/apache/poi/sl/usermodel/ ooxml/java/org/apache/poi/xslf/usermodel/ ooxml/testcases/org/apache/poi/xslf/usermodel/ scratchpad/src/org/apache/poi/hslf/usermodel/ scratchpad/testcases/org/apache/poi/hslf/...

Author: onealj
Date: Sun Jul 17 13:25:02 2016
New Revision: 1753073

URL: http://svn.apache.org/viewvc?rev=1753073&view=rev
Log:
bug 58190: push down XMLSlideShow tests to BaseTestSlideShow, add coverage for HSLFSlideShow
add tests for SlideShow.findPicture and SlideShow.addPicture

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java   (with props)
    poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java

Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java?rev=1753073&r1=1753072&r2=1753073&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java Sun Jul 17 13:25:02 2016
@@ -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

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1753073&r1=1753072&r2=1753073&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Sun Jul 17 13:25:02 2016
@@ -504,8 +504,12 @@ implements SlideShow<XSLFShape,XSLFTextP
 
     /**
      * 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);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java?rev=1753073&r1=1753072&r2=1753073&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java Sun Jul 17 13:25:02 2016
@@ -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();
-   }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java?rev=1753073&r1=1753072&r2=1753073&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java Sun Jul 17 13:25:02 2016
@@ -42,35 +42,8 @@ import org.apache.poi.hslf.exceptions.HS
 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 impleme
 
 	@Override
 	public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
-	    if (format == null || format.nativeId == -1) {
-	        throw new IllegalArgumentException("Unsupported picture format: " + format); 
-	    }
-	    
-	    byte[] uid = HSLFPictureData.getChecksum(data);
-
-		for (HSLFPictureData pd : getPictureData()) {
-		    if (Arrays.equals(pd.getUID(), uid)) {
-		        return pd;
-		    }
+		if (format == null || format.nativeId == -1) {
+			throw new IllegalArgumentException("Unsupported picture format: " + format); 
+		}
+		
+		HSLFPictureData pd = findPictureData(data);
+		if (pd != null) {
+			// identical picture was already added to the SlideShow
+			return pd;
 		}
 		
 		EscherContainerRecord bstore;
@@ -801,6 +772,7 @@ public final class HSLFSlideShow impleme
 		bse.setRecordId(EscherBSERecord.RECORD_ID);
 		bse.setOptions((short) (0x0002 | (format.nativeId << 4)));
 		bse.setSize(pict.getRawData().length + 8);
+		byte[] uid = HSLFPictureData.getChecksum(data);
 		bse.setUid(uid);
 
 		bse.setBlipTypeMacOS((byte) format.nativeId);
@@ -866,6 +838,24 @@ public final class HSLFSlideShow impleme
         }
 		return addPicture(data, format);
 	}
+	
+    /**
+     * 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
+     */
+    @Override
+    public HSLFPictureData findPictureData(byte[] pictureData) {
+        byte[] uid = HSLFPictureData.getChecksum(pictureData);
+
+        for (HSLFPictureData pic : getPictureData()) {
+            if (Arrays.equals(pic.getUID(), uid)) {
+                return pic;
+            }
+        }
+        return null;
+    }
 
 	/**
 	 * Add a font in this presentation

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java?rev=1753073&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java Sun Jul 17 13:25:02 2016
@@ -0,0 +1,35 @@
+/* ====================================================================
+   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.Assert.assertNotNull;
+
+import org.apache.poi.sl.usermodel.BaseTestSlideShow;
+import org.junit.Test;
+
+public class TestHSLFSlideShow extends BaseTestSlideShow {
+    @Override
+    public HSLFSlideShow createSlideShow() {
+        return new HSLFSlideShow();
+    }
+    
+    // make sure junit4 executes this test class
+    @Test
+    public void dummy() {
+        assertNotNull(createSlideShow());
+    }
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java?rev=1753073&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java Sun Jul 17 13:25:02 2016
@@ -0,0 +1,89 @@
+/* ====================================================================
+   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.sl.usermodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
+import org.junit.Test;
+
+public abstract class BaseTestSlideShow {
+    protected static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+    
+    public abstract 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();
+    }
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org