]> source.dussan.org Git - poi.git/commitdiff
Improve error message slightly, add tests to verify things failing in Gump-build...
authorDominik Stadler <centic@apache.org>
Mon, 27 Jul 2015 08:44:04 +0000 (08:44 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 27 Jul 2015 08:44:04 +0000 (08:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1692836 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java [deleted file]
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java
src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java [new file with mode: 0644]

index e2caa084dd726e70a355bcd61f62f195bc453328..676155361a9aae7513edaeb506732adc3cf8cdfb 100644 (file)
@@ -73,7 +73,7 @@ public class PresetGeometries extends LinkedHashMap<String, CustomGeometry> {
             cntElem++;
             
             if(containsKey(name)) {
-                LOG.log(POILogger.WARN, "Duplicate definoition of " + name);
+                LOG.log(POILogger.WARN, "Duplicate definition of " + name);
             }
             put(name, new CustomGeometry(cus));
         }       
index 79fbffe76ac73ae4ba21f5556bf1572143bde97e..bd29667c8cb254782febf0541949c6e0c4077c16 100644 (file)
@@ -577,7 +577,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape {
             String name = spPr.getPrstGeom().getPrst().toString();\r
             geom = dict.get(name);\r
             if(geom == null) {\r
-                throw new IllegalStateException("Unknown shape geometry: " + name);\r
+                throw new IllegalStateException("Unknown shape geometry: " + name + ", available geometries are: " + dict.keySet());\r
             }\r
         } else if (spPr.isSetCustGeom()){\r
             XMLStreamReader staxReader = spPr.getCustGeom().newXMLStreamReader();\r
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java b/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java
deleted file mode 100644 (file)
index 5001dc8..0000000
+++ /dev/null
@@ -1,57 +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.xslf.geom;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Rectangle2D;
-import java.util.Map;
-
-import org.apache.poi.sl.draw.geom.*;
-import org.junit.Test;
-
-/**
- * Date: 10/24/11
- *
- * @author Yegor Kozlov
- */
-public class TestPresetGeometries {
-    @Test
-    public void testRead(){
-
-        Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
-        assertEquals(187, shapes.size());
-
-
-        for(String name : shapes.keySet()) {
-            CustomGeometry geom = shapes.get(name);
-            Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() {
-                public Guide getAdjustValue(String name) {
-                    return null;
-                }
-            });
-            for(Path p : geom){
-                GeneralPath path = p.getPath(ctx);
-                assertNotNull(path);
-            }
-        }
-    }
-}
index 4b083225fd73eb4dec0f54081d395ca6d5d5acbe..7d962fc433789d0a505c676eab9ae5173665de6a 100644 (file)
@@ -22,12 +22,9 @@ package org.apache.poi.xslf.usermodel;
 import java.awt.Dimension;\r
 import java.awt.Graphics2D;\r
 import java.awt.image.BufferedImage;\r
-import java.io.File;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
-import javax.imageio.ImageIO;\r
-\r
 import org.apache.poi.sl.draw.Drawable;\r
 import org.apache.poi.util.JvmBugs;\r
 import org.apache.poi.xslf.XSLFTestDataSamples;\r
@@ -43,16 +40,20 @@ public class TestPPTX2PNG {
     public void render() throws Exception {\r
         String[] testFiles = {"backgrounds.pptx","layouts.pptx", "sample.pptx", "shapes.pptx", "themes.pptx",};\r
         for(String sampleFile : testFiles){\r
-            XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument(sampleFile);\r
-            Dimension pg = pptx.getPageSize();\r
-            int slideNo=1;\r
-            for(XSLFSlide slide : pptx.getSlides()){\r
-                BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB);\r
-                Graphics2D graphics = img.createGraphics();\r
-                fixFonts(graphics);\r
-                slide.draw(graphics);\r
-                // ImageIO.write(img, "PNG", new File("build/tmp/"+sampleFile.replaceFirst(".pptx?", "-")+slideNo+".png"));\r
-                slideNo++;\r
+            try {\r
+                XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument(sampleFile);\r
+                Dimension pg = pptx.getPageSize();\r
+                //int slideNo=1;\r
+                for(XSLFSlide slide : pptx.getSlides()){\r
+                    BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB);\r
+                    Graphics2D graphics = img.createGraphics();\r
+                    fixFonts(graphics);\r
+                    slide.draw(graphics);\r
+                    // ImageIO.write(img, "PNG", new File("build/tmp/"+sampleFile.replaceFirst(".pptx?", "-")+slideNo+".png"));\r
+                    //slideNo++;\r
+                }\r
+            } catch (IllegalStateException e) {\r
+                throw new IllegalStateException("While reading file " + sampleFile, e);\r
             }\r
         }\r
     }\r
index f4cc0371c90bf8dbac68bcbff1a8e98149f256ee..6088eeee71f9f1103fd149b088825acfebbfaed9 100644 (file)
@@ -19,14 +19,25 @@ package org.apache.poi.xslf.usermodel;
 import static org.junit.Assert.*;\r
 \r
 import java.awt.Color;\r
+import java.io.IOException;\r
 import java.util.List;\r
 \r
+import org.apache.poi.sl.draw.geom.TestPresetGeometries;\r
 import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;\r
 import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;\r
 import org.apache.poi.util.Units;\r
 import org.apache.poi.xslf.XSLFTestDataSamples;\r
 import org.junit.Test;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleList;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;\r
 \r
 /**\r
  * @author Yegor Kozlov\r
@@ -34,7 +45,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.*;
 public class TestXSLFSimpleShape {\r
     \r
     @Test\r
-    public void testLineStyles() {\r
+    public void testLineStyles() throws IOException {\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
 \r
@@ -121,10 +132,12 @@ public class TestXSLFSimpleShape {
         assertEquals(null, ln3.getLineDash());\r
         ln3.setLineCap(null);\r
         assertEquals(null, ln3.getLineDash());\r
+        \r
+        ppt.close();\r
     }\r
 \r
     @Test\r
-    public void testFill() {\r
+    public void testFill() throws IOException {\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
 \r
@@ -146,6 +159,7 @@ public class TestXSLFSimpleShape {
         shape.setFillColor(null);\r
         assertNull(shape.getFillColor());\r
         assertFalse(shape.getSpPr().isSetSolidFill());\r
+        ppt.close();\r
     }\r
 \r
     @Test\r
@@ -252,7 +266,7 @@ public class TestXSLFSimpleShape {
 \r
     @SuppressWarnings({ "deprecation", "unused" })\r
     @Test\r
-    public void testShadowEffects(){\r
+    public void testShadowEffects() throws IOException{\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
         CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();\r
@@ -261,5 +275,65 @@ public class TestXSLFSimpleShape {
         for(CTEffectStyleItem ef : lst.getEffectStyleArray()){\r
             CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();\r
         }\r
+        ppt.close();\r
+    }\r
+    \r
+    @Test\r
+    public void testValidGeometry() throws Exception {\r
+        XMLSlideShow ppt = new XMLSlideShow();\r
+        XSLFSlide slide = ppt.createSlide();\r
+\r
+        XSLFSimpleShape shape = slide.createAutoShape();\r
+        CTShapeProperties spPr = shape.getSpPr();\r
+        \r
+        CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();\r
+        prstGeom.setPrst(STShapeType.Enum.forInt(1));\r
+        \r
+        assertNotNull(prstGeom.getPrst());\r
+        assertNotNull(prstGeom.getPrst().toString());\r
+        assertNotNull(spPr.getPrstGeom());\r
+        spPr.setPrstGeom(prstGeom);\r
+        assertNotNull(spPr.getPrstGeom().getPrst());\r
+        assertNotNull(spPr.getPrstGeom().getPrst().toString());\r
+        \r
+        assertNotNull(shape.getGeometry());\r
+        \r
+        ppt.close();\r
+    }\r
+\r
+    \r
+    @Test\r
+    public void testInvalidGeometry() throws Exception {\r
+        XMLSlideShow ppt = new XMLSlideShow();\r
+        XSLFSlide slide = ppt.createSlide();\r
+\r
+        XSLFSimpleShape shape = slide.createAutoShape();\r
+        CTShapeProperties spPr = shape.getSpPr();\r
+        \r
+        CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();\r
+        prstGeom.setPrst(STShapeType.Enum.forInt(1));\r
+        \r
+        assertNotNull(prstGeom.getPrst());\r
+        assertNotNull(prstGeom.getPrst().toString());\r
+        assertNotNull(spPr.getPrstGeom());\r
+        spPr.setPrstGeom(prstGeom);\r
+        assertNotNull(spPr.getPrstGeom().getPrst());\r
+        assertNotNull(spPr.getPrstGeom().getPrst().toString());\r
+        \r
+        try {\r
+            // cause the geometries to be not found\r
+            TestPresetGeometries.clearPreset();\r
+            try {\r
+                shape.getGeometry();\r
+                fail("Should fail without the geometry");\r
+            } catch (IllegalStateException e) {\r
+                assertTrue(e.getMessage(), e.getMessage().contains("line"));\r
+            }\r
+        } finally {\r
+            // reset to not affect other tests\r
+            TestPresetGeometries.resetPreset();\r
+        }\r
+        \r
+        ppt.close();\r
     }\r
 }
\ No newline at end of file
diff --git a/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
new file mode 100644 (file)
index 0000000..079a22a
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  ====================================================================
+ *    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.draw.geom;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
+import java.util.Map;
+
+import org.junit.Test;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class TestPresetGeometries {
+    @Test
+    public void testRead(){
+
+        Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
+        assertEquals(187, shapes.size());
+
+
+        for(String name : shapes.keySet()) {
+            CustomGeometry geom = shapes.get(name);
+            Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() {
+                public Guide getAdjustValue(String name) {
+                    return null;
+                }
+            });
+            for(Path p : geom){
+                GeneralPath path = p.getPath(ctx);
+                assertNotNull(path);
+            }
+        }
+    }
+    
+    // helper methods to adjust list of presets for other tests
+    public static void clearPreset() {
+        // ensure that we are initialized
+        assertNotNull(PresetGeometries.getInstance());
+        
+        // test handling if some presets are not found
+        PresetGeometries._inst.clear();
+    }
+    
+    public static void resetPreset() {
+        PresetGeometries._inst = null;
+    }
+}