You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2015/04/29 20:31:13 UTC

svn commit: r1676810 - /poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java

Author: nick
Date: Wed Apr 29 18:31:12 2015
New Revision: 1676810

URL: http://svn.apache.org/r1676810
Log:
Add a (disabled) unit test showing the incorrect ordering problem of parts - bug #57552

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1676810&r1=1676809&r2=1676810&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Wed Apr 29 18:31:12 2015
@@ -18,6 +18,7 @@ package org.apache.poi.xslf;
 
 import static junit.framework.TestCase.assertEquals;
 import static org.apache.poi.POITestCase.assertContains;
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
@@ -47,7 +48,6 @@ import org.apache.poi.xslf.usermodel.XSL
 import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
 import org.junit.Ignore;
 import org.junit.Test;
-
 public class TestXSLFBugs {
 
     @Test
@@ -259,6 +259,108 @@ public class TestXSLFBugs {
         ss.setSlideOrder(slide, 2);
         validateSlides(ss, true, "Slide1","Slide2","New slide");
     }
+    
+    /**
+     * When working with >9 images, make sure the sorting ensures
+     *  that image10.foo isn't between image1.foo and image2.foo
+     */
+    @Test
+    @Ignore
+    public void test57552() throws Exception {
+        XMLSlideShow ss = new XMLSlideShow();
+        for (String s : new String[]{"Slide1","Slide2"}) {
+            ss.createSlide().createTextBox().setText(s);
+        }
+        
+        // Slide starts with just layout relation
+        XSLFSlide slide = ss.getSlides()[0];
+        assertEquals(0, ss.getAllPictures().size());
+        assertEquals(1, slide.getShapes().length);
+        
+        assertEquals(1, slide.getRelations().size());
+        assertRelationEquals(XSLFRelation.SLIDE_LAYOUT, slide.getRelations().get(0));
+        
+        // Some dummy pictures
+        byte[][] pics = new byte[15][3];
+        for (int i=0; i<pics.length; i++) {
+            for (int j=0; j<pics[i].length; j++) {
+                pics[i][j] = (byte)i;
+            }
+        }
+        
+        // Add a few pictures
+        for (int i=0; i<10; i++) {
+            int idx = ss.addPicture(pics[i], XSLFPictureData.PICTURE_TYPE_JPEG);
+            assertEquals(i, idx);
+            assertEquals(i+1, ss.getAllPictures().size());
+            
+            XSLFPictureShape shape = slide.createPicture(idx);
+            assertNotNull(shape.getPictureData());
+            assertArrayEquals(pics[i], shape.getPictureData().getData());
+            assertEquals(i+2, slide.getShapes().length);
+        }
+        // Re-fetch the pictures and check
+        for (int i=0; i<10; i++) {
+            XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes()[i+1];
+            assertNotNull(shape.getPictureData());
+            assertArrayEquals(pics[i], shape.getPictureData().getData());
+        }
+        
+        // Add past 10
+        for (int i=10; i<15; i++) {
+            int idx = ss.addPicture(pics[i], XSLFPictureData.PICTURE_TYPE_JPEG);
+            assertEquals(i, idx);
+            assertEquals(i+1, ss.getAllPictures().size());
+            
+            XSLFPictureShape shape = slide.createPicture(idx);
+            assertNotNull(shape.getPictureData());
+            assertArrayEquals(pics[i], shape.getPictureData().getData());
+            assertEquals(i+2, slide.getShapes().length);
+        }
+        // Check all pictures
+        for (int i=0; i<15; i++) {
+            XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes()[i+1];
+            assertNotNull(shape.getPictureData());
+            assertArrayEquals(pics[i], shape.getPictureData().getData());
+        }
+        
+        // Add a duplicate, check the right one is picked
+        int idx = ss.addPicture(pics[3], XSLFPictureData.PICTURE_TYPE_JPEG);
+        assertEquals(3, idx);
+        assertEquals(15, ss.getAllPictures().size());
+        
+        XSLFPictureShape shape = slide.createPicture(idx);
+        assertNotNull(shape.getPictureData());
+        assertArrayEquals(pics[3], shape.getPictureData().getData());
+        assertEquals(17, slide.getShapes().length);
+        
+        
+        // Save and re-load
+        ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
+        slide = ss.getSlides()[0];
+        
+        // Check the 15 individual ones added
+        for (int i=0; i<15; i++) {
+            shape = (XSLFPictureShape)slide.getShapes()[i+1];
+            assertNotNull(shape.getPictureData());
+            assertArrayEquals(pics[i], shape.getPictureData().getData());
+        }
+        
+        // Check the duplicate
+        shape = (XSLFPictureShape)slide.getShapes()[16];
+        assertNotNull(shape.getPictureData());
+        assertArrayEquals(pics[3], shape.getPictureData().getData());
+        
+        // Add another duplicate
+        idx = ss.addPicture(pics[5], XSLFPictureData.PICTURE_TYPE_JPEG);
+        assertEquals(5, idx);
+        assertEquals(15, ss.getAllPictures().size());
+        
+        shape = slide.createPicture(idx);
+        assertNotNull(shape.getPictureData());
+        assertArrayEquals(pics[5], shape.getPictureData().getData());
+        assertEquals(18, slide.getShapes().length);
+    }
 
     private void validateSlides(XMLSlideShow ss, boolean saveAndReload, String... slideTexts) {
         if (saveAndReload) {
@@ -272,5 +374,8 @@ public class TestXSLFBugs {
             assertContains(getSlideText(slide), slideTexts[i]);
         }
     }
-
+    private void assertRelationEquals(XSLFRelation expected, POIXMLDocumentPart relation) {
+        assertEquals(expected.getContentType(), relation.getPackagePart().getContentType());
+        assertEquals(expected.getFileName(expected.getFileNameIndex(relation)), relation.getPackagePart().getPartName().getName());
+    }
 }



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