1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sd; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.beans.XPropertySet; 35 import com.sun.star.container.XIndexAccess; 36 import com.sun.star.drawing.XDrawPage; 37 import com.sun.star.drawing.XDrawPages; 38 import com.sun.star.drawing.XDrawPagesSupplier; 39 import com.sun.star.drawing.XShape; 40 import com.sun.star.drawing.XShapes; 41 import com.sun.star.lang.XComponent; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.style.XStyle; 44 import com.sun.star.uno.AnyConverter; 45 import com.sun.star.uno.Type; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 49 /** 50 * Test for object which is represented by service 51 * <code>com.sun.star.drawing.Shape</code>. <p> 52 * Object implements the following interfaces : 53 * <ul> 54 * <li> <code>com::sun::star::lang::XComponent</code></li> 55 * <li> <code>com::sun::star::drawing::XShape</code></li> 56 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li> 57 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 58 * <li> <code>com::sun::star::drawing::Shape</code></li> 59 * </ul> 60 * @see com.sun.star.lang.XComponent 61 * @see com.sun.star.drawing.XShape 62 * @see com.sun.star.drawing.XShapeDescriptor 63 * @see com.sun.star.beans.XPropertySet 64 * @see com.sun.star.drawing.Shape 65 * @see ifc.lang._XComponent 66 * @see ifc.drawing._XShape 67 * @see ifc.drawing._XShapeDescriptor 68 * @see ifc.beans._XPropertySet 69 * @see ifc.drawing._Shape 70 */ 71 public class SdXShape extends TestCase { 72 XComponent xDrawDoc; 73 74 /** 75 * Creates Drawing document. 76 */ 77 protected void initialize(TestParameters Param, PrintWriter log) { 78 // get a soffice factory object 79 SOfficeFactory SOF = SOfficeFactory.getFactory( 80 (XMultiServiceFactory)Param.getMSF()); 81 82 try { 83 log.println( "creating a draw document" ); 84 xDrawDoc = SOF.createDrawDoc(null); 85 } catch (com.sun.star.uno.Exception e) { 86 e.printStackTrace( log ); 87 throw new StatusException("Couldn't create document", e); 88 } 89 } 90 91 /** 92 * Disposes Drawing document. 93 */ 94 protected void cleanup( TestParameters Param, PrintWriter log) { 95 log.println("disposing xDrawDoc"); 96 util.DesktopTools.closeDoc(xDrawDoc);; 97 } 98 99 /** 100 * Creating a Testenvironment for the interfaces to be tested. 101 * Retrieves the collection of the draw pages from the drawing document using 102 * the interface <code>XDrawPagesSupplier</code>. Creates a rectangle shape 103 * that is the instance of the service <code>com.sun.star.drawing.Shape</code>. 104 * Creates and adds several new rectangle shapes and one ellipse shape to 105 * the retrieved draw page. Sets and gets some properties of the created 106 * rectangle shape. 107 * Object relations created : 108 * <ul> 109 * <li> <code>'Style1'</code> for 110 * {@link ifc.drawing._XShapeDescriptor}, {@link ifc.drawing._XShape} 111 * (the value of the property 'Style' that was retrived from the created 112 * rectangle shape) </li> 113 * <li> <code>'Style2'</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 * ellipse shape) </li> 117 * </ul> 118 * @see com.sun.star.drawing.XDrawPagesSupplier 119 * @see com.sun.star.drawing.Shape 120 */ 121 protected synchronized TestEnvironment createTestEnvironment( 122 TestParameters Param, PrintWriter log) { 123 124 log.println( "creating a test environment" ); 125 126 // get a soffice factory object 127 SOfficeFactory SOF = SOfficeFactory.getFactory( 128 (XMultiServiceFactory)Param.getMSF()); 129 130 // get the drawpage of drawing here 131 log.println( "getting Drawpage" ); 132 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 133 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); 134 XDrawPages oDPn = oDPS.getDrawPages(); 135 XIndexAccess oDPi = (XIndexAccess) 136 UnoRuntime.queryInterface(XIndexAccess.class, oDPn); 137 XDrawPage oDP = null; 138 try { 139 oDP = (XDrawPage) AnyConverter.toObject( 140 new Type(XDrawPage.class),oDPi.getByIndex(0)); 141 } catch (com.sun.star.lang.WrappedTargetException e) { 142 e.printStackTrace( log ); 143 throw new StatusException("Couldn't get by index", e); 144 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 145 e.printStackTrace( log ); 146 throw new StatusException("Couldn't get by index", e); 147 } catch (com.sun.star.lang.IllegalArgumentException e) { 148 e.printStackTrace( log ); 149 throw new StatusException("Couldn't get by index", e); 150 } 151 152 //get a Shape 153 log.println( "getting Shape" ); 154 XShapes oShapes = (XShapes) UnoRuntime.queryInterface 155 (XShapes.class, oDP); 156 XInterface oObj = SOF.createShape 157 (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 158 for (int i=0; i < 10; i++) { 159 oShapes.add( 160 SOF.createShape(xDrawDoc, 161 5000, 3500, 7510 + 10 * i, 5010 + 10 * i, "Rectangle")); 162 } 163 XShape oShape = SOF.createShape 164 (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"); 165 oShapes.add((XShape) oObj); 166 oShapes.add((XShape) oShape); 167 168 log.println( "creating a new environment for XShape object" ); 169 TestEnvironment tEnv = new TestEnvironment( oObj ); 170 171 log.println( "adding two style as ObjRelation for ShapeDescriptor" ); 172 XPropertySet oShapeProps = (XPropertySet) 173 UnoRuntime.queryInterface(XPropertySet.class, oObj); 174 XStyle aStyle = null; 175 try { 176 aStyle = (XStyle) AnyConverter.toObject( 177 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 178 oShapeProps.setPropertyValue("ZOrder", new Integer(1)); 179 } catch (com.sun.star.lang.WrappedTargetException e) { 180 e.printStackTrace(log); 181 throw new StatusException("Couldn't set or get property value", e); 182 } catch (com.sun.star.beans.UnknownPropertyException e) { 183 e.printStackTrace(log); 184 throw new StatusException("Couldn't set or get property value", e); 185 } catch (com.sun.star.lang.IllegalArgumentException e) { 186 e.printStackTrace(log); 187 throw new StatusException("Couldn't set or get property value", e); 188 } catch (com.sun.star.beans.PropertyVetoException e) { 189 e.printStackTrace(log); 190 throw new StatusException("Couldn't set or get property value", e); 191 } 192 193 tEnv.addObjRelation("Style1", aStyle); 194 oShapeProps = (XPropertySet) 195 UnoRuntime.queryInterface(XPropertySet.class, oShape); 196 try { 197 aStyle = (XStyle) AnyConverter.toObject( 198 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 199 } catch (com.sun.star.lang.WrappedTargetException e) { 200 e.printStackTrace(log); 201 throw new StatusException("Couldn't get property value", e); 202 } catch (com.sun.star.beans.UnknownPropertyException e) { 203 e.printStackTrace(log); 204 throw new StatusException("Couldn't get property value", e); 205 } catch (com.sun.star.lang.IllegalArgumentException e) { 206 e.printStackTrace(log); 207 throw new StatusException("Couldn't get property value", e); 208 } 209 210 tEnv.addObjRelation("Style2", aStyle); 211 212 return tEnv; 213 } // finish method createTestEnvironment 214 215 } // finish class SdXShape 216