You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/24 23:47:58 UTC
svn commit: r1692593 [8/17] - in /poi: site/src/documentation/content/xdocs/
trunk/ trunk/src/examples/src/org/apache/poi/hslf/examples/
trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/
trunk/src/examples/src/org/apache/poi/xslf/usermodel...
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java Fri Jul 24 21:47:55 2015
@@ -19,15 +19,17 @@
package org.apache.poi.xslf.usermodel;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.POIXMLException;
+import org.apache.poi.sl.draw.DrawFactory;
+import org.apache.poi.sl.draw.DrawTextShape;
+import org.apache.poi.sl.usermodel.Insets2D;
+import org.apache.poi.sl.usermodel.TextShape;
+import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.PropertyFetcher;
@@ -35,29 +37,20 @@ import org.apache.poi.xslf.model.TextBod
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextListStyle;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextVerticalType;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextWrappingType;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
-import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
/**
* Represents a shape that can hold text.
- *
- * @author Yegor Kozlov
*/
@Beta
-public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable<XSLFTextParagraph>{
+public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape<XSLFTextParagraph> {
private final List<XSLFTextParagraph> _paragraphs;
- /**
- * whether the text was broken into lines.
- */
- private boolean _isTextBroken;
-
@SuppressWarnings("deprecation")
/*package*/ XSLFTextShape(XmlObject shape, XSLFSheet sheet) {
super(shape, sheet);
@@ -72,7 +65,7 @@ public abstract class XSLFTextShape exte
}
public Iterator<XSLFTextParagraph> iterator(){
- return _paragraphs.iterator();
+ return getTextParagraphs().iterator();
}
/**
@@ -129,7 +122,7 @@ public abstract class XSLFTextShape exte
* Sets the type of vertical alignment for the text.
*
* @param anchor - the type of alignment.
- * A <code>null</code> values unsets this property.
+ * A {@code null} values unsets this property.
*/
public void setVerticalAlignment(VerticalAlignment anchor){
CTTextBodyProperties bodyPr = getTextBodyPr();
@@ -163,6 +156,40 @@ public abstract class XSLFTextShape exte
}
/**
+ * Sets if the paragraphs are horizontal centered
+ *
+ * @param isCentered true, if the paragraphs are horizontal centered
+ * A {@code null} values unsets this property.
+ *
+ * @see TextShape#isHorizontalCentered()
+ */
+ public void setHorizontalCentered(Boolean isCentered){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if (isCentered == null) {
+ if (bodyPr.isSetAnchorCtr()) bodyPr.unsetAnchorCtr();
+ } else {
+ bodyPr.setAnchorCtr(isCentered);
+ }
+ }
+ }
+
+ @Override
+ public boolean isHorizontalCentered(){
+ PropertyFetcher<Boolean> fetcher = new TextBodyPropertyFetcher<Boolean>(){
+ public boolean fetch(CTTextBodyProperties props){
+ if(props.isSetAnchorCtr()){
+ setValue(props.getAnchorCtr());
+ return true;
+ }
+ return false;
+ }
+ };
+ fetchShapeProperty(fetcher);
+ return fetcher.getValue() == null ? false : fetcher.getValue();
+ }
+
+ /**
*
* @param orientation vertical orientation of the text
*/
@@ -283,7 +310,7 @@ public abstract class XSLFTextShape exte
}
/**
- * Sets the botom margin.
+ * Sets the bottom margin.
* @see #getBottomInset()
*
* @param margin the bottom margin
@@ -338,7 +365,13 @@ public abstract class XSLFTextShape exte
}
}
-
+ @Override
+ public Insets2D getInsets() {
+ Insets2D insets = new Insets2D(getTopInset(), getLeftInset(), getBottomInset(), getRightInset());
+ return insets;
+ }
+
+
/**
* @return whether to wrap words within the bounding rectangle
*/
@@ -408,53 +441,26 @@ public abstract class XSLFTextShape exte
return textBody == null ? null : textBody.getBodyPr();
}
-
protected abstract CTTextBody getTextBody(boolean create);
-
- public Placeholder getTextType(){
- CTPlaceholder ph;
- XmlObject[] obj = getXmlObject().selectPath(
- "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:nvPr/p:ph");
- if(obj.length == 1){
- ph = (CTPlaceholder)obj[0];
- int val = ph.getType().intValue();
- return Placeholder.values()[val - 1];
- }
- else {
- return null;
- }
+ @Override
+ public void setPlaceholder(Placeholder placeholder) {
+ super.setPlaceholder(placeholder);
}
+ public Placeholder getTextType(){
+ CTPlaceholder ph = getCTPlaceholder();
+ if (ph == null) return null;
- /**
- * Specifies that the corresponding shape should be represented by the generating application
- * as a placeholder. When a shape is considered a placeholder by the generating application
- * it can have special properties to alert the user that they may enter content into the shape.
- * Different types of placeholders are allowed and can be specified by using the placeholder
- * type attribute for this element
- *
- * @param placeholder
- */
- public void setPlaceholder(Placeholder placeholder){
- CTShape sh = (CTShape)getXmlObject();
- CTApplicationNonVisualDrawingProps nv = sh.getNvSpPr().getNvPr();
- if(placeholder == null) {
- if(nv.isSetPh()) nv.unsetPh();
- } else {
- nv.addNewPh().setType(STPlaceholderType.Enum.forInt(placeholder.ordinal() + 1));
- }
+ int val = ph.getType().intValue();
+ return Placeholder.values()[val - 1];
}
- /**
- * Compute the cumulative height occupied by the text
- */
+ @Override
public double getTextHeight(){
- // dry-run in a 1x1 image and return the vertical advance
- BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
- Graphics2D graphics = img.createGraphics();
- breakText(graphics);
- return drawParagraphs(graphics, 0, 0);
+ DrawFactory drawFact = DrawFactory.getInstance(null);
+ DrawTextShape<XSLFTextShape> dts = drawFact.getDrawable(this);
+ return dts.getTextHeight();
}
/**
@@ -475,162 +481,57 @@ public abstract class XSLFTextShape exte
return anchor;
}
- /**
- * break the contained text into lines
- */
- private void breakText(Graphics2D graphics){
- if(!_isTextBroken) {
- for(XSLFTextParagraph p : _paragraphs) p.breakText(graphics);
-
- _isTextBroken = true;
- }
- }
@Override
- public void drawContent(Graphics2D graphics) {
- breakText(graphics);
+ void copy(XSLFShape other){
+ super.copy(other);
- RenderableShape rShape = new RenderableShape(this);
- Rectangle2D anchor = rShape.getAnchor(graphics);
- double x = anchor.getX() + getLeftInset();
- double y = anchor.getY();
-
- // remember the initial transform
- AffineTransform tx = graphics.getTransform();
-
- // Transform of text in flipped shapes is special.
- // At this point the flip and rotation transform is already applied
- // (see XSLFShape#applyTransform ), but we need to restore it to avoid painting "upside down".
- // See Bugzilla 54210.
-
- if(getFlipVertical()){
- graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
- graphics.scale(1, -1);
- graphics.translate(-anchor.getX(), -anchor.getY());
-
- // text in vertically flipped shapes is rotated by 180 degrees
- double centerX = anchor.getX() + anchor.getWidth()/2;
- double centerY = anchor.getY() + anchor.getHeight()/2;
- graphics.translate(centerX, centerY);
- graphics.rotate(Math.toRadians(180));
- graphics.translate(-centerX, -centerY);
- }
-
- // Horizontal flipping applies only to shape outline and not to the text in the shape.
- // Applying flip second time restores the original not-flipped transform
- if(getFlipHorizontal()){
- graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
- graphics.scale(-1, 1);
- graphics.translate(-anchor.getX() , -anchor.getY());
- }
-
-
- // first dry-run to calculate the total height of the text
- double textHeight = getTextHeight();
-
- switch (getVerticalAlignment()){
- case TOP:
- y += getTopInset();
- break;
- case BOTTOM:
- y += anchor.getHeight() - textHeight - getBottomInset();
- break;
- default:
- case MIDDLE:
- double delta = anchor.getHeight() - textHeight -
- getTopInset() - getBottomInset();
- y += getTopInset() + delta/2;
- break;
- }
-
- drawParagraphs(graphics, x, y);
-
- // restore the transform
- graphics.setTransform(tx);
- }
-
-
- /**
- * paint the paragraphs starting from top left (x,y)
- *
- * @return the vertical advance, i.e. the cumulative space occupied by the text
- */
- private double drawParagraphs(Graphics2D graphics, double x, double y) {
- double y0 = y;
- for(int i = 0; i < _paragraphs.size(); i++){
- XSLFTextParagraph p = _paragraphs.get(i);
- List<TextFragment> lines = p.getTextLines();
-
- if(i > 0 && lines.size() > 0) {
- // the amount of vertical white space before the paragraph
- double spaceBefore = p.getSpaceBefore();
- if(spaceBefore > 0) {
- // positive value means percentage spacing of the height of the first line, e.g.
- // the higher the first line, the bigger the space before the paragraph
- y += spaceBefore*0.01*lines.get(0).getHeight();
- } else {
- // negative value means the absolute spacing in points
- y += -spaceBefore;
- }
- }
-
- y += p.draw(graphics, x, y);
-
- if(i < _paragraphs.size() - 1) {
- double spaceAfter = p.getSpaceAfter();
- if(spaceAfter > 0) {
- // positive value means percentage spacing of the height of the last line, e.g.
- // the higher the last line, the bigger the space after the paragraph
- y += spaceAfter*0.01*lines.get(lines.size() - 1).getHeight();
- } else {
- // negative value means the absolute spacing in points
- y += -spaceAfter;
- }
- }
+ XSLFTextShape otherTS = (XSLFTextShape)other;
+ CTTextBody otherTB = otherTS.getTextBody(false);
+ CTTextBody thisTB = getTextBody(true);
+ if (otherTB == null) {
+ return;
}
- return y - y0;
- }
-
- @Override
- void copy(XSLFShape sh){
- super.copy(sh);
-
- XSLFTextShape tsh = (XSLFTextShape)sh;
+
+ thisTB.setBodyPr((CTTextBodyProperties)otherTB.getBodyPr().copy());
- boolean srcWordWrap = tsh.getWordWrap();
+ if (thisTB.isSetLstStyle()) thisTB.unsetLstStyle();
+ if (otherTB.isSetLstStyle()) {
+ thisTB.setLstStyle((CTTextListStyle)otherTB.getLstStyle().copy());
+ }
+
+ boolean srcWordWrap = otherTS.getWordWrap();
if(srcWordWrap != getWordWrap()){
setWordWrap(srcWordWrap);
}
- double leftInset = tsh.getLeftInset();
+ double leftInset = otherTS.getLeftInset();
if(leftInset != getLeftInset()) {
setLeftInset(leftInset);
}
- double rightInset = tsh.getRightInset();
+ double rightInset = otherTS.getRightInset();
if(rightInset != getRightInset()) {
setRightInset(rightInset);
}
- double topInset = tsh.getTopInset();
+ double topInset = otherTS.getTopInset();
if(topInset != getTopInset()) {
setTopInset(topInset);
}
- double bottomInset = tsh.getBottomInset();
+ double bottomInset = otherTS.getBottomInset();
if(bottomInset != getBottomInset()) {
setBottomInset(bottomInset);
}
- VerticalAlignment vAlign = tsh.getVerticalAlignment();
+ VerticalAlignment vAlign = otherTS.getVerticalAlignment();
if(vAlign != getVerticalAlignment()) {
setVerticalAlignment(vAlign);
}
- List<XSLFTextParagraph> srcP = tsh.getTextParagraphs();
- List<XSLFTextParagraph> tgtP = getTextParagraphs();
- for(int i = 0; i < srcP.size(); i++){
- XSLFTextParagraph p1 = srcP.get(i);
- XSLFTextParagraph p2 = tgtP.get(i);
- p2.copy(p1);
+ clearText();
+
+ for (XSLFTextParagraph srcP : otherTS.getTextParagraphs()) {
+ XSLFTextParagraph tgtP = addNewTextParagraph();
+ tgtP.copy(srcP);
}
-
}
}
\ No newline at end of file
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java Fri Jul 24 21:47:55 2015
@@ -24,12 +24,14 @@ import org.apache.poi.xslf.usermodel.XML
import org.apache.poi.xslf.usermodel.XSLFSlide;
import javax.imageio.ImageIO;
+
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
+import java.util.List;
/**
* An utulity to convert slides of a .pptx slide show to a PNG image
@@ -79,11 +81,11 @@ public class PPTX2PNG {
int width = (int) (pgsize.width * scale);
int height = (int) (pgsize.height * scale);
- XSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
+ List<XSLFSlide> slide = ppt.getSlides();
+ for (int i = 0; i < slide.size(); i++) {
if (slidenum != -1 && slidenum != (i + 1)) continue;
- String title = slide[i].getTitle();
+ String title = slide.get(i).getTitle();
System.out.println("Rendering slide " + (i + 1) + (title == null ? "" : ": " + title));
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
@@ -101,7 +103,7 @@ public class PPTX2PNG {
graphics.scale(scale, scale);
// draw stuff
- slide[i].draw(graphics);
+ slide.get(i).draw(graphics);
// save the result
int sep = file.lastIndexOf(".");
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=1692593&r1=1692592&r2=1692593&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 Fri Jul 24 21:47:55 2015
@@ -55,8 +55,8 @@ public class TestXSLFBugs {
public void bug51187() throws Exception {
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("51187.pptx");
- assertEquals(1, ss.getSlides().length);
- XSLFSlide slide = ss.getSlides()[0];
+ assertEquals(1, ss.getSlides().size());
+ XSLFSlide slide = ss.getSlides().get(0);
// Check the relations on it
// Note - rId3 is a self reference
@@ -71,7 +71,7 @@ public class TestXSLFBugs {
// Save and re-load
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
- assertEquals(1, ss.getSlides().length);
+ assertEquals(1, ss.getSlides().size());
slidePart = ss._getXSLFSlideShow().getSlidePart(
ss._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
@@ -92,8 +92,8 @@ public class TestXSLFBugs {
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("with_japanese.pptx");
// Should have one slide
- assertEquals(1, ss.getSlides().length);
- XSLFSlide slide = ss.getSlides()[0];
+ assertEquals(1, ss.getSlides().size());
+ XSLFSlide slide = ss.getSlides().get(0);
// Check the relations from this
List<POIXMLDocumentPart> rels = slide.getRelations();
@@ -142,20 +142,20 @@ public class TestXSLFBugs {
XSLFSlide slide;
// Should find 4 slides
- assertEquals(4, ss.getSlides().length);
+ assertEquals(4, ss.getSlides().size());
// Check the text, to see we got them in order
- slide = ss.getSlides()[0];
+ slide = ss.getSlides().get(0);
assertContains("POI cannot read this", getSlideText(slide));
- slide = ss.getSlides()[1];
+ slide = ss.getSlides().get(1);
assertContains("POI can read this", getSlideText(slide));
assertContains("Has a relationship to another slide", getSlideText(slide));
- slide = ss.getSlides()[2];
+ slide = ss.getSlides().get(2);
assertContains("POI can read this", getSlideText(slide));
- slide = ss.getSlides()[3];
+ slide = ss.getSlides().get(3);
assertContains("POI can read this", getSlideText(slide));
}
@@ -202,7 +202,7 @@ public class TestXSLFBugs {
Dimension pgsize = ss.getPageSize();
- XSLFSlide slide = ss.getSlides()[0];
+ XSLFSlide slide = ss.getSlides().get(0);
// render it
double zoom = 1;
@@ -272,9 +272,9 @@ public class TestXSLFBugs {
}
// Slide starts with just layout relation
- XSLFSlide slide = ss.getSlides()[0];
+ XSLFSlide slide = ss.getSlides().get(0);
assertEquals(0, ss.getAllPictures().size());
- assertEquals(1, slide.getShapes().length);
+ assertEquals(1, slide.getShapes().size());
assertEquals(1, slide.getRelations().size());
assertRelationEquals(XSLFRelation.SLIDE_LAYOUT, slide.getRelations().get(0));
@@ -296,11 +296,11 @@ public class TestXSLFBugs {
XSLFPictureShape shape = slide.createPicture(idx);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[i], shape.getPictureData().getData());
- assertEquals(i+2, slide.getShapes().length);
+ assertEquals(i+2, slide.getShapes().size());
}
// Re-fetch the pictures and check
for (int i=0; i<10; i++) {
- XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes()[i+1];
+ XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes().get(i+1);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[i], shape.getPictureData().getData());
}
@@ -314,11 +314,11 @@ public class TestXSLFBugs {
XSLFPictureShape shape = slide.createPicture(idx);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[i], shape.getPictureData().getData());
- assertEquals(i+2, slide.getShapes().length);
+ assertEquals(i+2, slide.getShapes().size());
}
// Check all pictures
for (int i=0; i<15; i++) {
- XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes()[i+1];
+ XSLFPictureShape shape = (XSLFPictureShape)slide.getShapes().get(i+1);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[i], shape.getPictureData().getData());
}
@@ -331,22 +331,22 @@ public class TestXSLFBugs {
XSLFPictureShape shape = slide.createPicture(idx);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[3], shape.getPictureData().getData());
- assertEquals(17, slide.getShapes().length);
+ assertEquals(17, slide.getShapes().size());
// Save and re-load
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
- slide = ss.getSlides()[0];
+ slide = ss.getSlides().get(0);
// Check the 15 individual ones added
for (int i=0; i<15; i++) {
- shape = (XSLFPictureShape)slide.getShapes()[i+1];
+ shape = (XSLFPictureShape)slide.getShapes().get(i+1);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[i], shape.getPictureData().getData());
}
// Check the duplicate
- shape = (XSLFPictureShape)slide.getShapes()[16];
+ shape = (XSLFPictureShape)slide.getShapes().get(16);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[3], shape.getPictureData().getData());
@@ -358,7 +358,7 @@ public class TestXSLFBugs {
shape = slide.createPicture(idx);
assertNotNull(shape.getPictureData());
assertArrayEquals(pics[5], shape.getPictureData().getData());
- assertEquals(18, slide.getShapes().length);
+ assertEquals(18, slide.getShapes().size());
}
private void validateSlides(XMLSlideShow ss, boolean saveAndReload, String... slideTexts) {
@@ -366,10 +366,10 @@ public class TestXSLFBugs {
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
}
- assertEquals(slideTexts.length, ss.getSlides().length);
+ assertEquals(slideTexts.length, ss.getSlides().size());
for (int i = 0; i < slideTexts.length; i++) {
- XSLFSlide slide = ss.getSlides()[i];
+ XSLFSlide slide = ss.getSlides().get(i);
assertContains(getSlideText(slide), slideTexts[i]);
}
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestFormulaParser.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestFormulaParser.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestFormulaParser.java Fri Jul 24 21:47:55 2015
@@ -18,19 +18,19 @@
*/
package org.apache.poi.xslf.geom;
-import junit.framework.TestCase;
-import org.apache.poi.xslf.model.geom.Context;
-import org.apache.poi.xslf.model.geom.CustomGeometry;
-import org.apache.poi.xslf.model.geom.Formula;
-import org.apache.poi.xslf.model.geom.Guide;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.poi.sl.draw.binding.CTCustomGeometry2D;
+import org.apache.poi.sl.draw.geom.*;
+import org.junit.Test;
/**
* Date: 10/24/11
*
* @author Yegor Kozlov
*/
-public class TestFormulaParser extends TestCase {
+public class TestFormulaParser {
+ @Test
public void testParse(){
Formula[] ops = {
@@ -44,18 +44,18 @@ public class TestFormulaParser extends T
new Guide("a5", "abs -2"),
};
- CustomGeometry geom = new CustomGeometry(CTCustomGeometry2D.Factory.newInstance());
+ CustomGeometry geom = new CustomGeometry(new CTCustomGeometry2D());
Context ctx = new Context(geom, null, null);
for(Formula fmla : ops) {
ctx.evaluate(fmla);
}
- assertEquals(100.0, ctx.getValue("adj1"));
- assertEquals(200.0, ctx.getValue("adj2"));
- assertEquals(1.0, ctx.getValue("a1"));
- assertEquals(101.0, ctx.getValue("a2"));
- assertEquals(1.5, ctx.getValue("a3"));
- assertEquals(200.0, ctx.getValue("a4"));
- assertEquals(2.0, ctx.getValue("a5"));
+ assertEquals(100.0, ctx.getValue("adj1"), 0.0);
+ assertEquals(200.0, ctx.getValue("adj2"), 0.0);
+ assertEquals(1.0, ctx.getValue("a1"), 0.0);
+ assertEquals(101.0, ctx.getValue("a2"), 0.0);
+ assertEquals(1.5, ctx.getValue("a3"), 0.0);
+ assertEquals(200.0, ctx.getValue("a4"), 0.0);
+ assertEquals(2.0, ctx.getValue("a5"), 0.0);
}
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java Fri Jul 24 21:47:55 2015
@@ -18,24 +18,23 @@
*/
package org.apache.poi.xslf.geom;
-import junit.framework.TestCase;
-import org.apache.poi.xslf.model.geom.Context;
-import org.apache.poi.xslf.model.geom.CustomGeometry;
-import org.apache.poi.xslf.model.geom.Guide;
-import org.apache.poi.xslf.model.geom.IAdjustableShape;
-import org.apache.poi.xslf.model.geom.Path;
-import org.apache.poi.xslf.model.geom.PresetGeometries;
+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 extends TestCase {
+public class TestPresetGeometries {
+ @Test
public void testRead(){
Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java Fri Jul 24 21:47:55 2015
@@ -22,10 +22,13 @@ 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 org.apache.poi.sl.usermodel.TextPainter;
+import javax.imageio.ImageIO;
+
+import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.util.JvmBugs;
import org.apache.poi.xslf.XSLFTestDataSamples;
import org.junit.Test;
@@ -37,18 +40,19 @@ import org.junit.Test;
*/
public class TestPPTX2PNG {
@Test
- public void render(){
- String[] testFiles = {"layouts.pptx", "sample.pptx", "shapes.pptx",
- "themes.pptx", "backgrounds.pptx"};
+ 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_RGB);
+ 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++;
}
}
}
@@ -56,10 +60,10 @@ public class TestPPTX2PNG {
@SuppressWarnings("unchecked")
private void fixFonts(Graphics2D graphics) {
if (!JvmBugs.hasLineBreakMeasurerBug()) return;
- Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(TextPainter.KEY_FONTMAP);
+ Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(Drawable.FONT_MAP);
if (fontMap == null) fontMap = new HashMap<String,String>();
fontMap.put("Calibri", "Lucida Sans");
fontMap.put("Cambria", "Lucida Bright");
- graphics.setRenderingHint(TextPainter.KEY_FONTMAP, fontMap);
+ graphics.setRenderingHint(Drawable.FONT_MAP, fontMap);
}
}
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=1692593&r1=1692592&r2=1692593&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 Fri Jul 24 21:47:55 2015
@@ -16,23 +16,25 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
+import org.junit.Before;
+import org.junit.Test;
+import org.openxmlformats.schemas.presentationml.x2006.main.*;
-public class TestXMLSlideShow extends TestCase {
+public class TestXMLSlideShow {
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
private OPCPackage pack;
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
}
+ @Test
public void testContainsMainContentType() throws Exception {
boolean found = false;
for(PackagePart part : pack.getParts()) {
@@ -43,6 +45,7 @@ public class TestXMLSlideShow extends Te
assertTrue(found);
}
+ @Test
public void testOpen() throws Exception {
XMLSlideShow xml;
@@ -52,22 +55,20 @@ public class TestXMLSlideShow extends Te
assertNotNull(xml.getCTPresentation());
// Check it has some slides
- assertNotNull(xml.getSlides().length);
- assertTrue(xml.getSlides().length > 0);
-
- assertNotNull(xml.getSlideMasters().length);
- assertTrue(xml.getSlideMasters().length > 0);
+ assertFalse(xml.getSlides().isEmpty());
+ assertFalse(xml.getSlideMasters().isEmpty());
}
+ @Test
@SuppressWarnings("deprecation")
public void testSlideBasics() throws Exception {
XMLSlideShow xml = new XMLSlideShow(pack);
// Should have 1 master
- assertEquals(1, xml.getSlideMasters().length);
+ assertEquals(1, xml.getSlideMasters().size());
// Should have two sheets
- assertEquals(2, xml.getSlides().length);
+ assertEquals(2, xml.getSlides().size());
// Check they're as expected
CTSlideIdListEntry[] slides = xml.getCTPresentation().getSldIdLst().getSldIdArray();
@@ -78,19 +79,19 @@ public class TestXMLSlideShow extends Te
assertEquals("rId3", slides[1].getId2());
// Now get those objects
- assertNotNull(xml.getSlides()[0]);
- assertNotNull(xml.getSlides()[1]);
+ assertNotNull(xml.getSlides().get(0));
+ assertNotNull(xml.getSlides().get(1));
// And check they have notes as expected
- assertNotNull(xml.getSlides()[0].getNotes());
- assertNotNull(xml.getSlides()[1].getNotes());
+ assertNotNull(xml.getSlides().get(0).getNotes());
+ assertNotNull(xml.getSlides().get(1).getNotes());
// Next up look for the slide master
CTSlideMasterIdListEntry[] masters = xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdArray();
assertEquals(2147483648l, masters[0].getId());
assertEquals("rId1", masters[0].getId2());
- assertNotNull(xml.getSlideMasters()[0]);
+ assertNotNull(xml.getSlideMasters().get(0));
// Finally look for the notes master
CTNotesMasterIdListEntry notesMaster =
@@ -100,6 +101,7 @@ public class TestXMLSlideShow extends Te
assertNotNull(xml.getNotesMaster());
}
+ @Test
public void testMetadataBasics() throws Exception {
XMLSlideShow xml = new XMLSlideShow(pack);
@@ -114,6 +116,7 @@ public class TestXMLSlideShow extends Te
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
}
+ @Test
public void testComments() throws Exception {
// Default sample file has none
XMLSlideShow xml = new XMLSlideShow(pack);
@@ -134,8 +137,9 @@ public class TestXMLSlideShow extends Te
assertEquals("XPVMWARE01", xmlComments.getCommentAuthors().getAuthorById(0).getName());
// First two slides have comments
- for (int i=0; i<xmlComments.getSlides().length; i++) {
- XSLFSlide slide = xmlComments.getSlides()[i];
+ int i = -1;
+ for (XSLFSlide slide : xmlComments.getSlides()) {
+ i++;
if(i == 0) {
assertNotNull(slide.getComments());
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java Fri Jul 24 21:47:55 2015
@@ -16,15 +16,22 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
+import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
+import org.apache.poi.sl.usermodel.TextShape.TextAutofit;
+import org.apache.poi.sl.usermodel.TextShape.TextDirection;
import org.apache.poi.util.Units;
+import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
/**
* @author Yegor Kozlov
*/
-public class TestXSLFAutoShape extends TestCase {
+public class TestXSLFAutoShape {
+ @Test
public void testTextBodyProperies() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
@@ -33,38 +40,38 @@ public class TestXSLFAutoShape extends T
shape.addNewTextParagraph().addNewTextRun().setText("POI");
// default margins from slide master
- assertEquals(3.6, shape.getBottomInset());
- assertEquals(3.6, shape.getTopInset());
- assertEquals(7.2, shape.getLeftInset());
- assertEquals(7.2, shape.getRightInset());
+ assertEquals(3.6, shape.getBottomInset(), 0);
+ assertEquals(3.6, shape.getTopInset(), 0);
+ assertEquals(7.2, shape.getLeftInset(), 0);
+ assertEquals(7.2, shape.getRightInset(), 0);
shape.setBottomInset(1.0);
- assertEquals(1.0, shape.getBottomInset());
+ assertEquals(1.0, shape.getBottomInset(), 0);
shape.setTopInset(2.0);
- assertEquals(2.0, shape.getTopInset());
+ assertEquals(2.0, shape.getTopInset(), 0);
shape.setLeftInset(3.0);
- assertEquals(3.0, shape.getLeftInset());
+ assertEquals(3.0, shape.getLeftInset(), 0);
shape.setRightInset(4.0);
- assertEquals(4.0, shape.getRightInset());
+ assertEquals(4.0, shape.getRightInset(), 0);
shape.setBottomInset(0.0);
- assertEquals(0.0, shape.getBottomInset());
+ assertEquals(0.0, shape.getBottomInset(), 0);
shape.setTopInset(0.0);
- assertEquals(0.0, shape.getTopInset());
+ assertEquals(0.0, shape.getTopInset(), 0);
shape.setLeftInset(0.0);
- assertEquals(0.0, shape.getLeftInset());
+ assertEquals(0.0, shape.getLeftInset(), 0);
shape.setRightInset(0.0);
- assertEquals(0.0, shape.getRightInset());
+ assertEquals(0.0, shape.getRightInset(), 0);
// unset to defauls
shape.setBottomInset(-1);
- assertEquals(3.6, shape.getBottomInset());
+ assertEquals(3.6, shape.getBottomInset(), 0);
shape.setTopInset(-1);
- assertEquals(3.6, shape.getTopInset());
+ assertEquals(3.6, shape.getTopInset(), 0);
shape.setLeftInset(-1);
- assertEquals(7.2, shape.getLeftInset());
+ assertEquals(7.2, shape.getLeftInset(), 0);
shape.setRightInset(-1);
- assertEquals(7.2, shape.getRightInset());
+ assertEquals(7.2, shape.getRightInset(), 0);
// shape
assertTrue(shape.getWordWrap());
@@ -97,88 +104,89 @@ public class TestXSLFAutoShape extends T
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
}
+ @Test
public void testTextParagraph() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
- assertEquals(0, slide.getShapes().length);
+ assertTrue(slide.getShapes().isEmpty());
XSLFAutoShape shape = slide.createAutoShape();
assertEquals(0, shape.getTextParagraphs().size());
XSLFTextParagraph p = shape.addNewTextParagraph();
assertEquals(1, shape.getTextParagraphs().size());
- assertEquals(0., p.getIndent());
- assertEquals(0., p.getLeftMargin());
- assertEquals(100., p.getLineSpacing());
- assertEquals(0., p.getSpaceAfter());
- assertEquals(0., p.getSpaceBefore());
- assertEquals(0, p.getLevel());
+ assertNull(p.getIndent());
+ assertEquals(0, p.getLeftMargin(), 0);
+ assertNull(p.getLineSpacing());
+ assertNull(p.getSpaceAfter());
+ assertNull(p.getSpaceBefore());
+ assertEquals(0, p.getIndentLevel());
p.setIndent(2.0);
- assertEquals(2.0, p.getIndent());
+ assertEquals(2.0, p.getIndent(), 0);
assertTrue(p.getXmlObject().getPPr().isSetIndent());
- p.setIndent(-1);
- assertEquals(0.0, p.getIndent());
+ p.setIndent(null);
+ assertNull(p.getIndent());
assertFalse(p.getXmlObject().getPPr().isSetIndent());
p.setIndent(10.0);
- assertEquals(10., p.getIndent());
+ assertEquals(10., p.getIndent(), 0);
assertTrue(p.getXmlObject().getPPr().isSetIndent());
assertFalse(p.getXmlObject().getPPr().isSetLvl());
- p.setLevel(1);
- assertEquals(1, p.getLevel());
+ p.setIndentLevel(1);
+ assertEquals(1, p.getIndentLevel());
assertTrue(p.getXmlObject().getPPr().isSetLvl());
- p.setLevel(2);
- assertEquals(2, p.getLevel());
+ p.setIndentLevel(2);
+ assertEquals(2, p.getIndentLevel());
p.setLeftMargin(2.0);
- assertEquals(2.0, p.getLeftMargin());
+ assertEquals(2.0, p.getLeftMargin(), 0);
assertTrue(p.getXmlObject().getPPr().isSetMarL());
p.setLeftMargin(10.0);
- assertEquals(10., p.getLeftMargin());
+ assertEquals(10., p.getLeftMargin(), 0);
assertEquals(Units.toEMU(10), p.getXmlObject().getPPr().getMarL());
assertFalse(p.getXmlObject().getPPr().isSetSpcAft());
- p.setSpaceAfter(200);
+ p.setSpaceAfter(200d);
assertEquals(200000, p.getXmlObject().getPPr().getSpcAft().getSpcPct().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPts());
- p.setSpaceAfter(100);
+ p.setSpaceAfter(100d);
assertEquals(100000, p.getXmlObject().getPPr().getSpcAft().getSpcPct().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPts());
- p.setSpaceAfter(-20);
+ p.setSpaceAfter(-20d);
assertEquals(2000, p.getXmlObject().getPPr().getSpcAft().getSpcPts().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPct());
- p.setSpaceAfter(-10);
+ p.setSpaceAfter(-10d);
assertEquals(1000, p.getXmlObject().getPPr().getSpcAft().getSpcPts().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPct());
assertFalse(p.getXmlObject().getPPr().isSetSpcBef());
- p.setSpaceBefore(200);
+ p.setSpaceBefore(200d);
assertEquals(200000, p.getXmlObject().getPPr().getSpcBef().getSpcPct().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPts());
- p.setSpaceBefore(100);
+ p.setSpaceBefore(100d);
assertEquals(100000, p.getXmlObject().getPPr().getSpcBef().getSpcPct().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPts());
- p.setSpaceBefore(-20);
+ p.setSpaceBefore(-20d);
assertEquals(2000, p.getXmlObject().getPPr().getSpcBef().getSpcPts().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPct());
- p.setSpaceBefore(-10);
+ p.setSpaceBefore(-10d);
assertEquals(1000, p.getXmlObject().getPPr().getSpcBef().getSpcPts().getVal());
assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPct());
assertFalse(p.getXmlObject().getPPr().isSetLnSpc());
- p.setLineSpacing(200);
+ p.setLineSpacing(200d);
assertEquals(200000, p.getXmlObject().getPPr().getLnSpc().getSpcPct().getVal());
assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPts());
- p.setLineSpacing(100);
+ p.setLineSpacing(100d);
assertEquals(100000, p.getXmlObject().getPPr().getLnSpc().getSpcPct().getVal());
assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPts());
- p.setLineSpacing(-20);
+ p.setLineSpacing(-20d);
assertEquals(2000, p.getXmlObject().getPPr().getLnSpc().getSpcPts().getVal());
assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPct());
- p.setLineSpacing(-10);
+ p.setLineSpacing(-10d);
assertEquals(1000, p.getXmlObject().getPPr().getLnSpc().getSpcPts().getVal());
assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPct());
@@ -196,6 +204,7 @@ public class TestXSLFAutoShape extends T
assertFalse(p.getXmlObject().getPPr().isSetAlgn());
}
+ @Test
public void testTextRun() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
@@ -209,14 +218,14 @@ public class TestXSLFAutoShape extends T
assertEquals(1, p.getTextRuns().size());
assertSame(r, p.getTextRuns().get(0));
- assertEquals(18.0, r.getFontSize()); // default font size for text boxes
+ assertEquals(18.0, r.getFontSize(), 0); // default font size for text boxes
assertFalse(r.getXmlObject().getRPr().isSetSz());
r.setFontSize(10.0);
assertTrue(r.getXmlObject().isSetRPr());
assertEquals(1000, r.getXmlObject().getRPr().getSz());
r.setFontSize(12.5);
assertEquals(1250, r.getXmlObject().getRPr().getSz());
- r.setFontSize(-1);
+ r.setFontSize(null);
assertFalse(r.getXmlObject().getRPr().isSetSz());
assertFalse(r.getXmlObject().getRPr().isSetLatin());
@@ -251,31 +260,33 @@ public class TestXSLFAutoShape extends T
assertTrue(r.isItalic());
assertEquals(true, r.getXmlObject().getRPr().getI());
- assertFalse(r.isUnderline());
+ assertFalse(r.isUnderlined());
assertFalse(r.getXmlObject().getRPr().isSetU());
r.setUnderline(true);
- assertTrue(r.isUnderline());
+ assertTrue(r.isUnderlined());
assertEquals(STTextUnderlineType.SNG, r.getXmlObject().getRPr().getU());
r.setText("Apache");
- assertEquals("Apache", r.getText());
+ assertEquals("Apache", r.getRawText());
r.setText("POI");
- assertEquals("POI", r.getText());
+ assertEquals("POI", r.getRawText());
r.setText(null);
- assertNull(r.getText());
+ assertNull(r.getRawText());
}
+ @Test
public void testShapeType() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
XSLFAutoShape shape = slide.createAutoShape();
- assertEquals(XSLFShapeType.RECT, shape.getShapeType());
+ assertEquals(ShapeType.RECT, shape.getShapeType());
- shape.setShapeType(XSLFShapeType.TRIANGLE);
- assertEquals(XSLFShapeType.TRIANGLE, shape.getShapeType());
+ shape.setShapeType(ShapeType.TRIANGLE);
+ assertEquals(ShapeType.TRIANGLE, shape.getShapeType());
- for(XSLFShapeType tp : XSLFShapeType.values()) {
+ for(ShapeType tp : ShapeType.values()) {
+ if (tp.ooxmlId == -1 || tp == ShapeType.SEAL) continue;
shape.setShapeType(tp);
assertEquals(tp, shape.getShapeType());
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java Fri Jul 24 21:47:55 2015
@@ -46,7 +46,7 @@ public class TestXSLFChart extends TestC
String chartTitle = "Apache POI"; // first line is chart title
XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("pie-chart.pptx");
- XSLFSlide slide = pptx.getSlides()[0];
+ XSLFSlide slide = pptx.getSlides().get(0);
// find chart in the slide
XSLFChart chart = null;
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java Fri Jul 24 21:47:55 2015
@@ -16,108 +16,117 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.awt.Color;
+import java.awt.Rectangle;
+
+import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;
+import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
+import org.apache.poi.sl.usermodel.*;
+import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.main.*;
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
-import java.awt.*;
-
/**
* @author Yegor Kozlov
*/
-public class TestXSLFConnectorShape extends TestCase {
+public class TestXSLFConnectorShape {
+ @Test
public void testLineDecorations() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
XSLFConnectorShape shape = slide.createConnector();
- assertEquals(1, slide.getShapes().length);
+ assertEquals(1, slide.getShapes().size());
assertFalse(shape.getSpPr().getLn().isSetHeadEnd());
assertFalse(shape.getSpPr().getLn().isSetTailEnd());
// line decorations
- assertEquals(LineDecoration.NONE, shape.getLineHeadDecoration());
- assertEquals(LineDecoration.NONE, shape.getLineTailDecoration());
+ assertEquals(DecorationShape.NONE, shape.getLineHeadDecoration());
+ assertEquals(DecorationShape.NONE, shape.getLineTailDecoration());
shape.setLineHeadDecoration(null);
shape.setLineTailDecoration(null);
- assertEquals(LineDecoration.NONE, shape.getLineHeadDecoration());
- assertEquals(LineDecoration.NONE, shape.getLineTailDecoration());
+ assertEquals(DecorationShape.NONE, shape.getLineHeadDecoration());
+ assertEquals(DecorationShape.NONE, shape.getLineTailDecoration());
assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetType());
assertFalse(shape.getSpPr().getLn().getTailEnd().isSetType());
- shape.setLineHeadDecoration(LineDecoration.ARROW);
- shape.setLineTailDecoration(LineDecoration.DIAMOND);
- assertEquals(LineDecoration.ARROW, shape.getLineHeadDecoration());
- assertEquals(LineDecoration.DIAMOND, shape.getLineTailDecoration());
+ shape.setLineHeadDecoration(DecorationShape.ARROW);
+ shape.setLineTailDecoration(DecorationShape.DIAMOND);
+ assertEquals(DecorationShape.ARROW, shape.getLineHeadDecoration());
+ assertEquals(DecorationShape.DIAMOND, shape.getLineTailDecoration());
assertEquals(STLineEndType.ARROW, shape.getSpPr().getLn().getHeadEnd().getType());
assertEquals(STLineEndType.DIAMOND, shape.getSpPr().getLn().getTailEnd().getType());
- shape.setLineHeadDecoration(LineDecoration.DIAMOND);
- shape.setLineTailDecoration(LineDecoration.ARROW);
- assertEquals(LineDecoration.DIAMOND, shape.getLineHeadDecoration());
- assertEquals(LineDecoration.ARROW, shape.getLineTailDecoration());
+ shape.setLineHeadDecoration(DecorationShape.DIAMOND);
+ shape.setLineTailDecoration(DecorationShape.ARROW);
+ assertEquals(DecorationShape.DIAMOND, shape.getLineHeadDecoration());
+ assertEquals(DecorationShape.ARROW, shape.getLineTailDecoration());
assertEquals(STLineEndType.DIAMOND, shape.getSpPr().getLn().getHeadEnd().getType());
assertEquals(STLineEndType.ARROW, shape.getSpPr().getLn().getTailEnd().getType());
// line end width
- assertEquals(LineEndWidth.MEDIUM, shape.getLineHeadWidth());
- assertEquals(LineEndWidth.MEDIUM, shape.getLineTailWidth());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineHeadWidth());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineTailWidth());
shape.setLineHeadWidth(null);
shape.setLineHeadWidth(null);
- assertEquals(LineEndWidth.MEDIUM, shape.getLineHeadWidth());
- assertEquals(LineEndWidth.MEDIUM, shape.getLineTailWidth());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineHeadWidth());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineTailWidth());
assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetW());
assertFalse(shape.getSpPr().getLn().getTailEnd().isSetW());
- shape.setLineHeadWidth(LineEndWidth.LARGE);
- shape.setLineTailWidth(LineEndWidth.MEDIUM);
- assertEquals(LineEndWidth.LARGE, shape.getLineHeadWidth());
- assertEquals(LineEndWidth.MEDIUM, shape.getLineTailWidth());
+ shape.setLineHeadWidth(DecorationSize.LARGE);
+ shape.setLineTailWidth(DecorationSize.MEDIUM);
+ assertEquals(DecorationSize.LARGE, shape.getLineHeadWidth());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineTailWidth());
assertEquals(STLineEndWidth.LG, shape.getSpPr().getLn().getHeadEnd().getW());
assertEquals(STLineEndWidth.MED, shape.getSpPr().getLn().getTailEnd().getW());
- shape.setLineHeadWidth(LineEndWidth.MEDIUM);
- shape.setLineTailWidth(LineEndWidth.LARGE);
- assertEquals(LineEndWidth.MEDIUM, shape.getLineHeadWidth());
- assertEquals(LineEndWidth.LARGE, shape.getLineTailWidth());
+ shape.setLineHeadWidth(DecorationSize.MEDIUM);
+ shape.setLineTailWidth(DecorationSize.LARGE);
+ assertEquals(DecorationSize.MEDIUM, shape.getLineHeadWidth());
+ assertEquals(DecorationSize.LARGE, shape.getLineTailWidth());
assertEquals(STLineEndWidth.MED, shape.getSpPr().getLn().getHeadEnd().getW());
assertEquals(STLineEndWidth.LG, shape.getSpPr().getLn().getTailEnd().getW());
// line end length
- assertEquals(LineEndLength.MEDIUM, shape.getLineHeadLength());
- assertEquals(LineEndLength.MEDIUM, shape.getLineTailLength());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineHeadLength());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineTailLength());
shape.setLineHeadLength(null);
shape.setLineTailLength(null);
- assertEquals(LineEndLength.MEDIUM, shape.getLineHeadLength());
- assertEquals(LineEndLength.MEDIUM, shape.getLineTailLength());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineHeadLength());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineTailLength());
assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetLen());
assertFalse(shape.getSpPr().getLn().getTailEnd().isSetLen());
- shape.setLineHeadLength(LineEndLength.LARGE);
- shape.setLineTailLength(LineEndLength.MEDIUM);
- assertEquals(LineEndLength.LARGE, shape.getLineHeadLength());
- assertEquals(LineEndLength.MEDIUM, shape.getLineTailLength());
+ shape.setLineHeadLength(DecorationSize.LARGE);
+ shape.setLineTailLength(DecorationSize.MEDIUM);
+ assertEquals(DecorationSize.LARGE, shape.getLineHeadLength());
+ assertEquals(DecorationSize.MEDIUM, shape.getLineTailLength());
assertEquals(STLineEndLength.LG, shape.getSpPr().getLn().getHeadEnd().getLen());
assertEquals(STLineEndLength.MED, shape.getSpPr().getLn().getTailEnd().getLen());
- shape.setLineHeadLength(LineEndLength.MEDIUM);
- shape.setLineTailLength(LineEndLength.LARGE);
- assertEquals(LineEndLength.MEDIUM, shape.getLineHeadLength());
- assertEquals(LineEndLength.LARGE, shape.getLineTailLength());
+ shape.setLineHeadLength(DecorationSize.MEDIUM);
+ shape.setLineTailLength(DecorationSize.LARGE);
+ assertEquals(DecorationSize.MEDIUM, shape.getLineHeadLength());
+ assertEquals(DecorationSize.LARGE, shape.getLineTailLength());
assertEquals(STLineEndLength.MED, shape.getSpPr().getLn().getHeadEnd().getLen());
assertEquals(STLineEndLength.LG, shape.getSpPr().getLn().getTailEnd().getLen());
}
+ @Test
public void testAddConnector(){
XMLSlideShow pptx = new XMLSlideShow();
XSLFSlide slide = pptx.createSlide();
XSLFAutoShape rect1 = slide.createAutoShape();
- rect1.setShapeType(XSLFShapeType.RECT);
+ rect1.setShapeType(ShapeType.RECT);
rect1.setAnchor(new Rectangle(100, 100, 100, 100));
rect1.setFillColor(Color.blue);
XSLFAutoShape rect2 = slide.createAutoShape();
- rect2.setShapeType(XSLFShapeType.RECT);
+ rect2.setShapeType(ShapeType.RECT);
rect2.setAnchor(new Rectangle(300, 300, 100, 100));
rect2.setFillColor(Color.red);
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java Fri Jul 24 21:47:55 2015
@@ -16,17 +16,20 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
+import org.junit.Test;
+
/**
* @author Yegor Kozlov
*/
-public class TestXSLFFreeformShape extends TestCase {
+public class TestXSLFFreeformShape {
+ @Test
public void testSetPath() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java Fri Jul 24 21:47:55 2015
@@ -16,16 +16,19 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
import java.awt.Dimension;
import java.awt.geom.Rectangle2D;
+import org.junit.Test;
+
/**
* @author Yegor Kozlov
*/
-public class TestXSLFGroupShape extends TestCase {
+public class TestXSLFGroupShape {
+ @Test
public void testCreateShapes() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
@@ -33,7 +36,7 @@ public class TestXSLFGroupShape extends
ppt.setPageSize(new Dimension(792, 612));
XSLFGroupShape group = slide.createGroup();
- assertEquals(1, slide.getShapes().length);
+ assertEquals(1, slide.getShapes().size());
Rectangle2D interior = new Rectangle2D.Double(-10, -10, 20, 20);
group.setInteriorAnchor(interior);
@@ -43,45 +46,46 @@ public class TestXSLFGroupShape extends
group.setAnchor(anchor);
assertEquals(anchor, group.getAnchor());
- assertEquals(0, group.getShapes().length);
+ assertTrue(group.getShapes().isEmpty());
XSLFTextBox shape1 = group.createTextBox();
- assertEquals(1, group.getShapes().length);
- assertSame(shape1, group.getShapes()[0]);
+ assertEquals(1, group.getShapes().size());
+ assertSame(shape1, group.getShapes().get(0));
assertEquals(3, shape1.getShapeId());
XSLFAutoShape shape2 = group.createAutoShape();
- assertEquals(2, group.getShapes().length);
- assertSame(shape1, group.getShapes()[0]);
- assertSame(shape2, group.getShapes()[1]);
+ assertEquals(2, group.getShapes().size());
+ assertSame(shape1, group.getShapes().get(0));
+ assertSame(shape2, group.getShapes().get(1));
assertEquals(4, shape2.getShapeId());
XSLFConnectorShape shape3 = group.createConnector();
- assertEquals(3, group.getShapes().length);
- assertSame(shape3, group.getShapes()[2]);
+ assertEquals(3, group.getShapes().size());
+ assertSame(shape3, group.getShapes().get(2));
assertEquals(5, shape3.getShapeId());
XSLFGroupShape shape4 = group.createGroup();
- assertEquals(4, group.getShapes().length);
- assertSame(shape4, group.getShapes()[3]);
+ assertEquals(4, group.getShapes().size());
+ assertSame(shape4, group.getShapes().get(3));
assertEquals(6, shape4.getShapeId());
group.removeShape(shape2);
- assertEquals(3, group.getShapes().length);
- assertSame(shape1, group.getShapes()[0]);
- assertSame(shape3, group.getShapes()[1]);
- assertSame(shape4, group.getShapes()[2]);
+ assertEquals(3, group.getShapes().size());
+ assertSame(shape1, group.getShapes().get(0));
+ assertSame(shape3, group.getShapes().get(1));
+ assertSame(shape4, group.getShapes().get(2));
group.removeShape(shape3);
- assertEquals(2, group.getShapes().length);
- assertSame(shape1, group.getShapes()[0]);
- assertSame(shape4, group.getShapes()[1]);
+ assertEquals(2, group.getShapes().size());
+ assertSame(shape1, group.getShapes().get(0));
+ assertSame(shape4, group.getShapes().get(1));
group.removeShape(shape1);
group.removeShape(shape4);
- assertEquals(0, group.getShapes().length);
+ assertTrue(group.getShapes().isEmpty());
}
+ @Test
public void testRemoveShapes() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java Fri Jul 24 21:47:55 2015
@@ -16,24 +16,29 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URI;
+import java.util.List;
+
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.xslf.XSLFTestDataSamples;
-
-import java.net.URI;
+import org.junit.Test;
/**
* @author Yegor Kozlov
*/
-public class TestXSLFHyperlink extends TestCase {
+public class TestXSLFHyperlink {
+ @Test
public void testRead(){
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
- XSLFSlide slide = ppt.getSlides()[4];
- XSLFShape[] shapes = slide.getShapes();
- XSLFTable tbl = (XSLFTable)shapes[0];
+ XSLFSlide slide = ppt.getSlides().get(4);
+ List<XSLFShape> shapes = slide.getShapes();
+ XSLFTable tbl = (XSLFTable)shapes.get(0);
XSLFTableCell cell1 = tbl.getRows().get(1).getCells().get(0);
assertEquals("Web Page", cell1.getText());
XSLFHyperlink link1 = cell1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
@@ -53,6 +58,7 @@ public class TestXSLFHyperlink extends T
assertEquals(URI.create("mailto:dev@poi.apache.org?subject=Hi%20There"), link3.getTargetURI());
}
+ @Test
public void testCreate() throws Exception {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide1 = ppt.createSlide();
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java Fri Jul 24 21:47:55 2015
@@ -16,22 +16,20 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
+import java.util.*;
import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.junit.Test;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
/**
* @author Yegor Kozlov
*/
-public class TestXSLFPictureShape extends TestCase {
+public class TestXSLFPictureShape {
+ @Test
public void testCreate() {
XMLSlideShow ppt = new XMLSlideShow();
assertEquals(0, ppt.getAllPictures().size());
@@ -61,11 +59,12 @@ public class TestXSLFPictureShape extend
assertArrayEquals(data1, pics.get(0).getData());
assertArrayEquals(data2, pics.get(1).getData());
- XSLFShape[] shapes = ppt.getSlides()[0].getShapes();
- assertArrayEquals(data1, ((XSLFPictureShape) shapes[0]).getPictureData().getData());
- assertArrayEquals(data2, ((XSLFPictureShape) shapes[1]).getPictureData().getData());
+ List<XSLFShape> shapes = ppt.getSlides().get(0).getShapes();
+ assertArrayEquals(data1, ((XSLFPictureShape) shapes.get(0)).getPictureData().getData());
+ assertArrayEquals(data2, ((XSLFPictureShape) shapes.get(1)).getPictureData().getData());
}
+ @Test
public void testCreateMultiplePictures() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide1 = ppt.createSlide();
@@ -118,6 +117,7 @@ public class TestXSLFPictureShape extend
}
}
+ @Test
public void testImageCaching() {
XMLSlideShow ppt = new XMLSlideShow();
byte[] img1 = new byte[]{1,2,3};
@@ -137,6 +137,7 @@ public class TestXSLFPictureShape extend
}
+ @Test
public void testMerge() {
XMLSlideShow ppt1 = new XMLSlideShow();
byte[] data1 = new byte[100];
@@ -150,7 +151,7 @@ public class TestXSLFPictureShape extend
XMLSlideShow ppt2 = new XMLSlideShow();
XSLFSlide slide2 = ppt2.createSlide().importContent(slide1);
- XSLFPictureShape shape2 = (XSLFPictureShape)slide2.getShapes()[0];
+ XSLFPictureShape shape2 = (XSLFPictureShape)slide2.getShapes().get(0);
assertArrayEquals(data1, shape2.getPictureData().getData());
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java Fri Jul 24 21:47:55 2015
@@ -16,8 +16,10 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
import java.util.List;
@@ -25,17 +27,18 @@ import java.util.List;
/**
* @author Yegor Kozlov
*/
-public class TestXSLFShape extends TestCase {
+public class TestXSLFShape {
+ @Test
public void testReadTextShapes() {
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
- XSLFSlide[] slides = ppt.getSlides();
+ List<XSLFSlide> slides = ppt.getSlides();
- XSLFSlide slide1 = slides[0];
- XSLFShape[] shapes1 = slide1.getShapes();
- assertEquals(7, shapes1.length);
- assertEquals("TextBox 3", shapes1[0].getShapeName());
- XSLFAutoShape sh0 = (XSLFAutoShape) shapes1[0];
+ XSLFSlide slide1 = slides.get(0);
+ List<XSLFShape> shapes1 = slide1.getShapes();
+ assertEquals(7, shapes1.size());
+ assertEquals("TextBox 3", shapes1.get(0).getShapeName());
+ XSLFAutoShape sh0 = (XSLFAutoShape) shapes1.get(0);
assertEquals("Learning PPTX", sh0.getText());
List<XSLFTextParagraph> paragraphs0 = sh0.getTextParagraphs();
assertEquals(1, paragraphs0.size());
@@ -43,28 +46,28 @@ public class TestXSLFShape extends TestC
assertEquals("Learning PPTX", p0.getText());
assertEquals(1, p0.getTextRuns().size());
XSLFTextRun r0 = p0.getTextRuns().get(0);
- assertEquals("Learning PPTX", r0.getText());
+ assertEquals("Learning PPTX", r0.getRawText());
- XSLFSlide slide2 = slides[1];
- XSLFShape[] shapes2 = slide2.getShapes();
- assertTrue(shapes2[0] instanceof XSLFAutoShape);
- assertEquals("PPTX Title", ((XSLFAutoShape) shapes2[0]).getText());
- XSLFAutoShape sh1 = (XSLFAutoShape) shapes2[0];
+ XSLFSlide slide2 = slides.get(1);
+ List<XSLFShape> shapes2 = slide2.getShapes();
+ assertTrue(shapes2.get(0) instanceof XSLFAutoShape);
+ assertEquals("PPTX Title", ((XSLFAutoShape) shapes2.get(0)).getText());
+ XSLFAutoShape sh1 = (XSLFAutoShape) shapes2.get(0);
List<XSLFTextParagraph> paragraphs1 = sh1.getTextParagraphs();
assertEquals(1, paragraphs1.size());
XSLFTextParagraph p1 = paragraphs1.get(0);
assertEquals("PPTX Title", p1.getText());
List<XSLFTextRun> r2 = paragraphs1.get(0).getTextRuns();
assertEquals(2, r2.size());
- assertEquals("PPTX ", r2.get(0).getText());
- assertEquals("Title", r2.get(1).getText());
+ assertEquals("PPTX ", r2.get(0).getRawText());
+ assertEquals("Title", r2.get(1).getRawText());
// Title is underlined
assertEquals(STTextUnderlineType.SNG, r2.get(1).getXmlObject().getRPr().getU());
- assertTrue(shapes2[1] instanceof XSLFAutoShape);
- assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape) shapes2[1]).getText());
- XSLFAutoShape sh2 = (XSLFAutoShape) shapes2[1];
+ assertTrue(shapes2.get(1) instanceof XSLFAutoShape);
+ assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape) shapes2.get(1)).getText());
+ XSLFAutoShape sh2 = (XSLFAutoShape) shapes2.get(1);
List<XSLFTextParagraph> paragraphs2 = sh2.getTextParagraphs();
assertEquals(2, paragraphs2.size());
assertEquals("Subtitle", paragraphs2.get(0).getText());
@@ -73,20 +76,20 @@ public class TestXSLFShape extends TestC
assertEquals(1, paragraphs2.get(0).getTextRuns().size());
assertEquals(1, paragraphs2.get(1).getTextRuns().size());
- assertEquals("Subtitle", paragraphs2.get(0).getTextRuns().get(0).getText());
+ assertEquals("Subtitle", paragraphs2.get(0).getTextRuns().get(0).getRawText());
assertTrue(paragraphs2.get(0).getTextRuns().get(0).getXmlObject().getRPr().getB());
- assertEquals("And second line", paragraphs2.get(1).getTextRuns().get(0).getText());
+ assertEquals("And second line", paragraphs2.get(1).getTextRuns().get(0).getRawText());
}
public void testCreateShapes() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
- assertEquals(0, slide.getShapes().length);
+ assertTrue(slide.getShapes().isEmpty());
XSLFTextBox textBox = slide.createTextBox();
- assertEquals(1, slide.getShapes().length);
- assertSame(textBox, slide.getShapes()[0]);
+ assertEquals(1, slide.getShapes().size());
+ assertSame(textBox, slide.getShapes().get(0));
assertEquals("", textBox.getText());
assertEquals(0, textBox.getTextParagraphs().size());
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java Fri Jul 24 21:47:55 2015
@@ -18,35 +18,39 @@
*/
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
/**
* test common operations on containers of shapes (sheets and groups of shapes)
*
* @author Yegor Kozlov
*/
-public class TestXSLFShapeContainer extends TestCase {
+public class TestXSLFShapeContainer {
+ @SuppressWarnings("unused")
public void verifyContainer(XSLFShapeContainer container) {
container.clear();
- assertEquals(0, container.getShapes().length);
+ assertEquals(0, container.getShapes().size());
XSLFGroupShape shape1 = container.createGroup();
- assertEquals(1, container.getShapes().length);
+ assertEquals(1, container.getShapes().size());
XSLFTextBox shape2 = container.createTextBox();
- assertEquals(2, container.getShapes().length);
+ assertEquals(2, container.getShapes().size());
XSLFAutoShape shape3 = container.createAutoShape();
- assertEquals(3, container.getShapes().length);
+ assertEquals(3, container.getShapes().size());
XSLFConnectorShape shape4 = container.createConnector();
- assertEquals(4, container.getShapes().length);
+ assertEquals(4, container.getShapes().size());
container.clear();
- assertEquals(0, container.getShapes().length);
+ assertEquals(0, container.getShapes().size());
}
+ @Test
public void testSheet() {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSheet sheet = ppt.createSlide();
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java?rev=1692593&r1=1692592&r2=1692593&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java Fri Jul 24 21:47:55 2015
@@ -16,50 +16,56 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
+import java.util.List;
+
import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.junit.Test;
/**
* test common properties for sheets (slides, masters, layouts, etc.)
*
* @author Yegor Kozlov
*/
-public class TestXSLFSheet extends TestCase {
+public class TestXSLFSheet {
+
+ @Test
public void testCreateShapes(){
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
- assertEquals(0, slide.getShapes().length);
+ assertTrue(slide.getShapes().isEmpty());
XSLFSimpleShape shape1 = slide.createAutoShape();
- assertEquals(1, slide.getShapes().length);
- assertSame(shape1, slide.getShapes()[0]);
+ assertEquals(1, slide.getShapes().size());
+ assertSame(shape1, slide.getShapes().get(0));
XSLFTextBox shape2 = slide.createTextBox();
- assertEquals(2, slide.getShapes().length);
- assertSame(shape1, slide.getShapes()[0]);
- assertSame(shape2, slide.getShapes()[1]);
+ assertEquals(2, slide.getShapes().size());
+ assertSame(shape1, slide.getShapes().get(0));
+ assertSame(shape2, slide.getShapes().get(1));
XSLFConnectorShape shape3 = slide.createConnector();
- assertEquals(3, slide.getShapes().length);
- assertSame(shape1, slide.getShapes()[0]);
- assertSame(shape2, slide.getShapes()[1]);
- assertSame(shape3, slide.getShapes()[2]);
+ assertEquals(3, slide.getShapes().size());
+ assertSame(shape1, slide.getShapes().get(0));
+ assertSame(shape2, slide.getShapes().get(1));
+ assertSame(shape3, slide.getShapes().get(2));
XSLFGroupShape shape4 = slide.createGroup();
- assertEquals(4, slide.getShapes().length);
- assertSame(shape1, slide.getShapes()[0]);
- assertSame(shape2, slide.getShapes()[1]);
- assertSame(shape3, slide.getShapes()[2]);
- assertSame(shape4, slide.getShapes()[3]);
+ assertEquals(4, slide.getShapes().size());
+ assertSame(shape1, slide.getShapes().get(0));
+ assertSame(shape2, slide.getShapes().get(1));
+ assertSame(shape3, slide.getShapes().get(2));
+ assertSame(shape4, slide.getShapes().get(3));
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
- slide = ppt.getSlides()[0];
- XSLFShape[] shapes = slide.getShapes();
- assertEquals(4, shapes.length);
-
- assertTrue(shapes[0] instanceof XSLFAutoShape);
- assertTrue(shapes[1] instanceof XSLFTextBox);
- assertTrue(shapes[2] instanceof XSLFConnectorShape);
- assertTrue(shapes[3] instanceof XSLFGroupShape);
+ slide = ppt.getSlides().get(0);
+ List<XSLFShape> shapes = slide.getShapes();
+ assertEquals(4, shapes.size());
+
+ assertTrue(shapes.get(0) instanceof XSLFAutoShape);
+ assertTrue(shapes.get(1) instanceof XSLFTextBox);
+ assertTrue(shapes.get(2) instanceof XSLFConnectorShape);
+ assertTrue(shapes.get(3) instanceof XSLFGroupShape);
}
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org