1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sd; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.container.XIndexAccess; 40 import com.sun.star.drawing.XDrawPage; 41 import com.sun.star.drawing.XDrawPages; 42 import com.sun.star.drawing.XDrawPagesSupplier; 43 import com.sun.star.drawing.XShape; 44 import com.sun.star.drawing.XShapes; 45 import com.sun.star.lang.XComponent; 46 import com.sun.star.lang.XMultiServiceFactory; 47 import com.sun.star.style.XStyle; 48 import com.sun.star.uno.AnyConverter; 49 import com.sun.star.uno.Type; 50 import com.sun.star.uno.UnoRuntime; 51 import com.sun.star.uno.XInterface; 52 53 /** 54 * Test for object which is represented by service 55 * <code>com.sun.star.drawing.Shape</code>. <p> 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::lang::XComponent</code></li> 59 * <li> <code>com::sun::star::drawing::XShape</code></li> 60 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li> 61 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 62 * <li> <code>com::sun::star::drawing::Shape</code></li> 63 * </ul> 64 * @see com.sun.star.lang.XComponent 65 * @see com.sun.star.drawing.XShape 66 * @see com.sun.star.drawing.XShapeDescriptor 67 * @see com.sun.star.beans.XPropertySet 68 * @see com.sun.star.drawing.Shape 69 * @see ifc.lang._XComponent 70 * @see ifc.drawing._XShape 71 * @see ifc.drawing._XShapeDescriptor 72 * @see ifc.beans._XPropertySet 73 * @see ifc.drawing._Shape 74 */ 75 public class SdXShape extends TestCase { 76 XComponent xDrawDoc; 77 78 /** 79 * Creates Drawing document. 80 */ 81 protected void initialize(TestParameters Param, PrintWriter log) { 82 // get a soffice factory object 83 SOfficeFactory SOF = SOfficeFactory.getFactory( 84 (XMultiServiceFactory)Param.getMSF()); 85 86 try { 87 log.println( "creating a draw document" ); 88 xDrawDoc = SOF.createDrawDoc(null); 89 } catch (com.sun.star.uno.Exception e) { 90 e.printStackTrace( log ); 91 throw new StatusException("Couldn't create document", e); 92 } 93 } 94 95 /** 96 * Disposes Drawing document. 97 */ 98 protected void cleanup( TestParameters Param, PrintWriter log) { 99 log.println("disposing xDrawDoc"); 100 util.DesktopTools.closeDoc(xDrawDoc);; 101 } 102 103 /** 104 * Creating a Testenvironment for the interfaces to be tested. 105 * Retrieves the collection of the draw pages from the drawing document using 106 * the interface <code>XDrawPagesSupplier</code>. Creates a rectangle shape 107 * that is the instance of the service <code>com.sun.star.drawing.Shape</code>. 108 * Creates and adds several new rectangle shapes and one ellipse shape to 109 * the retrieved draw page. Sets and gets some properties of the created 110 * rectangle shape. 111 * Object relations created : 112 * <ul> 113 * <li> <code>'Style1'</code> for 114 * {@link ifc.drawing._XShapeDescriptor}, {@link ifc.drawing._XShape} 115 * (the value of the property 'Style' that was retrived from the created 116 * rectangle shape) </li> 117 * <li> <code>'Style2'</code> for 118 * {@link ifc.drawing._XShapeDescriptor}, {@link ifc.drawing._XShape} 119 * (the value of the property 'Style' that was retrived from the created 120 * ellipse shape) </li> 121 * </ul> 122 * @see com.sun.star.drawing.XDrawPagesSupplier 123 * @see com.sun.star.drawing.Shape 124 */ 125 protected synchronized TestEnvironment createTestEnvironment( 126 TestParameters Param, PrintWriter log) { 127 128 log.println( "creating a test environment" ); 129 130 // get a soffice factory object 131 SOfficeFactory SOF = SOfficeFactory.getFactory( 132 (XMultiServiceFactory)Param.getMSF()); 133 134 // get the drawpage of drawing here 135 log.println( "getting Drawpage" ); 136 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 137 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); 138 XDrawPages oDPn = oDPS.getDrawPages(); 139 XIndexAccess oDPi = (XIndexAccess) 140 UnoRuntime.queryInterface(XIndexAccess.class, oDPn); 141 XDrawPage oDP = null; 142 try { 143 oDP = (XDrawPage) AnyConverter.toObject( 144 new Type(XDrawPage.class),oDPi.getByIndex(0)); 145 } catch (com.sun.star.lang.WrappedTargetException e) { 146 e.printStackTrace( log ); 147 throw new StatusException("Couldn't get by index", e); 148 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 149 e.printStackTrace( log ); 150 throw new StatusException("Couldn't get by index", e); 151 } catch (com.sun.star.lang.IllegalArgumentException e) { 152 e.printStackTrace( log ); 153 throw new StatusException("Couldn't get by index", e); 154 } 155 156 //get a Shape 157 log.println( "getting Shape" ); 158 XShapes oShapes = (XShapes) UnoRuntime.queryInterface 159 (XShapes.class, oDP); 160 XInterface oObj = SOF.createShape 161 (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 162 for (int i=0; i < 10; i++) { 163 oShapes.add( 164 SOF.createShape(xDrawDoc, 165 5000, 3500, 7510 + 10 * i, 5010 + 10 * i, "Rectangle")); 166 } 167 XShape oShape = SOF.createShape 168 (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"); 169 oShapes.add((XShape) oObj); 170 oShapes.add((XShape) oShape); 171 172 log.println( "creating a new environment for XShape object" ); 173 TestEnvironment tEnv = new TestEnvironment( oObj ); 174 175 log.println( "adding two style as ObjRelation for ShapeDescriptor" ); 176 XPropertySet oShapeProps = (XPropertySet) 177 UnoRuntime.queryInterface(XPropertySet.class, oObj); 178 XStyle aStyle = null; 179 try { 180 aStyle = (XStyle) AnyConverter.toObject( 181 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 182 oShapeProps.setPropertyValue("ZOrder", new Integer(1)); 183 } catch (com.sun.star.lang.WrappedTargetException e) { 184 e.printStackTrace(log); 185 throw new StatusException("Couldn't set or get property value", e); 186 } catch (com.sun.star.beans.UnknownPropertyException e) { 187 e.printStackTrace(log); 188 throw new StatusException("Couldn't set or get property value", e); 189 } catch (com.sun.star.lang.IllegalArgumentException e) { 190 e.printStackTrace(log); 191 throw new StatusException("Couldn't set or get property value", e); 192 } catch (com.sun.star.beans.PropertyVetoException e) { 193 e.printStackTrace(log); 194 throw new StatusException("Couldn't set or get property value", e); 195 } 196 197 tEnv.addObjRelation("Style1", aStyle); 198 oShapeProps = (XPropertySet) 199 UnoRuntime.queryInterface(XPropertySet.class, oShape); 200 try { 201 aStyle = (XStyle) AnyConverter.toObject( 202 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 203 } catch (com.sun.star.lang.WrappedTargetException e) { 204 e.printStackTrace(log); 205 throw new StatusException("Couldn't get property value", e); 206 } catch (com.sun.star.beans.UnknownPropertyException e) { 207 e.printStackTrace(log); 208 throw new StatusException("Couldn't get property value", e); 209 } catch (com.sun.star.lang.IllegalArgumentException e) { 210 e.printStackTrace(log); 211 throw new StatusException("Couldn't get property value", e); 212 } 213 214 tEnv.addObjRelation("Style2", aStyle); 215 216 return tEnv; 217 } // finish method createTestEnvironment 218 219 } // finish class SdXShape 220