### Eclipse Workspace Patch 1.0 #P testuno Index: source/testlib/uno/ShapeUtil.java =================================================================== --- source/testlib/uno/ShapeUtil.java (revision 1376382) +++ source/testlib/uno/ShapeUtil.java (working copy) @@ -25,6 +25,7 @@ import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.IndexOutOfBoundsException; import com.sun.star.lang.WrappedTargetException; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiServiceFactory; @@ -37,7 +38,11 @@ import com.sun.star.container.NoSuchElementException; import com.sun.star.container.XEnumeration; import com.sun.star.container.XEnumerationAccess; +import com.sun.star.container.XIndexAccess; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; import com.sun.star.drawing.XShape; import com.sun.star.drawing.XShapes; @@ -75,27 +80,8 @@ return xShape; } - /** - * try to get shape according position - * - * @param aPos - * @return - */ - public static XShape getShape(XComponent xDrawDoc, Point aPos, - String sShapeType) { - XShape xShape = null; - try { - XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime - .queryInterface(XMultiServiceFactory.class, xDrawDoc); - Object xObj = xFactory.createInstance(sShapeType); - xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xObj); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return xShape; - } + /** * add text to a shape. the return value is the PropertySet of the text * range that has been added @@ -187,4 +173,39 @@ } } } + /** + * Get shapes in specific page + * @param impressDocument + * @param pageIndex + * @return + * @throws Exception + */ + public static XShapes getShapes(XComponent impressDocument, int pageIndex) throws Exception{ + + XDrawPagesSupplier drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( + XDrawPagesSupplier.class, impressDocument); + XDrawPages drawpages = drawsupplier.getDrawPages(); + XDrawPage xpage=(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawpages.getByIndex(pageIndex)); + XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + return xShapes; + + } + + /** + * Remove the specific shape in specific page + * @param impressDocument + * @param pageIndex + * @param shapeIndex + * @throws Exception + */ + public static void removeOneShape(XComponent impressDocument, int pageIndex, int shapeIndex) throws Exception{ + XDrawPagesSupplier drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( + XDrawPagesSupplier.class, impressDocument); + XDrawPages drawpages = drawsupplier.getDrawPages(); + XDrawPage xpage=(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawpages.getByIndex(pageIndex)); + XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex)); + xShapes.remove(xShape); + + } } Index: source/testcase/uno/sd/ShapeProperties.java =================================================================== --- source/testcase/uno/sd/ShapeProperties.java (revision 1376382) +++ source/testcase/uno/sd/ShapeProperties.java (working copy) @@ -20,6 +20,7 @@ *************************************************************/ package testcase.uno.sd; +import java.awt.geom.AffineTransform; import java.io.File; import java.io.IOException; @@ -35,7 +36,11 @@ import testlib.uno.PageUtil; import testlib.uno.ShapeUtil; +import testlib.uno.TestUtil; +import com.sun.star.text.WrapTextMode; +import com.sun.star.text.XText; +import com.sun.star.text.XTextContent; import com.sun.star.uno.UnoRuntime; import com.sun.star.presentation.XPresentation; import com.sun.star.presentation.XPresentationSupplier; @@ -45,9 +50,13 @@ import com.sun.star.awt.Point; import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; +import com.sun.star.drawing.DashStyle; import com.sun.star.drawing.FillStyle; import com.sun.star.drawing.Hatch; import com.sun.star.drawing.HatchStyle; +import com.sun.star.drawing.HomogenMatrix3; +import com.sun.star.drawing.LineDash; +import com.sun.star.drawing.LineStyle; import com.sun.star.drawing.XDrawPage; import com.sun.star.drawing.XDrawPages; import com.sun.star.drawing.XDrawPagesSupplier; @@ -69,7 +78,7 @@ XDrawPages drawpages = null; XShapes xShapes = null; XDrawPage xpage = null; - String filePath=null; + String filePath = null; @Before public void setUp() throws Exception { @@ -82,7 +91,7 @@ unoApp.closeDocument(impressDocument); unoApp.closeDocument(reLoadFile); unoApp.close(); - if(filePath!=null) + if (filePath != null) FileUtil.deleteFile(filePath); } @@ -91,128 +100,252 @@ * * @throws Exception */ - @Test - public void testInsertShape() throws Exception { - Point po = new Point(1000, 8000); - xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); - XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( - 5000, 5000), "com.sun.star.drawing.EllipseShape"); - xShapes.add(xShape); - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, xShape); - xPropSet.setPropertyValue("Name", "test"); - XShape shap = ShapeUtil.getShape(impressDocument, po, - "com.sun.star.drawing.EllipseShape"); - XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, xShape); - assertEquals("Not the same shape","test",xPropSet2.getPropertyValue("Name")); - assertEquals("Not EllopseShape","com.sun.star.drawing.EllipseShape",shap.getShapeType()); - } + @Test + public void testInsertShape() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + xPropSet.setPropertyValue("Name", "test"); + + xShape=saveAndLoadShape(1,0); + XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + assertEquals("Not the same shape","test",xPropSet2.getPropertyValue("Name")); + assertEquals("Not EllopseShape","com.sun.star.drawing.EllipseShape",xShape.getShapeType()); + } + + /** + * test Insert text to an EllopseShape + * + * @throws Exception + */ + @Test + public void testInsertTextToShape() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + xShape=saveAndLoadShape(1,0); + ShapeUtil.addPortion(xShape, "test", false); + assertEquals("Not put text correctly","test",ShapeUtil.getPortion(xShape)); + } + + /** + * test Shape fill with Gradient + * + * @throws Exception + */ + @Test + public void testShapeFillGradient() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + xPropSet.setPropertyValue("FillStyle", FillStyle.GRADIENT); + Gradient aGradient = new Gradient(); + aGradient.Style = GradientStyle.LINEAR; + aGradient.StartColor = 0x00ff00; + aGradient.EndColor = 0xffff00; + aGradient.Angle = 450; + aGradient.Border = 0; + aGradient.XOffset = 0; + aGradient.YOffset = 0; + aGradient.StartIntensity = 100; + aGradient.EndIntensity = 100; + aGradient.StepCount = 10; + xPropSet.setPropertyValue("FillGradient", aGradient); + // -------------------------- + xShape=saveAndLoadShape(1,0); + xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); + // ---------------------------- + assertEquals("Not Gradient Fill Style",FillStyle.GRADIENT,xPropSet.getPropertyValue("FillStyle")); + aGradient=(Gradient) xPropSet.getPropertyValue("FillGradient"); + assertEquals("Not Linear Gradient",GradientStyle.LINEAR,aGradient.Style); + } + + /** + * test Shape fill with yellow color + * + * @throws Exception + */ + @Test + public void testShapeFillColor() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + xPropSet.setPropertyValue("FillStyle", FillStyle.SOLID); + xPropSet.setPropertyValue("FillColor", 0xffff00); + // -------------------------- + xShape=saveAndLoadShape(1,0); + xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); + // ---------------------------------------------------- + assertEquals("Not Color Fill Style",FillStyle.SOLID,xPropSet.getPropertyValue("FillStyle")); + assertEquals("Not Yellow Color Fill",0xffff00,xPropSet.getPropertyValue("FillColor")); + } + + /** + * test shape fill with Hatch Style(Pattern in MS) + * @throws Exception + */ + @Test + public void testShapeFillHatch() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + xPropSet.setPropertyValue("FillStyle", FillStyle.HATCH); + Hatch aHatch=new Hatch(); + aHatch.Style=HatchStyle.DOUBLE; + aHatch.Color=0x00ff00; + aHatch.Distance=100; + aHatch.Angle=450; + xPropSet.setPropertyValue("FillHatch", aHatch); + + // -------------------------- + xShape=saveAndLoadShape(1,0); + xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); + // ---------------------------- + assertEquals("Not Gradient Fill Style",FillStyle.HATCH,xPropSet.getPropertyValue("FillStyle")); + aHatch=(Hatch) xPropSet.getPropertyValue("FillHatch"); + assertEquals("Not Double Hatch",HatchStyle.DOUBLE,aHatch.Style); + } + // ------------Shape Line----------------------------- /** - * test Insert text to an EllopseShape + * test Shape Line style DASH * * @throws Exception */ - @Test - public void testInsertTextToShape() throws Exception { - Point po = new Point(1000, 8000); - xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); - XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( - 5000, 5000), "com.sun.star.drawing.EllipseShape"); - xShapes.add(xShape); - ShapeUtil.addPortion(xShape, "test", false); - assertEquals("Not put text correctly","test",ShapeUtil.getPortion(xShape)); - } + @Test + public void testShapeLineStyle() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + xPropSet.setPropertyValue("LineStyle", LineStyle.DASH); + + LineDash aLineDash=new LineDash(); + aLineDash.Style=DashStyle.ROUND; + aLineDash.Dots=2; + aLineDash.DashLen=100; + aLineDash.Distance=50; + xPropSet.setPropertyValue("LineDash", aLineDash); + + // -------------------------- + xShape=saveAndLoadShape(1,0); + xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); + // ---------------------------- + assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle")); + aLineDash=(LineDash) xPropSet.getPropertyValue("LineDash"); + assertEquals("Not Round Dash Style", DashStyle.ROUND ,aLineDash.Style); + } + + /** + * test Shape Line Color + * @throws Exception + */ + + @Test + public void testShapeLineColor() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + xPropSet.setPropertyValue("LineStyle", LineStyle.DASH); + xPropSet.setPropertyValue("LineColor", 0x00ff00); + xShape=saveAndLoadShape(1,0); + xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); + // ---------------------------- + assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle")); + assertEquals("wrong line color", 0x00ff00,xPropSet.getPropertyValue("LineColor")); + } /** - * test Shape fill with Gradient + * test Shape position and size * * @throws Exception */ - @Test - public void testShapeFillGradient() throws Exception { - Point po = new Point(1000, 8000); - xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); - XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( - 5000, 5000), "com.sun.star.drawing.EllipseShape"); - xShapes.add(xShape); - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, xShape); - xPropSet.setPropertyValue("FillStyle", FillStyle.GRADIENT); - Gradient aGradient = new Gradient(); - aGradient.Style = GradientStyle.LINEAR; - aGradient.StartColor = 0x00ff00; - aGradient.EndColor = 0xffff00; - aGradient.Angle = 450; - aGradient.Border = 0; - aGradient.XOffset = 0; - aGradient.YOffset = 0; - aGradient.StartIntensity = 100; - aGradient.EndIntensity = 100; - aGradient.StepCount = 10; - xPropSet.setPropertyValue("FillGradient", aGradient); - // -------------------------- - xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape"); - // ---------------------------- - assertEquals("Not Gradient Fill Style",FillStyle.GRADIENT,xPropSet.getPropertyValue("FillStyle")); - aGradient=(Gradient) xPropSet.getPropertyValue("FillGradient"); - assertEquals("Not Linear Gradient",GradientStyle.LINEAR,aGradient.Style); - } + @Test + public void testShapePositionSize() throws Exception { + Point po = new Point(1000, 8000); + xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); + XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( + 5000, 5000), "com.sun.star.drawing.EllipseShape"); + xShapes.add(xShape); + xShape=saveAndLoadShape(1,0); + assertEquals("wrong shape position",1000,xShape.getPosition().X); + assertEquals("wrong shape Height", 5000 ,xShape.getSize().Height); + } /** - * test Shape fill with yellow color - * + * test Shape rotate with 25 degree. * @throws Exception */ @Test - public void testShapeFillColor() throws Exception { + public void testShapeRotation() throws Exception { Point po = new Point(1000, 8000); xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( - 5000, 5000), "com.sun.star.drawing.EllipseShape"); + 5000, 5000), "com.sun.star.drawing.RectangleShape"); xShapes.add(xShape); XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xShape); - xPropSet.setPropertyValue("FillStyle", FillStyle.SOLID); - xPropSet.setPropertyValue("FillColor", 0xffff00); - // -------------------------- - xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape"); - // ---------------------------------------------------- - assertEquals("Not Color Fill Style",FillStyle.SOLID,xPropSet.getPropertyValue("FillStyle")); - assertEquals("Not Yellow Color Fill",0xffff00,xPropSet.getPropertyValue("FillColor")); + xPropSet.setPropertyValue("RotateAngle", 2500); + xShape=saveAndLoadShape(1,0); + xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xShape); + assertEquals("RotateAngle is not 2500", 2500 , xPropSet.getPropertyValue("RotateAngle")); } - + + + // ------------------Shape Remove---------------------------- /** - * test shape fill with Hatch Style(Pattern in MS) + * test Remove shape from impress Document + * * @throws Exception */ - @Test - public void testShapeFillHatch() throws Exception { - Point po = new Point(1000, 8000); - xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); - XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( - 5000, 5000), "com.sun.star.drawing.EllipseShape"); - xShapes.add(xShape); - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, xShape); - xPropSet.setPropertyValue("FillStyle", FillStyle.HATCH); - Hatch aHatch=new Hatch(); - aHatch.Style=HatchStyle.DOUBLE; - aHatch.Color=0x00ff00; - aHatch.Distance=100; - aHatch.Angle=450; - xPropSet.setPropertyValue("FillHatch", aHatch); - - // -------------------------- - xShape = saveAndLoadShape(po, "com.sun.star.drawing.EllipseShape"); - // ---------------------------- - assertEquals("Not Gradient Fill Style",FillStyle.HATCH,xPropSet.getPropertyValue("FillStyle")); - - aHatch=(Hatch) xPropSet.getPropertyValue("FillHatch"); - assertEquals("Not Double Hatch",HatchStyle.DOUBLE,aHatch.Style); - } - + @Test + public void testShapeRemove() throws Exception { + Point aPos=null; + Size aSize=new Size(4000,4000); + for(int i=0;i<=4;i++){ + aPos=new Point(1000, 3000*i); + xShapes=ShapeUtil.getShapes(impressDocument, 0); + ShapeUtil.createAndInsertShape(impressDocument, xShapes, aPos, aSize, + "com.sun.star.drawing.EllipseShape"); + } + int countBeforeRemove=ShapeUtil.getShapes(impressDocument, 0).getCount(); + ShapeUtil.removeOneShape(impressDocument, 0, 2); + int countAfterRemove=ShapeUtil.getShapes(impressDocument, 0).getCount(); + assertEquals("Not remove shape successfully",1,countBeforeRemove-countAfterRemove); + reLoadFile = saveAndReloadDoc(impressDocument, + "StarOffice XML (Impress)", "odp"); + xShapes=ShapeUtil.getShapes(reLoadFile, 0); + assertEquals("Shape count is wrong after reload",6,xShapes.getCount()); + } + /** * create a new presentation document and insert a new slide. * @@ -236,19 +369,12 @@ * @return * @throws Exception */ - public XShape saveAndLoadShape(Point po, String shapeType) throws Exception { + public XShape saveAndLoadShape(int pageIndex, int shapeIndex) throws Exception { reLoadFile = saveAndReloadDoc(impressDocument, "StarOffice XML (Impress)", "odp"); - drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( - XDrawPagesSupplier.class, reLoadFile); - drawpages = drawsupplier.getDrawPages(); - xpage = PageUtil.getDrawPageByIndex(impressDocument, 1); - xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); - XShape shap = ShapeUtil.getShape(impressDocument, po, - "com.sun.star.drawing.EllipseShape"); - return shap; + xShapes=ShapeUtil.getShapes(reLoadFile, pageIndex); + return (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex)); } - /** * save and reload Presentation document. * @@ -260,8 +386,7 @@ */ private XComponent saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension) throws Exception { - filePath = Testspace.getPath("tmp/presentationtest." - + sExtension); + filePath = Testspace.getPath("tmp/presentationtest." + sExtension); PropertyValue[] aStoreProperties = new PropertyValue[2]; aStoreProperties[0] = new PropertyValue(); aStoreProperties[1] = new PropertyValue();