diff options
author | Dominik Stadler <centic@apache.org> | 2015-07-27 08:44:04 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2015-07-27 08:44:04 +0000 |
commit | 7eb27ea492a2ccb9138c882fc444256d9898b150 (patch) | |
tree | 0ae0bbd4aa202553949a86bd9a91135b3235d7ff /src | |
parent | f0acd2152fd2aab9c5b4168ac82ef8b8258e4bb1 (diff) | |
download | poi-7eb27ea492a2ccb9138c882fc444256d9898b150.tar.gz poi-7eb27ea492a2ccb9138c882fc444256d9898b150.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java | 2 | ||||
-rw-r--r-- | src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java | 2 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java | 27 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java | 82 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java (renamed from src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java) | 16 |
5 files changed, 108 insertions, 21 deletions
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<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)); } 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/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/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java index 5001dc8b91..079a22a8db 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java +++ b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java @@ -16,7 +16,7 @@ * limitations under the License. * ==================================================================== */ -package org.apache.poi.xslf.geom; +package org.apache.poi.sl.draw.geom; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -25,7 +25,6 @@ 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; /** @@ -54,4 +53,17 @@ public class TestPresetGeometries { } } } + + // 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; + } } |