Index: testuno/data/uno/sd/36.gif =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: testuno/data/uno/sd/36.gif =================================================================== --- testuno/data/uno/sd/36.gif (revision 0) +++ testuno/data/uno/sd/36.gif (working copy) Property changes on: testuno/data/uno/sd/36.gif ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: testuno/source/testcase/uno/sd/graphic/GraphicPro_Position.java =================================================================== --- testuno/source/testcase/uno/sd/graphic/GraphicPro_Position.java (revision 0) +++ testuno/source/testcase/uno/sd/graphic/GraphicPro_Position.java (working copy) @@ -0,0 +1,148 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ +package testcase.uno.sd.graphic; +import static org.junit.Assert.*; +import static testlib.uno.GraphicUtil.getGraphicsOfPage; +import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile; +import static testlib.uno.GraphicUtil.insertGraphic; +import static testlib.uno.SDUtil.saveFileAs; + +import java.util.Arrays; +import java.util.Collection; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.openoffice.test.uno.UnoApp; +import org.openoffice.test.common.FileUtil; +import org.openoffice.test.common.Testspace; + +import testlib.uno.SDUtil; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XShape; +import com.sun.star.lang.XComponent; +import com.sun.star.uno.UnoRuntime; + +@RunWith(Parameterized.class) +public class GraphicPro_Position { + + private static final UnoApp app = new UnoApp(); + + private XComponent m_xSDComponent = null; + private XDrawPage m_xCurrentPage=null; + private Point m_position=null; + private Point m_expectedPosition=null; + private String m_fileType = null; + + public GraphicPro_Position(Point position, String fileType, Point expectedPosition){ + m_position = position; + m_fileType = fileType; + m_expectedPosition = expectedPosition; + } + @Parameters + public static Collection data() { + Point pNegative2 = new Point(-28000,-28000); //minimum + Point pNegative3 = new Point(-1000,-1000); + Point pZero = new Point(0,0); + Point pPositive1 = new Point(1000,1000); + Point pPositive2 = new Point(34833,34833); //maximum + return Arrays.asList(new Object[][]{ + {pNegative2, "odp", pNegative2}, + {pNegative2, "ppt", pNegative2}, + {pNegative3, "odp", pNegative3}, + {pNegative3, "ppt", pNegative3}, + {pZero, "odp", pZero}, + {pZero, "ppt", pZero}, + {pPositive1, "odp", pPositive1}, + {pPositive1, "ppt", pPositive1}, + {pPositive2, "odp", pPositive2}, + {pPositive2, "ppt", pPositive2} + }); + } + + @Before + public void setUpDocument() throws Exception { + m_xSDComponent = (XComponent) UnoRuntime.queryInterface( + XComponent.class, app.newDocument("simpress")); + Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0); + m_xCurrentPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage); + String graphicURL = FileUtil.getUrl(Testspace.prepareData("uno/sd/36.gif")); + + Size orgSize = getSizePixelOfGraphicFile(app,graphicURL); + Size newSize = new Size(orgSize.Width*2645/100, orgSize.Height*2645/100); + insertGraphic(m_xSDComponent, m_xCurrentPage, graphicURL, newSize, new Point(5000, 5000)); + } + + @After + public void tearDownDocument() { + app.closeDocument(m_xSDComponent); + + } + + @BeforeClass + public static void setUpConnection() throws Exception { + app.start(); + } + + @AfterClass + public static void tearDownConnection() throws InterruptedException, + Exception { + app.close(); + //remove the temp file + FileUtil.deleteFile(Testspace.getPath("temp")); + } + + + private XDrawPage load(String filePath) throws Exception{ + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0); + return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage); + } + + @Test + public void testPosition() throws Exception { + String fileName = "GraphicPro_Position"; + String filePath = Testspace.getPath("temp/"+fileName+"."+m_fileType); + Object[] graphics = getGraphicsOfPage(m_xCurrentPage); + Object oGraphic = graphics[0]; + XShape xGraphicShape = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic); + + xGraphicShape.setPosition(m_position); + + saveFileAs(m_xSDComponent, fileName, m_fileType); + app.closeDocument(m_xSDComponent); + + XDrawPage CurrentPage = load(filePath); + Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0]; + XShape xGraphicShape2 = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2); + + assertEquals("Position X of graphic error", m_expectedPosition.X, xGraphicShape2.getPosition().X, 2); + assertEquals("Position Y of graphic error", m_expectedPosition.Y, xGraphicShape2.getPosition().Y, 2); + } +} Index: testuno/source/testcase/uno/sd/graphic/GraphicPro_Size.java =================================================================== --- testuno/source/testcase/uno/sd/graphic/GraphicPro_Size.java (revision 0) +++ testuno/source/testcase/uno/sd/graphic/GraphicPro_Size.java (working copy) @@ -0,0 +1,143 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ +package testcase.uno.sd.graphic; +import static org.junit.Assert.*; +import static testlib.uno.GraphicUtil.getGraphicsOfPage; +import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile; +import static testlib.uno.GraphicUtil.insertGraphic; +import static testlib.uno.SDUtil.saveFileAs; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.openoffice.test.uno.UnoApp; +import org.openoffice.test.common.FileUtil; +import org.openoffice.test.common.Testspace; + +import testlib.uno.SDUtil; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XShape; +import com.sun.star.lang.XComponent; +import com.sun.star.uno.UnoRuntime; + +@RunWith(Parameterized.class) +public class GraphicPro_Size { + + private static final UnoApp app = new UnoApp(); + + private XComponent m_xSDComponent = null; + private XDrawPage m_xCurrentPage=null; + private Size m_Size=null; + private Size m_ExpectedSize=null; + private String m_fileType = null; + + public GraphicPro_Size(Size size, String fileType, Size expectedSize){ + m_Size = size; + m_fileType = fileType; + m_ExpectedSize = expectedSize; + } + @Parameters + public static Collection data() { + Size sMinimum = new Size(1,1); //minimum in UI + Size sNormal = new Size(2000,2000); + Size sMaximum = new Size(52448,28852); //maximum in UI + + return Arrays.asList(new Object[][]{ + {sMinimum, "odp", sMinimum}, + {sMinimum, "ppt", sMinimum}, + {sNormal, "odp", sNormal}, + {sNormal, "ppt", sNormal}, + {sMaximum, "odp", sMaximum}, + {sMaximum, "ppt", sMaximum} + }); + } + + @Before + public void setUpDocument() throws Exception { + m_xSDComponent = (XComponent) UnoRuntime.queryInterface( + XComponent.class, app.newDocument("simpress")); + Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0); + m_xCurrentPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage); + + String graphicURL = FileUtil.getUrl(Testspace.prepareData("uno/sd/36.gif")); + Size orgSize = getSizePixelOfGraphicFile(app,graphicURL); + Size newSize = new Size(orgSize.Width*2645/100, orgSize.Height*2645/100); + insertGraphic(m_xSDComponent, m_xCurrentPage, graphicURL, newSize, new Point(5000, 5000)); + } + + @After + public void tearDownDocument() { + app.closeDocument(m_xSDComponent); + + } + + @BeforeClass + public static void setUpConnection() throws Exception { + app.start(); + } + + @AfterClass + public static void tearDownConnection() throws InterruptedException, + Exception { + app.close(); + //remove the temp file + FileUtil.deleteFile(Testspace.getPath("temp")); + } + + private XDrawPage load(String filePath) throws Exception{ + m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, + app.loadDocument(filePath)); + Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0); + return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage); + } + + @Test + public void testGraphicSize() throws Exception{ + String fileName = "GraphicPro_Size"; + String filePath = Testspace.getPath("temp/"+fileName+"."+m_fileType); + Object[] graphics = getGraphicsOfPage(m_xCurrentPage); + Object oGraphic = graphics[0]; + XShape xGraphicShape = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic); + + xGraphicShape.setSize(m_Size); + + saveFileAs(m_xSDComponent, fileName, m_fileType); + app.closeDocument(m_xSDComponent); + + XDrawPage CurrentPage = load(filePath); + Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0]; + XShape xGraphicShape2 = (XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2); + + assertEquals("Height of graphic error", m_ExpectedSize.Height, xGraphicShape2.getSize().Height, 3); + assertEquals("Width of graphic error", m_ExpectedSize.Width, xGraphicShape2.getSize().Width, 3); + } +} Index: testuno/source/testlib/uno/GraphicUtil.java =================================================================== --- testuno/source/testlib/uno/GraphicUtil.java (revision 0) +++ testuno/source/testlib/uno/GraphicUtil.java (working copy) @@ -0,0 +1,159 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ +package testlib.uno; +import static org.junit.Assert.*; +import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.uno.UnoApp; +import org.openoffice.test.common.FileUtil; +import org.openoffice.test.common.Testspace; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.graphic.XGraphic; +import com.sun.star.graphic.XGraphicObject; +import com.sun.star.graphic.XGraphicProvider; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XServiceName; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +//import com.sun.star.uno.AnyConverter; + +public class GraphicUtil { + + public static String getUniqueIDbyXGraphic(UnoApp unoApp, XGraphic xgraphic) throws Exception{ + Object graphicObj = unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicObject"); + XGraphicObject xgraphicObj = (XGraphicObject)UnoRuntime.queryInterface(XGraphicObject.class, graphicObj); + xgraphicObj.setGraphic(xgraphic); + + return xgraphicObj.getUniqueID(); + } + +// String sUrl = "file:///F:/work/36.gif"; + public static String getUniqueIDOfGraphicFile(UnoApp unoApp, String sUrl) throws Exception{ + XGraphic xgraphic = getXGraphicOfGraphicFile(unoApp,sUrl); + String uniqueID = getUniqueIDbyXGraphic(unoApp, xgraphic); + + return uniqueID; + } + + public static XGraphic getXGraphicOfGraphicFile(UnoApp unoApp, String sUrl) throws Exception + { + Object graphicObj = unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicProvider"); + XGraphicProvider xgraphicProvider = (XGraphicProvider)UnoRuntime.queryInterface(XGraphicProvider.class, graphicObj); + PropertyValue[] sourceProps = new PropertyValue[1]; + sourceProps[0] = new PropertyValue(); + sourceProps[0].Name = "URL"; + sourceProps[0].Value = sUrl; + return xgraphicProvider.queryGraphic(sourceProps); + } + + public static Size getSize100thMMOfGraphicFile(UnoApp unoApp, String sUrl) throws Exception + { + Object graphicObj = unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicProvider"); + XGraphicProvider xgraphicProvider = (XGraphicProvider)UnoRuntime.queryInterface(XGraphicProvider.class, graphicObj); + PropertyValue[] sourceProps = new PropertyValue[1]; + sourceProps[0] = new PropertyValue(); + sourceProps[0].Name = "URL"; + sourceProps[0].Value = sUrl; + XPropertySet xGraphicPro = xgraphicProvider.queryGraphicDescriptor(sourceProps); + Size size = (Size)xGraphicPro.getPropertyValue("Size100thMM"); + return size; + } + + public static Size getSizePixelOfGraphicFile(UnoApp unoApp, String sUrl) throws Exception + { + Object graphicObj = unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicProvider"); + XGraphicProvider xgraphicProvider = (XGraphicProvider)UnoRuntime.queryInterface(XGraphicProvider.class, graphicObj); + PropertyValue[] sourceProps = new PropertyValue[1]; + sourceProps[0] = new PropertyValue(); + sourceProps[0].Name = "URL"; + sourceProps[0].Value = sUrl; + XPropertySet xGraphicPro = xgraphicProvider.queryGraphicDescriptor(sourceProps); + Size size = (Size)xGraphicPro.getPropertyValue("SizePixel"); + return size; + } + + + //GraphicObjectShape + public static Object[] getGraphicsOfPage(XDrawPage xDrawPage) throws Exception { + XShapes m_xdrawShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage); + int count = m_xdrawShapes.getCount(); + Object[] temp = new Object[count]; + int graphicNum=0; + for(int i=0;i 0) { + return; + } + + filterName.put("odp", "impress8"); + filterName.put("ppt", "MS PowerPoint 97"); + } + }