From: Dominik Stadler Date: Mon, 27 Jul 2015 08:44:04 +0000 (+0000) Subject: Improve error message slightly, add tests to verify things failing in Gump-build... X-Git-Tag: REL_3_13_FINAL~203 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7eb27ea492a2ccb9138c882fc444256d9898b150;p=poi.git Improve error message slightly, add tests to verify things failing in Gump-build currently git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1692836 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java index e2caa084dd..676155361a 100644 --- a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java +++ b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java @@ -73,7 +73,7 @@ public class PresetGeometries extends LinkedHashMap { 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)); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java index 79fbffe76a..bd29667c8c 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java @@ -577,7 +577,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { String name = spPr.getPrstGeom().getPrst().toString(); geom = dict.get(name); if(geom == null) { - throw new IllegalStateException("Unknown shape geometry: " + name); + throw new IllegalStateException("Unknown shape geometry: " + name + ", available geometries are: " + dict.keySet()); } } else if (spPr.isSetCustGeom()){ XMLStreamReader staxReader = spPr.getCustGeom().newXMLStreamReader(); 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 index 5001dc8b91..0000000000 --- a/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java +++ /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 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); - } - } - } -} diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java index 4b083225fd..7d962fc433 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java @@ -22,12 +22,9 @@ package org.apache.poi.xslf.usermodel; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferedImage; -import java.io.File; import java.util.HashMap; import java.util.Map; -import javax.imageio.ImageIO; - import org.apache.poi.sl.draw.Drawable; import org.apache.poi.util.JvmBugs; import org.apache.poi.xslf.XSLFTestDataSamples; @@ -43,16 +40,20 @@ public class TestPPTX2PNG { public void render() throws Exception { String[] testFiles = {"backgrounds.pptx","layouts.pptx", "sample.pptx", "shapes.pptx", "themes.pptx",}; for(String sampleFile : testFiles){ - XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument(sampleFile); - Dimension pg = pptx.getPageSize(); - int slideNo=1; - for(XSLFSlide slide : pptx.getSlides()){ - BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB); - Graphics2D graphics = img.createGraphics(); - fixFonts(graphics); - slide.draw(graphics); - // ImageIO.write(img, "PNG", new File("build/tmp/"+sampleFile.replaceFirst(".pptx?", "-")+slideNo+".png")); - slideNo++; + try { + XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument(sampleFile); + Dimension pg = pptx.getPageSize(); + //int slideNo=1; + for(XSLFSlide slide : pptx.getSlides()){ + BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = img.createGraphics(); + fixFonts(graphics); + slide.draw(graphics); + // ImageIO.write(img, "PNG", new File("build/tmp/"+sampleFile.replaceFirst(".pptx?", "-")+slideNo+".png")); + //slideNo++; + } + } catch (IllegalStateException e) { + throw new IllegalStateException("While reading file " + sampleFile, e); } } } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java index f4cc0371c9..6088eeee71 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java @@ -19,14 +19,25 @@ package org.apache.poi.xslf.usermodel; import static org.junit.Assert.*; import java.awt.Color; +import java.io.IOException; import java.util.List; +import org.apache.poi.sl.draw.geom.TestPresetGeometries; import org.apache.poi.sl.usermodel.StrokeStyle.LineCap; import org.apache.poi.sl.usermodel.StrokeStyle.LineDash; import org.apache.poi.util.Units; import org.apache.poi.xslf.XSLFTestDataSamples; import org.junit.Test; -import org.openxmlformats.schemas.drawingml.x2006.main.*; +import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem; +import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleList; +import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor; +import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix; +import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap; +import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal; +import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType; /** * @author Yegor Kozlov @@ -34,7 +45,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.*; public class TestXSLFSimpleShape { @Test - public void testLineStyles() { + public void testLineStyles() throws IOException { XMLSlideShow ppt = new XMLSlideShow(); XSLFSlide slide = ppt.createSlide(); @@ -121,10 +132,12 @@ public class TestXSLFSimpleShape { assertEquals(null, ln3.getLineDash()); ln3.setLineCap(null); assertEquals(null, ln3.getLineDash()); + + ppt.close(); } @Test - public void testFill() { + public void testFill() throws IOException { XMLSlideShow ppt = new XMLSlideShow(); XSLFSlide slide = ppt.createSlide(); @@ -146,6 +159,7 @@ public class TestXSLFSimpleShape { shape.setFillColor(null); assertNull(shape.getFillColor()); assertFalse(shape.getSpPr().isSetSolidFill()); + ppt.close(); } @Test @@ -252,7 +266,7 @@ public class TestXSLFSimpleShape { @SuppressWarnings({ "deprecation", "unused" }) @Test - public void testShadowEffects(){ + public void testShadowEffects() throws IOException{ XMLSlideShow ppt = new XMLSlideShow(); XSLFSlide slide = ppt.createSlide(); CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme(); @@ -261,5 +275,65 @@ public class TestXSLFSimpleShape { for(CTEffectStyleItem ef : lst.getEffectStyleArray()){ CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw(); } + ppt.close(); + } + + @Test + public void testValidGeometry() throws Exception { + XMLSlideShow ppt = new XMLSlideShow(); + XSLFSlide slide = ppt.createSlide(); + + XSLFSimpleShape shape = slide.createAutoShape(); + CTShapeProperties spPr = shape.getSpPr(); + + CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance(); + prstGeom.setPrst(STShapeType.Enum.forInt(1)); + + assertNotNull(prstGeom.getPrst()); + assertNotNull(prstGeom.getPrst().toString()); + assertNotNull(spPr.getPrstGeom()); + spPr.setPrstGeom(prstGeom); + assertNotNull(spPr.getPrstGeom().getPrst()); + assertNotNull(spPr.getPrstGeom().getPrst().toString()); + + assertNotNull(shape.getGeometry()); + + ppt.close(); + } + + + @Test + public void testInvalidGeometry() throws Exception { + XMLSlideShow ppt = new XMLSlideShow(); + XSLFSlide slide = ppt.createSlide(); + + XSLFSimpleShape shape = slide.createAutoShape(); + CTShapeProperties spPr = shape.getSpPr(); + + CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance(); + prstGeom.setPrst(STShapeType.Enum.forInt(1)); + + assertNotNull(prstGeom.getPrst()); + assertNotNull(prstGeom.getPrst().toString()); + assertNotNull(spPr.getPrstGeom()); + spPr.setPrstGeom(prstGeom); + assertNotNull(spPr.getPrstGeom().getPrst()); + assertNotNull(spPr.getPrstGeom().getPrst().toString()); + + try { + // cause the geometries to be not found + TestPresetGeometries.clearPreset(); + try { + shape.getGeometry(); + fail("Should fail without the geometry"); + } catch (IllegalStateException e) { + assertTrue(e.getMessage(), e.getMessage().contains("line")); + } + } finally { + // reset to not affect other tests + TestPresetGeometries.resetPreset(); + } + + ppt.close(); } } \ 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 index 0000000000..079a22a8db --- /dev/null +++ b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java @@ -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 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; + } +}